public function postSendCode(Request $request)
 {
     //get data
     extract($input = $this->parseInput($request));
     //validate
     $verifyResult = SM::validator($input);
     if (!$verifyResult['success']) {
         return response()->json($verifyResult);
     }
     //send verify sms
     $code = SM::generateCode();
     $minutes = SM::getCodeValidTime();
     $templates = SM::getVerifySmsTemplates();
     $template = SM::getVerifySmsContent();
     try {
         $content = vsprintf($template, [$code, $minutes]);
     } catch (\Exception $e) {
         $content = $template;
     }
     $result = $this->phpSms->make($templates)->to($mobile)->data(['code' => $code, 'minutes' => $minutes])->content($content)->send();
     if ($result['success']) {
         $data = SM::getSentInfo();
         $data['sent'] = true;
         $data['mobile'] = $mobile;
         $data['code'] = $code;
         $data['deadline_time'] = time() + $minutes * 60;
         SM::storeSentInfo($token, $data);
         SM::setResendTime($token, $seconds);
         $verifyResult = SM::genResult(true, 'sms_send_success');
     } else {
         $verifyResult = SM::genResult(false, 'sms_send_failure');
     }
     return response()->json($verifyResult);
 }
Ejemplo n.º 2
0
 /**
  * 设置可以发送短信的时间
  *
  * @param int $token
  * @param int $seconds
  * @return int 
  * @static 
  */
 public static function setResendTime($token, $seconds = 60)
 {
     return \Toplan\Sms\SmsManager::setResendTime($token, $seconds);
 }