引入验证码发送类:
/**
* 发送验证码* @Author TGhan
* @DateTime 2018-01-25
* @version [version]
* @return [type] [description]
*/
function verifyCode(){
$m_phone[] = trim($this->o_toolObj->getPost("phone"));
// $m_phoneMsg = trim($this->o_toolObj->getPost("phoneMsg"));
$sql = 'select sms_number,sms_pwd from hps_sms limit 1';
$sms_config = $this->o_dataBase->executes($sql);
$this->AliSendSms($m_phone,$sms_config);
}
/**
* 调用阿里发短信,并记录发送失败信息
* */
private function AliSendSms($mobile_arr, $sms_config) {
require_once ( __DIR__ . '/sms/send/sendSms.php' );
require_once ( __DIR__ . '/sms/send/querySendDetails.php' );
$this->o_dataBase->setTable('hps_sms_order');
foreach($mobile_arr as $k=>$v) {
// 发送短信
$content = \Aliyun\DySDKLite\Sms\sendSms($sms_config['0']['sms_number'],$sms_config['0']['sms_pwd'], $v);
$sms['user_phone'] = $v;
$sms['addtime'] = time();
$sms['send_ip'] = $_SERVER['REMOTE_ADDR'];
// 判断是否发送成功
if($content['Message'] == 'OK' && $content['Code'] == 'OK') {
//sleep(1); // 1秒之后 查询短信记录
//$query_sms = \Aliyun\DySDKLite\Sms\querySendDetails($sms_config['0']['sms_number'],$sms_config['0']['sms_pwd'], $v);
// 获取发送验证的内容
//$i = count($query_sms['SmsSendDetailDTOs']['SmsSendDetailDTO'])-1;
$sms['sms_content'] = '发送成功!'; //$query_sms['SmsSendDetailDTOs']['SmsSendDetailDTO'][$i]['Content'];
} else {
$sms['sms_content'] = '发送失败!'; //$content['Code'];
$sms['status'] = 0;
$sms['ali_param'] = 0; //json_encode($content);
$error_msg = 1;
}
$this->o_dataBase->insert($sms); ///插入数据库一条数据记录
// $this->o_dataBase->printsql();die;
// var_dump($query_sms);
}
if(isset($error_msg)) {
return false;
}
return true;
}
判断:接过来的值与Session值判断是否一致
$code = trim($this->o_toolObj->getPost("code"));
$m_sessionCode = $this->o_toolObj->getSession('verifyCode');
$tempArray = array ( );
preg_match("/[^@]+@[^@]+\.[^@]+/i", $email,$tempArray);
if(empty($email)||sizeof($tempArray)<1||empty($code)) {
$this->m_message .= "请填写完整邮件地址和验证玛 、";
}
if($m_sessionCode!=$code) {
$this->m_message .= "验证玛填写错误 、";
}