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("发送失败,请重试"); } }
本文为看恩吧原创文章,转载无需和我联系,但请注明来自knsay.com