APICloud知識教程 | 用戶手機號獲取驗證碼註冊源碼分享

分享自:APICloud官方論壇javascript

做者:論壇版主【funy】php

用戶手機號註冊源碼分享,首頁獲取驗證碼,調用阿里大魚短信驗證碼,接口thinkphp5.2寫的,能夠判斷手機號是否註冊,短信發送是否成功。html

title
</head>
   <body>

           <div class="aui-content aui-margin-b-15">
                   <ul class="aui-list aui-form-list">
                           <li class="aui-list-item">
                                   <div class="aui-list-item-inner">
                                           <div class="aui-list-item-label-icon">
                                                   <i class="aui-iconfont aui-icon-mobile"></i>
                                           </div>
                                           <div class="aui-list-item-input">
                                                   <input type="text" placeholder="手機號" id="mobile">
                                           </div>
                                   </div>
                           </li>
                           <li class="aui-list-item">
                                   <div class="aui-list-item-inner">
                                           <div class="aui-list-item-label-icon">
                                                   <i class="aui-iconfont aui-icon-lock"></i>
                                           </div>
                                           <div class="aui-list-item-input">
                                                   <input type="text" placeholder="驗證碼" id="code">
                                           </div>
                                           <div class="aui-list-item-label-icon">
                                                   <i class="aui-iconfont aui-icon-display"></i>
                                           </div>
                                   </div>
                           </li>
                   </ul>
           </div>
           <div align="center">
                   <button type="button"  onclick="get_code();">
                           獲取驗證碼
                   </button>
                   <button type="button"  onclick="next_reg();">
                           下一步
                   </button>
           </div>

   </body>
   <script type="text/javascript" src="../script/api.js"></script>
   <script type="text/javascript">
           var mobile = document.getElementById("mobile");
           var code = document.getElementById("code");
           var code_str = "";
           for (var i = 0; i < 6; i++) {
                   code_str += Math.round(Math.random() * 10);
           }
           var getcode = document.getElementById("getcode");
           //                alert(code_str);
           function get_code() {
                   //                alert(mobile.value);
                   //                alert();
                   if (mobile.value.length == 0) {
                           alert("手機號不能爲空");
                           return;
                   }
                   api.ajax({
                           url : 'http://huodong.demo.com/index.php/api/Member/getCode',
                           method : 'post',
                           data : {
                                   values : {
                                           mobile : mobile.value,
                                           code_str : code_str,
                                           signature : '*******'
                                   }
                           }
                   }, function(data) {
                           //                        alert(data.code);
                           if (data) {
                                   if (data.code == 1) {
                                           //                                                alert('驗證碼發送成功');
                                           api.toast({
                                                   msg : '驗證碼發送成功'
                                           });
                                   } else if (data.code == 2) {
                                           alert('驗證碼發送失敗');
                                   } else if (data.code == 3) {
                                           alert('手機號已註冊');
                                   }
                           } else {
                                   alert('111');
                           }
                   });
           }

           //用戶註冊
           function next_reg() {
                   if (code.value != code_str) {
                           alert("驗證碼錯誤");
                           return;
                   }
複製代碼

// api.openWin({ // name : 'personer_regsetpass', // url : 'personer_regsetpass.html', // pageParam : { // mobile : mobile.value // } // }); api.openWin({ name : 'personer_regsetpass', url : './a_headbackindex.html', pageParam : { title : '註冊', url : 'personer_regsetpass', mobile : $api.setStorage('mobile', mobile.value) } }); }java

// function backtoIndex() { // api.closeToWin({ // name : 'root' // }); // }ajax

apiready = function() {
複製代碼

// api.fixStatusBar(api.dom('header')); // api.addEventListener({ // name : 'keyback' // }, function(ret, err) { // backtoIndex(); // }); }; thinkphp

php接口代碼:json

//註冊獲取手機驗證碼接口 public function getCode() { code = Request::instance()->post('code_str');mobile = Request::instance()->post('mobile'); signature = Request::instance()->post('signature');str = Db::table('member')->where('phone', mobile)->find();
       if (str) { // echo 3; res['code'] = 3;
       } else {
           if (signature == '************') { Loader::import('AlibabaAliqinFcSmsNumSendRequest', EXTEND_PATH); Loader::import('TopClient', EXTEND_PATH); Loader::import('ResultSet', EXTEND_PATH); Loader::import('RequestCheckUtil', EXTEND_PATH); Loader::import('TopLogger', EXTEND_PATH); c = new \TopClient;c->appkey = '';//換成本身的 c->secretKey = '';//換成本身的req = new \AlibabaAliqinFcSmsNumSendRequest; req->setExtend("123456");req->setSmsType("normal"); req->setSmsFreeSignName("");//換成本身的req->setSmsParam("{"code":"code\",\"product\":\"註冊\"}");req->setRecNum("mobile");req->setSmsTemplateCode("SMS_2575466"); resp =c->execute(req);
               if (resp) { // echo 1; res['code'] = 1;
               } else {
                   // echo 2;res['code'] = 2; } } else { // echo 3; res['code'] = 3;
           }
       }
       echo json_encode(res); }api

相關文章
相關標籤/搜索