<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                # 附件六 阿里大于短信接口 [TOC] * 2017-12-10 阿里大于 短信API接口 TP5專用類庫 http://www.hmoore.net/mikkle/thinkphp5_study/475226 ### TP5 接口類文件 ~~~ <?php namespace app\base\controller; use think\Controller; use think\Validate; class SendSms extends Controller { public static $sms_config = [ 'appkey' => '2358*****',//阿里大于APPKEY 'secretKey' => '60ec4baf8dfb46*******************',//阿里大于secretKey 'FreeSignName' => '短信簽名',//短信簽名 ]; public function sms($data=[]) { $validate = new Validate([ ['param','require|array','參數必填|參數必須為數組'], ['mobile','require|/1[34578]{1}\d{9}$/','手機號錯誤|手機號錯誤'], ['template','require','模板id錯誤'], ]); if (!$validate->check($data)) { return $validate->getError(); } define('TOP_SDK_WORK_DIR', CACHE_PATH.'sms_tmp/'); define('TOP_SDK_DEV_MODE', false); vendor('alidayu.TopClient'); vendor('alidayu.AlibabaAliqinFcSmsNumSendRequest'); vendor('alidayu.RequestCheckUtil'); vendor('alidayu.ResultSet'); vendor('alidayu.TopLogger'); $config = self::$sms_config; $c = new \TopClient; $c->appkey = $config['appkey']; $c->secretKey = $config['secretKey']; $req = new \AlibabaAliqinFcSmsNumSendRequest; $req->setExtend(''); $req->setSmsType('normal'); $req->setSmsFreeSignName($config['FreeSignName']); $req->setSmsParam(json_encode($data['param'])); $req->setRecNum($data['mobile']); $req->setSmsTemplateCode($data['template']); $result = $c->execute($req); $result = $this->_simplexml_to_array($result); if(isset($result['code'])){ return $result['sub_code']; } return true; } private function _simplexml_to_array($obj) { if(count($obj) >= 1){ $result = $keys = []; foreach($obj as $key=>$value){ isset($keys[$key]) ? ($keys[$key] += 1) : ($keys[$key] = 1); if( $keys[$key] == 1 ){ $result[$key] = $this->_simplexml_to_array($value); }elseif( $keys[$key] == 2 ){ $result[$key] = [$result[$key], $this->_simplexml_to_array($value)]; }else if( $keys[$key] > 2 ){ $result[$key][] = $this->_simplexml_to_array($value); } } return $result; }else if(count($obj) == 0){ return (string)$obj; } } } ~~~ ## 調用方法 ~~~ /** * 發送手機短信驗證碼 * #User: Mikkle * #Email:776329498@qq.com * #Date: * @param bool|false $mobile * @return 出錯返回1003錯誤碼和錯誤詳情|返回錯誤碼 */ public function sendRegSms($mobile=false){ if (!$this->request->isAjax() ) return $this->showCode(1002); if(!$mobile) $mobile=$this->request->param('mobile'); if (!$mobile) return $this->showCode(1004); if (model('base/User')->infoByMobile($mobile)) return $this->showCode(1003,'該手機已經注冊過,請勿重新注冊'); $data_mobile['mobile']=$mobile; $result_mobile=$this->checkValidate($data_mobile,'base/Register.mobile',true); if ( isset($result_mobile['code']) ) return $result_mobile; if(!$this->checkRegSms($mobile)) return $this->showCode(1003,'請勿一分鐘內重復申請驗證碼'); $req=$this->sendSmsCode($mobile); if ($req===true){ return $this->showCode(1001); }else{ return $this->showCode(1003,$req); } } ~~~ ### 調用方法(私有) ~~~ protected function sendSmsCode($mobile = false) { if (!$mobile) return false; $code = rand(10000, 99999); $data = [ 'param' => ['code' => (string)$code, 'product' => '【****】'], 'mobile' => $mobile, 'template' => 'SMS_37185084', ]; $req = controller('base/SendSms')->sms($data); if ($req === true) { $data_cache = [ 'mobile' => $mobile, 'code' => (string)$code, 'times' => time() + 60, ]; $this->setRegSmsCache($data_cache); return true; } else { return $req; } } ~~~ ### 設置手機短息驗證碼緩存setRegSmsCache 方法 ~~~ /** * 設置手機短息驗證碼緩存 * #User: Mikkle * #Email:776329498@qq.com * #Date: * @param $data_cache */ protected function setRegSmsCache($data_cache) { Cache::set('sms_' . $data_cache['mobile'], $data_cache, 300); } ~~~ ### 檢測手機短信驗證碼檢測手機短信驗證碼 ~~~ /** * 檢測手機短信驗證碼 * #User: Mikkle * #Email:776329498@qq.com * #Date: * @param $mobile * @param bool|false $code * @return bool */ protected function checkRegSms($mobile, $code = false) { if (!$mobile) return false; if ($code === false) { //判斷60秒以內是否重復發送 if (!Cache::has('sms_' . $mobile)) return true; if (Cache::get('sms_' . $mobile)['times'] > time()) { return false; } else { return true; } } else { //判斷驗證碼是否輸入正確 if (!Cache::has('sms_' . $mobile)) return false; if (Cache::get('sms_' . $mobile)['code'] == $code) { return true; } else { return false; } } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看