|
|
|
@ -583,7 +583,43 @@ eof;
@@ -583,7 +583,43 @@ eof;
|
|
|
|
|
return $rndCode; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//保存当天最新发送过的验证码 |
|
|
|
|
protected function saveTodaySmsCode($cellphone, $sms_code) { |
|
|
|
|
if(session_status() !== PHP_SESSION_ACTIVE) { |
|
|
|
|
session_start(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$_SESSION['randSmsCode_today'] = $sms_code; |
|
|
|
|
$_SESSION['randSmsCode_created_date'] = date('Ymd'); |
|
|
|
|
$_SESSION['smsCodePhone_today'] = $cellphone; //保存发送验证码的手机号码,便于在登录、注册的时候验证 |
|
|
|
|
|
|
|
|
|
return $sms_code; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//获取当天最新发送过的验证码 |
|
|
|
|
protected function getTodaySmsCode($cellphone) { |
|
|
|
|
if(session_status() !== PHP_SESSION_ACTIVE) { |
|
|
|
|
session_start(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$sms_code = !empty($_SESSION['randSmsCode_today']) ? $_SESSION['randSmsCode_today'] : 0; |
|
|
|
|
$sms_date = !empty($_SESSION['randSmsCode_created_date']) ? $_SESSION['randSmsCode_created_date'] : 0; |
|
|
|
|
$today = = date('Ymd'); |
|
|
|
|
$codeSentPhoneNumber = !empty($_SESSION['smsCodePhone_today']) ? $_SESSION['smsCodePhone_today'] : 0; |
|
|
|
|
|
|
|
|
|
if ($today == $sms_date && $cellphone == $codeSentPhoneNumber && !empty($sms_code)) { |
|
|
|
|
return $sms_code; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//获取短信验证码 |
|
|
|
|
//TODO: 调整发送逻辑,发送前,先查询当天发送详情,从而限制一个手机号码每天最多2次发送验证码的机会 |
|
|
|
|
//查询结果判断 |
|
|
|
|
//rescode == 2 当天发送过,但是失败了,直接返回验证码,帮用户填上 |
|
|
|
|
//rescode == 3 当天发送过,且成功了,需要用户自己填(考虑用户删除了验证码短信,可在距离上一次发送超1小时后当天再给用户一次获取验证码的机会) |
|
|
|
|
//rescode == 0 当天没发送过,则发送验证码 |
|
|
|
|
public function actionSendsmscode() { |
|
|
|
|
$ip = $this->getUserIp(); |
|
|
|
|
$check_key = "sendsmscode_{$ip}"; |
|
|
|
@ -598,6 +634,7 @@ eof;
@@ -598,6 +634,7 @@ eof;
|
|
|
|
|
|
|
|
|
|
//返回给视图的变量 |
|
|
|
|
$code = 0; |
|
|
|
|
$rescode = -1; //短信发送详情结果:-1 默认值,0 - 未发送,1 - 发送中,2 - 发送失败,3 - 发送成功 |
|
|
|
|
$msg = ''; |
|
|
|
|
$err = ''; |
|
|
|
|
|
|
|
|
@ -620,19 +657,32 @@ eof;
@@ -620,19 +657,32 @@ eof;
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//尝试发送短信验证码 |
|
|
|
|
//获取当天最新发送过的验证码 |
|
|
|
|
$sms_code = $this->getTodaySmsCode($cellphone); |
|
|
|
|
if (empty($sms_code)) { |
|
|
|
|
$sms_code = $this->generateRandSmsCode($cellphone); |
|
|
|
|
$this->saveTodaySmsCode($cellphone, $sms_code); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$params = array( |
|
|
|
|
'phoneNumber' => $cellphone, |
|
|
|
|
'codeNumber' => $this->generateRandSmsCode($cellphone), |
|
|
|
|
'codeNumber' => $sms_code, |
|
|
|
|
'action' => $action, |
|
|
|
|
); |
|
|
|
|
$params['sign'] = $this->sign($params, FSC::$app['config']['service_3rd_api_key']); |
|
|
|
|
|
|
|
|
|
$api = FSC::$app['config']['service_3rd_api_domain'] . '/aliyun/sendverifycode/'; |
|
|
|
|
$timeout = 30; //api请求超时时长 |
|
|
|
|
$pc = false; |
|
|
|
|
$headers = array("Content-Type: application/json"); |
|
|
|
|
//以json格式post数据 |
|
|
|
|
$headers = array("Content-Type: application/json"); |
|
|
|
|
$pc = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//发送之前先查询当天该手机号码的发送情况,并根据发送结果来决定是否发送验证码短信 |
|
|
|
|
$api_query = FSC::$app['config']['service_3rd_api_domain'] . '/aliyun/querysendresult/'; |
|
|
|
|
$res_query = $this->request($api, json_encode($params), $timeout, $pc, $headers); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//发送短信验证码 |
|
|
|
|
$api = FSC::$app['config']['service_3rd_api_domain'] . '/aliyun/sendverifycode/'; |
|
|
|
|
$res = $this->request($api, json_encode($params), $timeout, $pc, $headers); |
|
|
|
|
|
|
|
|
|
if (!empty($res) && $res['status'] == 200) { |
|
|
|
|