public function smsTest() { $type = $_REQUEST['type'] ? $_REQUEST['type'] : 1; $phone = '13983475645'; //手机号码 $verifcode = rand(1000, 9999); $content = "创客荟APP本次验证码:" . $verifcode . ",将于60S内超期"; //调用短信接口 import('@.ORG.SmsHttp'); $smsHttp = new SmsHttp(); switch ($type) { case 1: //短信操作 $smsNotic = $smsHttp->getMessage($phone, $content, $httpType = 1); print_R("调试类型" . $type . ":"); print_R($phone . $content); print_R($smsNotic); break; case 2: //获取上行短信 $smsNotic = $smsHttp->getMessage($phone, $content, $httpType = 2); print_R("调试类型" . $type . ":"); print_R($smsNotic); break; case 3: //获取报告 $smsNotic = $smsHttp->getMessage($phone, $content, $httpType = 3); print_R("调试类型" . $type . ":"); print_R($smsNotic); break; case 4: //查询余额 $smsNotic = $smsHttp->getMessage($phone, $content, $httpType = 4); print_R("调试类型" . $type . ":"); print_R($smsNotic); break; } }
/** getVerificationCode 获取司机验证码 */ public function getVerificationCode($returnType = 'json') { if (!empty($_REQUEST['phone']) && is_numeric($_REQUEST['phone'])) { $verifcode = rand(1000, 9999); //echo $verifcode; $phone = $_REQUEST['phone']; //手机号码 $type = $_REQUEST['type']; //类型 $content = $verifcode . "(您获取的手机验证码),有效期为24小时,感谢您注册风平物流。如非本人操作,请忽略此短信。"; $userid = $this->checkPhoneExist($phone, $type); if ($userid) { //存在手机号,回写验证码到数据库 $map = array(); $map['id'] = $userid; $data['verifcode'] = $verifcode; $result = $this->CURD('MisAutoCsb', 'save', $data, $map); } else { //不存在手机号,插入到数据库 $data['account'] = $phone; $data['phone'] = $phone; $data['verifcode'] = $verifcode; $data['createtime'] = time(); $data['status'] = 0; $result = $this->CURD('MisAutoCsb', 'add', $data); } //echo 123; if ($result) { //查询短信发送一个手机号短信间隔最短60s 一个小时不超过3条 ,一天不超过5条 $phoneHisteryMpdel = D('MisSystemPhoneHistery'); //首先查询是否发送了5条数据 $dstarttime = strtotime(date('Y-m-d', time())); $dendtime = strtotime(date('Y-m-d', strtotime('+1 day'))); $dphMap['createtime'] = array(array('egt', $dstarttime), array('lt', $dendtime)); $dphMap['phone'] = $phone; $dphList = $phoneHisteryMpdel->where($dphMap)->count(); $phListInfo = $phoneHisteryMpdel->where($dphMap)->order('id desc ')->find(); //查询一个小时内发送的数据 $hendtime = $phListInfo['createtime']; $hstarttime = strtotime(date('Y-m-d H:i:s', strtotime('-1 hour', $hendtime))); $hphMap['createtime'] = array(array('egt', $hstarttime), array('lt', $hendtime)); $hphMap['phone'] = $phone; $hphList = $phoneHisteryMpdel->where($hphMap)->count(); $stime = time() - $hendtime; if ($dphList < 5 && $hphList < 3 && $stime >= 60) { //调用短信接口 import('@.ORG.SmsHttp'); $smsHttp = new SmsHttp(); //短信操作 $smsNotic = $smsHttp->getMessage($phone, $content, $httpType = 1); //回写状态正常时 $data = $result; $code = '1000'; $msg = $smsNotic . "验证码为:" . $verifcode; //添加号码发送短信记录 $phdate['phone'] = $phone; $phdate['createtime'] = time(); $phresult = $this->CURD('MisSystemPhoneHistery', 'add', $phdate); } else { $data = array(); $code = '1006'; if ($dphList >= 5) { $msg = '1006:当天验证码获取超过5条'; } elseif ($hphList >= 3) { $msg = '1006:一个小时内验证码获取超过3条'; } elseif ($stime < 60) { $msg = '1006:上次获取验证码时间不足60s'; } } } else { $data = array(); $code = '1006'; $msg = '1006:获取验证码失败'; } } else { $data = array(); $code = '1007'; $msg = '1007:非法访问:未有手机号'; } return $this->getReturnData($data, $returnType, $code, $msg); }