public static function checkMobileRepeat($mobile) { $mobileFormat = self::checkMobileFormat($mobile); if (!$mobileFormat) { return false; } // 验证手机是否已经绑定过 $mobileRegisterInfo = UserUtils::checkMobile($mobile); if ($mobileRegisterInfo) { return false; } return true; }
/** * 发送模板短信 * @param to 手机号码集合,用英文逗号分开 * @param datas 内容数据 格式为数组 例如:array('Marry','Alon'),如不需替换请填 null * @param $tempId 模板Id,测试应用和未上线应用使用测试模板请填写1,正式应用上线后填写已申请审核通过的模板ID * */ private function sendTemplateSMS($res, $to, $datas, $tempId, $params) { extract($params); // 初始化REST SDK // global $accountSid,$accountToken,$appId,$serverIP,$serverPort,$softVersion,$db; $rest = new RestSmsSDK($serverIP, $serverPort, $softVersion); $rest->setAccount($accountSid, $accountToken); $rest->setAppId($appId); if ($type == 'mobile') { //手机注册 // 发送模板短信 //echo "Sending TemplateSMS to $to <br/>"; if (!$to) { // $res = WebUtils::makeErrorInfo_oldVersion($res, 'mobile_empty'); return $this->makeErrorInfo($res, 'mobcent_mobile_empty'); } if (!preg_match('/^1(3|5|8|7)\\d{9}$/', $to)) { //^(((d{2,3}))|(d{3}-))?13d{9}$ // $res = WebUtils::makeErrorInfo_oldVersion($res,'mobile_error'); return $this->makeErrorInfo($res, 'mobcent_mobile_error'); } if ($action == 'register') { //注册验证手机号是否唯一 // $mobileInfo = $db->get_one("SELECT * FROM pw_appbyme_sendsms WHERE mobile = " . S::sqlEscape($to) ." AND uid > 0"); $bindInfo = UserUtils::checkMobile($to); if ($bindInfo) { // $res = WebUtils::makeErrorInfo_oldVersion($res,'mobile_repeat'); return $this->makeErrorInfo($res, 'mobcent_mobile_repeat'); } } $result = $rest->sendTemplateSMS($to, $datas, $tempId); if ($result == NULL) { // $res = WebUtils::makeErrorInfo_oldVersion($res,'result_error'); return $this->makeErrorInfo($res, 'mobcent_result_error'); //echo "result error!"; //break; } if ($result->statusCode != 0) { $res['rs'] = 0; $res['head']['alert'] = 1; $res['errcode'] = $res['head']['errCode'] = $result->statusCode; $res['head']['errInfo'] = $result->statusMsg; //echo "error code :" . $result->statusCode . "<br>"; //echo "error msg :" . $result->statusMsg . "<br>"; //TODO 添加错误处理逻辑 // return $this->makeErrorInfo($res, 'mobcent_result_error'); } else { // echo "Sendind TemplateSMS success!<br/>"; // 获取返回信息 $smsmessage = $result->TemplateSMS; $time = strtotime($smsmessage->dateCreated); $inserArray = array('id' => '', 'mobile' => $to, 'code' => $datas[0], 'time' => $time, 'uid' => 0); $mobileInfo = AppbymeSendsms::getMobileUidInfo($to); if ($mobileInfo) { $updataArr = array('time' => $time, 'code' => $datas[0]); AppbymeSendsms::updateMobile($to, $updataArr); } else { AppbymeSendsms::insertMobile($inserArray); } } return $res; } else { //pc注册 } }