Exemplo n.º 1
0
function dxyzm()
{
    $sessionid = session_id();
    $user_phone = isset($_POST['userphone']) ? $_POST['userphone'] : '';
    $sign = isset($_POST['sign']) ? $_POST['sign'] : 'in';
    $user_phone = substr($user_phone, 1);
    $token = isset($_POST['token']) ? $_POST['token'] : '';
    if (!$user_phone || strlen($user_phone) != 11 || !Func::checkmobile($user_phone)) {
        ABase::toJson(1, '请正确输入手机号码');
    }
    $_SESSION['tmp_user'] = $user_phone;
    if (!$sessionid || !$token || !ABase::token($token)) {
        $_SESSION['tmp_get_yzm'] = 1;
        ABase::toJson(-1, '请求异常或自动刷新');
    }
    $dxyzm_send_num = isset($_SESSION['dxyzm_send_num']) ? (int) $_SESSION['dxyzm_send_num'] : 0;
    if ($dxyzm_send_num > 10) {
        ABase::toJson(1, '您今日发送短信数过多');
    }
    $user = Users::check($user_phone);
    $userid = isset($user['id']) ? (int) $user['id'] : 0;
    $ustatus = isset($user['status']) ? (int) $user['status'] : 0;
    if ('in' === $sign) {
        if (!$userid) {
            ABase::toJson(1, '手机号码未注册');
        }
        if ($ustatus < 0) {
            ABase::toJson(1, '该账号被冻结,详情请致电本公司。');
        }
    } else {
        if ($userid) {
            ABase::toJson(1, '手机号码被占用');
        }
    }
    $_SESSION['dxyzm_send_num'] = $dxyzm_send_num + 1;
    $_SESSION['dxyzm'] = $vcode = rand(100000, 999999);
    $plaintext = $user_phone . '-1001-' . $vcode;
    if (!_DEVDEBUG) {
        $pcontent = ABase::RSASignature($plaintext, _USERMOBSEND);
    } else {
        $pcontent = "1,ok";
        //test
    }
    $pcontent = explode(',', $pcontent);
    $status = isset($pcontent[0]) ? (int) $pcontent[0] : 0;
    $msg = isset($pcontent[1]) ? $pcontent[1] : '';
    if (1 != $status) {
        ABase::toJson(1, $msg);
    } else {
        if (!_DEVDEBUG) {
            ABase::toJson(0, $msg);
        } else {
            ABase::toJson(0, $msg, array($vcode));
            //test
        }
    }
}