thinkphp实现发送手机验证码功能!
生活随笔
收集整理的這篇文章主要介紹了
thinkphp实现发送手机验证码功能!
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
?? ? php實(shí)現(xiàn)發(fā)送手機(jī)驗(yàn)證碼功能如下:
//發(fā)送手機(jī)驗(yàn)證碼public function sendPhoneCodeMessage(){ vendor('SendPhoneCode.SendCode','','.php');$phone = I("post.phone"); $randomNumber=rand(10000,99999);session('phoneCode',md5($randomNumber));cookie('phoneCode',md5($randomNumber),3600);$content = "您的一畝地驗(yàn)證碼:".$randomNumber."。";$sendCode = new \SendCode();$codeResult = $sendCode->sendPhoneCode($phone,$content);if ($codeResult['message'] == "成功") {echo 1;}else{echo 0;}}--------------------- 發(fā)送短信類------------------------------/*-------------------------------- 功能: HTTP接口 發(fā)送短信類 --------------------------------*/class SendCode {const ACCOUNT='ymdw@ymd';const PASSWORD = 'YIMUDI%wcdK9';const MOS_WSDL = 'http://11.11.11.11/Service/WebService.asmx?wsdl'; //MOS wsdl地址const SING = '【一畝地網(wǎng)】';//短信簽名const TYPE = '1'; //寫(xiě)入短信表中的類型const TOTAL = 15; //單個(gè)號(hào)碼發(fā)送驗(yàn)證碼的限制數(shù)量/*** 2018-08-06*發(fā)送手機(jī)驗(yàn)證碼*/function sendPhoneCode($phone,$content){ $this->client = new SoapClient(self::MOS_WSDL);//SoapClient對(duì)象$uuid = $this->getUuid();$MessageData = array( 'Phone'=>$phone,'Content'=>$content,'vipFlag'=>'false','customMsgID'=>'','customNum'=>'');$mtpack = array('uuid'=>$uuid,'batchID'=>$uuid,'batchName'=>'發(fā)送短信','sendType'=>'1','msgType'=>'1','msgs'=>array('MessageData'=>$MessageData),'bizType'=>'','distinctFlag'=>'','scheduleTime'=>'','deadline'=>'');//var_dump($mtpack);$ret = $this->client->Post(array('account'=>self::ACCOUNT,'password'=>self::PASSWORD,'mtpack'=>$mtpack)); //var_dump($ret); return $this->objectToArr($ret->PostResult);}//生成uuid的方法public function getUuid(){mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.$charid = strtoupper(md5(uniqid(rand(), true)));$hyphen = chr(45);// "-"$uuid = substr($charid, 0, 8).$hyphen.substr($charid, 8, 4).$hyphen.substr($charid,12, 4).$hyphen.substr($charid,16, 4).$hyphen.substr($charid,20,12);return $uuid;}//處理返回值public function objectToArr($array){if(is_object($array)){$array = (array)$array;}if(is_array($array)){foreach($array as $key=>$value){$array[$key] = $this->objectToArr($value);}}return $array;}}?
總結(jié)
以上是生活随笔為你收集整理的thinkphp实现发送手机验证码功能!的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: UNITY性能优化✨MeshBaker在
- 下一篇: PHP开发环境搭建与工具