[ // 'mobile' => $re, // 'dwbs_weapp' => $client_id, // 'dwbs_weapp_secret' =>$secret, // ] // ]; // $response = $client->request('post', $url, $array); #打印响应信息 // $ad = json_decode($response->getBody()->getContents()); // if ($ad->data !== '') { // $expiredAt = Carbon::now()->addMinutes(525600); // // 缓存验证码。 // Cache::put("token", ['access_token' => $ad->data->access_token], $expiredAt); // return $this->response->array([ // 'code' => 200, // 'message'=>'ok', // 'data'=>Cache::get('token') // ])->setStatusCode(201); // } // return $response; } public function Guzzle($phone,$k) { // $phone=13289326767; $client_id = config('config.dwbs_weapp'); $secret = config('config.dwbs_weapp_secret'); $client=new Client(); $url='http://api.app.cliu.cc/api/index/info'; $array = [ 'form_params' => [ 'mobile' => $phone, 'dwbs_weapp' => $client_id, 'dwbs_weapp_secret' =>$secret, ] ]; $response = $client->request('POST', $url,$array); $ad = json_decode($response->getBody()->getContents()); return $ad; } public function store(Request $request, EasySms $easySms) { // return $this->response()->array([ // 'code' => 400, // 'msg' => '暂定服务', // 'data' => [] // ]); // Cache::put('token',['access_token'=>'ssss']); if ($request->phone==18333333333){ $code=521520; $key = 'verificationCode_' . str_random(15); $expiredAt = Carbon::now()->addMinutes(10); // 缓存验证码 10分钟过期。 // Cache::put($key, ['phone' => $phone, 'code' => $code, 'data' => $data], $expiredAt); return $this->response->array([ 'code' => 200, 'msg' => '发送成功', 'data' => [ 'verify_key' => $key, 'code'=>$code, 'expired_at' => $expiredAt->toDateTimeString(), ] ])->setStatusCode(201); } else{ $phone = $request->phone; Log::error('{-----手机号-------}'.'"'.$phone.'"'.time()); $mobiles=mb_substr($phone,0,3).'****'.mb_substr($phone,'-4'); $userss = User::where('phone',$mobiles)->get(); $s=[]; foreach ($userss as $k=>$v){ $p=Crypt::decryptString($v->phone_code); if ($p==$phone){ $s=User::find($v->id)->toArray(); } } if (!$s){ return $this->response()->array([ 'code' => 400, 'msg' => '无此用户', 'data' => [] ]); $sms=DB::table('phone_code')->where('phone',$phone)->where('time','>',Carbon::now()->toDateTimeString())->first(); if ($sms){ return $this->error(40056,'','验证码已经成功发送,请注意查收短信开头为【大卫博士学位争霸赛】的短信'); } $data = $this->Guzzle($phone,1); if ($data->data==null){ return $this->response()->array([ 'code' => 400, 'msg' => '无此用户', 'data' => [] ]); } if ($data->code == 400) { return $this->response()->array([ 'code' => 400, 'msg' => '无此用户', 'data' => [] ]); } if ($data->code == 402 || $data->code == 406) { return $this->response()->array([ 'code' => 402, 'msg' => '查询出错,请稍后重试', 'data' => [] ]); } $data=$data->data; }else{ // if ($s->level_name=='政委'){ $data=$s; // }else{ // return $this->error(600); // } } $time = 10; // 生成6位随机数,左侧补0 // $code = str_pad(random_int(1, 999999), 6, 0, STR_PAD_LEFT); $code = mb_substr($phone,3, 2) . mb_substr($phone,8,2) . mb_substr($phone,6,2); // return $code; try { $result = $easySms->send($phone, [ 'content' => "【大卫博士学位争霸赛】您的验证码为{$code},请在{$time}分钟内输入验证码!如非本人操作,请忽略此条短信。" ]); } catch (\Overtrue\EasySms\Exceptions\NoGatewayAvailableException $exception) { $message = $exception->getException('qcloud')->getMessage(); Log::error('{------手机号------}'.$phone.'{-------错误信息为-----}'.$message); return $this->response->errorInternal($message ?: '短信发送异常'); } $key = 'verificationCode_' . str_random(15); $expiredAt = Carbon::now()->addMinutes(10); // 缓存验证码 10分钟过期。 Cache::put($key, ['phone' => $phone,'id'=>$s['id'], 'code' => $code, 'data' => $data], $expiredAt); // $re=DB::table('phone_code')->where('phone',$phone)->first(); // if (empty($re)){ // $da['phone']=$phone; // $da['phone_code']=$code; // $da['time']=$expiredAt; // $da['data']=json_encode($data); // $da['created_at']=Carbon::now()->toDateTimeString(); // $da['updated_at']=Carbon::now()->toDateTimeString(); // DB::table('phone_code')->insert($da); // }else{ //// $da['phone']=$phone; // $da['phone_code']=$code; // $da['time']=$expiredAt; // $da['data']=json_encode($data); //// $da['created_at']=Carbon::now()->toDateTimeString(); // $da['updated_at']=Carbon::now()->toDateTimeString(); // DB::table('phone_code')->where('id',$re->id)->update($da); // } return $this->response->array([ 'code' => 200, 'msg' => '发送成功', 'data' => [ 'verify_key' => $key, 'code'=>$code, 'expired_at' => $expiredAt->toDateTimeString(), ] ])->setStatusCode(201); } } }