短信驗(yàn)證碼發(fā)送成功后 點(diǎn)擊提交按鈕顯示驗(yàn)證碼未發(fā)送
驗(yàn)證碼代碼
<button class="btn" onclick="dr_ajax_url('/index.php?s=form&c=api&m=send_code&&id='+$('#dr_dianhua2').val())" type="button" >獲取驗(yàn)證碼</button>
<button type="button" onclick="dr_ajax_submit('{$post_url}', 'myform2', '2000', '{$rt_url}')" class="btn btn-warning btn-block mt15" >免費(fèi)領(lǐng)取</button>控制器代碼
<?php namespace Phpcmf\Controllers;
/**
* 二次開發(fā)時(shí)可以修改本文件,不影響升級覆蓋
*/
class Xfbd extends \Phpcmf\Home\Form
{
public function index() {
$this->_Home_List();
}
public function show() {
$this->_Home_Show();
}
public function post() {
$code = \Phpcmf\Service::L('Form')->get_mobile_code($phone);
if (!$code) {
$this->_json(0, dr_lang('沒有發(fā)送驗(yàn)證碼'));
} elseif ($code != $_POST['sms']) {
$this->_json(0, dr_lang('驗(yàn)證碼不正確'));
}
$this->_Home_Post();
}
}api代碼:
<?php namespace Phpcmf\Controllers;
// 用戶api
class Api extends \Phpcmf\Common
{
/**
* 發(fā)送驗(yàn)證碼
*/
public function send_code() {
$phone = dr_safe_replace(\Phpcmf\Service::L('input')->get('id'));
if (!$phone) {
$this->_json(0, dr_lang('手機(jī)號(hào)碼未填寫'), ['field' => 'phone']);
} elseif (!\Phpcmf\Service::L('Form')->check_phone($phone)) {
$this->_json(0, dr_lang('手機(jī)號(hào)碼格式不正確'), ['field' => 'phone']);
}
if (\Phpcmf\Service::L('Form')->get_mobile_code($phone)) {
// 驗(yàn)證操作間隔
$this->_json(1, dr_lang('已經(jīng)發(fā)送稍后再試'));
}
$code = rand(100000, 999999);
$rt = \Phpcmf\Service::M('member')->sendsms_code($phone, $code);
if (!$rt['code']) {
$this->_json(0, dr_lang('發(fā)送失敗'));
}
\Phpcmf\Service::L('Form')->set_mobile_code($phone, $code);
$this->_json(1, dr_lang('驗(yàn)證碼發(fā)送成功'));
}
}使用的是阿里云的接口 手機(jī)可以獲得驗(yàn)證碼 但是提交表單顯示沒有發(fā)送
表單:
{php extract(dr_get_form_post_value('biaodan'))} <form action="" class="form-horizontal" method="post" name="myform" id="myform2"> {$form} <div class="fc-form-body"> <div class="p_r mt15" id="dr_row_xingming"> <input type="text" class="form-control pl30" name="data[xingming2]" id="dr_xingming2" placeholder="請輸入名字" /> <i class="glyphicon glyphicon-user"></i> </div> <div class="p_r mt15" id="dr_row_dianhua"> <input type="text" class="form-control pl30" name="data[dianhua2]" id="dr_dianhua2" placeholder="請輸入手機(jī)號(hào)" /> <i class="glyphicon glyphicon-phone"></i> </div> <div class="input-group input-large mt15"> <input class="form-control placeholder-no-fix" type="text" autocomplete="off" id="dr_sms" name="sms"> <div class="input-group-btn"> <button class="btn" onclick="dr_ajax_url('/index.php?s=form&c=api&m=send_code&&id='+$('#dr_dianhua2').val())" type="button" >獲取驗(yàn)證碼</button> </div> </div> </div> <button type="button" onclick="dr_ajax_submit('{$post_url}', 'myform2', '2000', '{$rt_url}')" class="btn btn-warning btn-block mt15" >免費(fèi)領(lǐng)取</button> </form>驗(yàn)證碼獲取地址錯(cuò)了,一般二次開發(fā)時(shí)都會(huì)遇到寫錯(cuò)地址的問
參考文檔:《發(fā)送手機(jī)驗(yàn)證碼開發(fā)》
開源是一種精神,但不是義務(wù),幫忙是情分,不幫也不要抱怨,建議大家多研究代碼、多閱讀代碼、多翻閱社區(qū)歷史問題!
回復(fù)@官方研發(fā)實(shí)習(xí)技術(shù) 是指的onclick="dr_ajax_url('/index.php?s=form&c=api&m=send_code&id='+$('#dr_dianhua2').val())" 這個(gè)嗎
這個(gè)是從新寫了一個(gè)api 來跳過第一層圖片驗(yàn)證的~ 這個(gè)api文件寫在上面了~
控制器寫錯(cuò)了,都沒有傳遞phone
<?php namespace Phpcmf\Controllers; /** * 二次開發(fā)時(shí)可以修改本文件,不影響升級覆蓋 */ class Xfbd extends \Phpcmf\Home\Form { public function index() { $this->_Home_List(); } public function show() { $this->_Home_Show(); } public function post() { if (IS_POST) { $phone = $_POST['data']['dianhua2']; $code = \Phpcmf\Service::L('Form')->get_mobile_code($phone); if (!$code) { $this->_json(0, dr_lang('沒有發(fā)送驗(yàn)證碼')); } elseif ($code != $_POST['sms']) { $this->_json(0, dr_lang('驗(yàn)證碼不正確')); } } $this->_Home_Post(); } }