Beispiel #1
0
 public function check($pPhone, $pReqmode, $pCode)
 {
     $tCodeMO = new PhonecodeModel();
     $tTime = time();
     $tRow = $tCodeMO->field('code_time,id')->where('phone = \'' . $pPhone . '\' and reqmode = ' . $pReqmode . ' and code = \'' . $pCode . '\'')->fRow();
     if (!empty($tRow['code_time'])) {
         $tTmptime = ($tTime - $tRow['code_time']) / 60;
         if ($tTmptime > 5) {
             return array('status' => 0, 'msg' => '验证码过期');
         }
     } else {
         return array('status' => 0, 'msg' => '验证码错误');
     }
     return array('status' => 1, 'msg' => '验证码认证成功');
 }
Beispiel #2
0
 public function authcodeAction()
 {
     $p = $_REQUEST;
     $pPhone = empty($p['phone']) ? '' : trim($p['phone']);
     $pTms = empty($p['tms']) ? '' : intval(trim($p['tms']));
     #请求次数
     $pReqmode = empty($p['reqmode']) ? '' : intval(trim($p['reqmode']));
     #1: 注册请求;2: 忘记/找回密码请求; 3:第三方注册
     $tTime = time();
     if (!Tool_Validate::mo($pPhone)) {
         Tool_Fnc::ajaxMsg('手机号不正确');
     }
     if (empty($pReqmode)) {
         Tool_Fnc::ajaxMsg('请选择请求类型');
     }
     $tUMO = new UserModel();
     $tURow = $tUMO->field('count(0) c')->where('phone = \'' . $pPhone . '\'')->fRow();
     $tIsregphone = 0;
     if (!empty($tURow['c'])) {
         $tIsregphone = 1;
     }
     if ($pReqmode == 1 && $tIsregphone) {
         Tool_Fnc::ajaxMsg('该手机号已被注册');
     }
     $tCodeMO = new PhonecodeModel();
     $tRow = $tCodeMO->field('code,code_time')->where('phone = \'' . $pPhone . '\' and code_time > \'' . date('Y-m-d', $tTime - 86400) . '\'')->order('id desc')->fRow();
     $tCodetime = empty($tRow['code_time']) ? 0 : $tRow['code_time'];
     $tTmptime = ($tTime - $tCodetime) / 60;
     if ($tTmptime < 1) {
         Tool_Fnc::ajaxMsg('您发送太频繁,请稍等一会再试');
     }
     //判断发送是否超过可发送的数量
     $tRow = $tCodeMO->field('count(0) c')->where('phone = \'' . $pPhone . '\' and reqmode = ' . $pReqmode)->fRow();
     if (!empty($tRow['c']) && $tRow['c'] >= 10) {
         Tool_Fnc::ajaxMsg('您已经超过最大可发送数量');
     }
     $tCode = rand(1000, 9999);
     $apikey = Yaf_Registry::get("config")->yunpian->sms->apikey;
     //请用自己的apikey代替
     $mobile = $pPhone;
     //请用自己的手机号代替
     $tpl_id = 2;
     //对应默认模板 【#company#】您的验证码是#code#
     $tpl_value = "#company#=达康透析&#code#=" . $tCode;
     $tRes = $this->tpl_send_sms($apikey, $tpl_id, $tpl_value, $mobile);
     #$tRes['code'] = 0;
     if ($tRes['code'] === 0) {
         $tData = array('phone' => $pPhone, 'code' => $tCode, 'reqmode' => $pReqmode, 'code_time' => $tTime);
         if ($tCodeMO->insert($tData)) {
             #Tool_Fnc::ajaxMsg("成功发送验证码",1,array("code"=>$tCode));
             Tool_Fnc::ajaxMsg("成功发送验证码", 1);
         } else {
             Tool_Fnc::ajaxMsg("操作数据库失败");
         }
     } else {
         //写日志
         $tWrite = date("Y-m-d H:i:s") . "\r\n";
         $tWrite .= $pPhone . "   " . $tCode . "   " . json_encode($tRes) . "\r\n\r\n\r\n";
         $tWrite .= "\r\n\r\n\r\n";
         Tool_Fnc::writefile(APPLICATION_PATH . '/smssend/' . date("Ymd", $tTime) . ".log", $tWrite);
         Tool_Fnc::ajaxMsg("发送验证码失败");
     }
     return;
 }