function action_send_mobile_code ()
{
// 获取全局变量
$user = $GLOBALS['user'];
$_CFG = $GLOBALS['_CFG'];
$_LANG = $GLOBALS['_LANG'];
$smarty = $GLOBALS['smarty'];
$db = $GLOBALS['db'];
$ecs = $GLOBALS['ecs'];
$user_id = $_SESSION['user_id'];
/* 载入语言文件 */
require_once (ROOT_PATH . 'languages/' . $_CFG['lang'] . '/user.php');
require_once (ROOT_PATH . 'includes/lib_validate_record.php');
$mobile_phone = trim($_REQUEST['mobile_phone']);
/* 验证码检查 */
if((intval($_CFG['captcha']) & CAPTCHA_REGISTER) && gd_version() > 0)
{
if(empty($_POST['captcha']))
{
exit($_LANG['invalid_captcha']);
return;
}
/* 检查验证码 */
include_once ('includes/cls_captcha.php');
$captcha = new captcha();
if(! $captcha->check_word(trim($_POST['captcha'])))
{
exit($_LANG['invalid_captcha']);
return;
}
}
if(empty($mobile_phone))
{
exit("手机号不能为空");
return;
}
else if(! is_mobile_phone($mobile_phone))
{
exit("手机号格式不正确");
return;
}
else if(check_validate_record_exist($mobile_phone))
{
// 获取数据库中的验证记录
$record = get_validate_record($mobile_phone);
/**
* 检查是过了限制发送短信的时间
*/
$last_send_time = $record['last_send_time'];
$expired_time = $record['expired_time'];
$create_time = $record['create_time'];
$count = $record['count'];
// 每天每个手机号最多发送的验证码数量
$max_sms_count = 10;
// 发送最多验证码数量的限制时间,默认为24小时
$max_sms_count_time = 60 * 60 * 24;
if((time() - $last_send_time) < 60)
{
echo ("每60秒内只能发送一次短信验证码,请稍候重试");
return;
}
else if(time() - $create_time < $max_sms_count_time && $record['count'] > $max_sms_count)
{
echo ("您发送验证码太过于频繁,请稍后重试!");
return;
}
else
{
$count ++;
}
}
require_once (ROOT_PATH . 'includes/lib_passport.php');
// 设置为空
$_SESSION['mobile_register'] = array();
require_once (ROOT_PATH . 'sms/sms.php');
$mobile_code = rand_number(6);
$mobile_code= (string)$mobile_code;
$aa=array(
'code'=>$mobile_code,
'product'=>$GLOBALS['_CFG']['shop_name']
);
$moban=trim($GLOBALS['_CFG']['dayu_zhuce_tpl']);
$result = sendSMS($mobile_phone,$aa,$moban);
if($result)
{
if(! isset($count))
{
$ext_info = array(
"count" => 1
);
}
else
{
$ext_info = array(
"count" => $count
);
}
// 保存手机号码到SESSION中
$_SESSION[VT_MOBILE_REGISTER] = $mobile_phone;
// 保存验证信息
save_validate_record($mobile_phone, $mobile_code, VT_MOBILE_REGISTER, time(), time() + 30 * 60, $ext_info);
echo 'ok';
}
else
{
echo '短信验证码发送失败';
}
}
function sendSMS ($mobile,$aa,$moban)
{ include_once(ROOT_PATH ."alidayu/TopClient.php");
include_once(ROOT_PATH ."alidayu/RequestCheckUtil.php");
include_once(ROOT_PATH ."alidayu/ResultSet.php");
include_once(ROOT_PATH ."alidayu/TopLogger.php");
include_once(ROOT_PATH ."alidayu/AlibabaAliqinFcSmsNumSendRequest.php");
$c = new TopClient;
$c->appkey = $GLOBALS['_CFG']['appkey'];
$c->secretKey = $GLOBALS['_CFG']['secretKey'];
$req = new AlibabaAliqinFcSmsNumSendRequest;
$req->setExtend("123456");
$req->setSmsType("normal");
$req->setSmsFreeSignName($GLOBALS['_CFG']['dayu_sign']);
$bb=json_encode($aa);
$req->setSmsParam($bb);
$req->setRecNum($mobile);
$req->setSmsTemplateCode($moban);
$resp = $c->execute($req);
$resp= (array)$resp;
$cc=(array)$resp['result'];
if ($cc['err_code']=='0')
{
return true;
}
else
{
return false;
}