阿里云发送短信

public function sendsmscode()
    {
        $param = $this->request->param();

        $geetestconfig = Config::get('geetestconfig');
        $geetest       = new Geetest((array) $geetestconfig);

        if (1 == Session('geetest_status')) {
            if (!$geetest->success_validate($param['geetest_challenge'], $param['geetest_validate'], $param['geetest_seccode'], Session('geetest_userid'))) {
                $this->error('请通过智能验证');
                exit;
            }
        } else {
            if (!$geetest->fail_validate($param['geetest_challenge'], $param['geetest_validate'], $param['geetest_seccode'])) {
                $this->error('请通过智能验证');
                exit;
            }
        }
        
        if (!checkmobile($param['mobile'])) {
            $this->error('手机号格式错误');
        }

        //查询手机号是否存在
        $res=Db::name('bj_user')->where("mobile",$param['mobile'])->find();
        if ($res) {
            $this->error('手机号已经注册');
        }

        // 检测发送次数
        $end = time()-86400;
        $res=Db::name('bj_smslog')->where("mobile",$mobile)->where('sendtime', '>=', $end)->count();
        
        if ($res>=3) {
            $this->error('次数超限');
        }
        $ip = request()->ip();
        $res=Db::name('bj_smslog')->where("ip",ip2long($ip))->where('sendtime', '>=', $end)->count();

        if ($res>=3) {
            $this->error('次数超限');
        }

        $smscode = mt_rand(100000,999999);
        // 发送短信
        $aliconfig = Config::get('aliconfig');
        $client  = new Client($aliconfig);
        $sendSms = new SendSms;
        $sendSms->setPhoneNumbers($mobile);
        $sendSms->setSignName('xxxxxxx');
        $sendSms->setTemplateCode('SMS_188888888');
        $sendSms->setTemplateParam(['code' => $smscode]);
        $result = $client->execute($sendSms);

        if($result->Code == 'OK'){
            session($mobile, $smscode);
            Db::name('bj_smslog')->add(array('ip'=>ip2long(request()->ip()),'mobile'=>$mobile,'addtime'=>time(),'smscode'=>$smscode));
            $this->success('发送成功');
        }else{
            $this->error("发送失败,请重试");
        }
    }


打赏

看恩吧
网站不承担任何有关评论的责任
  • 最新评论
  • 总共条评论
取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦