LaneSonnet 2017-12-29 13:03 采纳率: 100%
浏览 1413
已采纳

一个PHP短信验证码的问题,短信发送失败,不知道是旧的大鱼api问题,还是代码问题.

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;
}

  • 写回答

5条回答 默认 最新

  • JPF1024 2017-12-29 14:09
    关注

    没有提示吗?

    最好用最新API写一下,或者拿着返回代号去官方查一下。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?