Пример #1
0
 /**
  * 激活 第一步 POST
  * @author Hanxinag
  */
 public function activateS1Post()
 {
     $input = Input::all();
     $validator = Validator::make($input, ['mobile' => 'required', 'code' => 'required', 'sn' => 'required']);
     if ($validator->fails()) {
         return redirect()->back()->with('error_tips', $validator->messages()->first());
     }
     // check mobile and code
     $check = SmsCode::checkCode($input['mobile'], $input['code']);
     if (!$check) {
         return redirect()->back()->with('error_tips', "验证码错误");
     }
     // check seller
     $seller = Seller::where('mobile', $input['mobile'])->first();
     if (count($seller) == 0) {
         return redirect()->back()->with('error_tips', "手机号不存在");
     }
     $shop = $seller->shop;
     $shopService = new ShopService();
     $bindResult = $shopService->bindDevice($shop, $input['sn']);
     if ($bindResult) {
         return redirect()->route('sellerActivateS2')->with('success_tips', "绑定成功");
     } else {
         return redirect()->back()->with('error_tips', "绑定失败");
     }
 }
Пример #2
0
 /**
  * 检查手机号和验证码是否已存在
  * @author Hanxiang
  * @param $mobile
  * @param $code
  * @return bool
  */
 public static function checkMobile($mobile, $code)
 {
     $smsCode = self::where('mobile', $mobile)->first();
     if (count($smsCode) > 0) {
         if (time() - strtotime($smsCode->created_at) < 30) {
             // TODO
             return false;
             //存在,且小于30秒
         } else {
             $smsCode->code = $code;
             $smsCode->save();
             return true;
         }
     } else {
         $smsCode = new SmsCode();
         $smsCode->mobile = $mobile;
         $smsCode->code = $code;
         $smsCode->ip = '';
         $smsCode->save();
         return true;
     }
 }
Пример #3
0
 /**
  * 发送短信验证码
  * @author Hanxiang
  */
 public function sendSmsCode()
 {
     $input = Input::all();
     $validator = Validator::make($input, ['mobile' => 'required']);
     if ($validator->fails()) {
         return $this->sendResponse(20101, $validator->messages()->first());
     }
     if (!preg_match('/^[1][34578]\\d{9}$/', $input['mobile'])) {
         return $this->sendResponse(20102, 'mobile invalid');
     }
     $code = mt_rand(1000, 9999);
     $check = SmsCode::checkMobile($input['mobile'], $code);
     if (!$check) {
         return $this->sendResponse(20103, 'please retry after 30s');
     }
     Yunpian::sendSmsCode($input['mobile'], $code);
     return $this->sendResponse(10000, 'success');
 }