token = Auth::refresh(); $user->token_ttl = config('jwt.ttl'); $user->is_password = !empty($user->password)?1:0; $fractal = new Manager(); $res = new Item($user,new LoginTransformer()); $array = $fractal->createData($res)->toArray(); //同一类型登陆只允许登陆一个 return $this->jsonSuccess($array); } /** * 登出 * @return mixed */ public function logout() { Auth::logout(); return $this->jsonSuccess([],'登出成功'); } //登陆 public function login(Request $request){ $data = $request->all(); $validator = Validator::make($data, [ 'account' => 'required|max:50', 'password' => 'required|max:32', ]); if ($validator->fails()) { return $this->response->error($validator->errors()->first(), 500); } $account = ShopAccount::where(['account'=>$data['account'],'status'=>1])->first(); if(!$account){ return $this->response->error('登录失败,请重试', 500); } $token = Auth::attempt(['account'=>$request->get('account'),'password'=>$request->get('password')]); if(!$token){ return $this->response->error('登陆失败', 500); }else{ $shopAccount = Auth::user(); $factory = JWTFactory::customClaims(['shop'=>['uid'=>$shopAccount->id,'username'=>$shopAccount->account,'shop_id'=>$shopAccount->shop_id,'sign'=>md5($shopAccount->id).config('customer.jwt_secret')],'type'=>2]); $payload = $factory->make(); $token = JWTAuth::encode($payload); $shopAccount->token = $token; $shopAccount->token_ttl = config('jwt.ttl'); //如果有绑定微信,显示微信open_id $fractal = new Manager(); $res = new Item($shopAccount,new LoginTransformer()); $array = $fractal->createData($res)->toArray(); //日志 return $array; } } }