input('mobile'); $password = request()->input('password'); if (empty($mobile) || empty($password)) return $this->failure("登陆失败,缺少登录信息"); if (!$result = $this->checkAuth($mobile, $password)) { return $this->failure("登陆失败,账号或者密码错误"); } $token = $result[0]; $user = $result[1]; return $this->success('ok', compact('user', 'token')); } /** * @param $mobile * @param $password * @return 检验账号密码是否正确 */ public function checkAuth($mobile, $password) { $user = UnionUser::where('mobile', $mobile)->first(); if (empty($user)) return false; $md5_password = md5(sha1($password) . 'ufutx2021$'); if ($user->password != $md5_password) return false; $token = auth('union')->tokenById($user->id); return [$token, $user]; } public function logout() { auth('union')->logout(); return $this->success('ok'); } /** * 公众号openid获取token * @return \Illuminate\Http\JsonResponse|string */ public function officialLogin() { $wechatUser = session('wechat.oauth_user.new'); if (empty($wechat_user)) return $this->failure("登陆失败,未微信授权"); $openid = $wechatUser->getId(); $plat = request()->input('plat', 'LO');//默认福恋公众号 $user = null; switch ($plat) { case 'LO': $user = Viewer::where('openid', $openid)->select('id', 'uuid', 'openid')->first(); break; case 'SO': $user = MerchantUser::where('openid', $openid)->select('id', 'uuid', 'openid')->first(); break; } if (empty($user) || empty($user->uuid)) return $this->failure("登陆失败,未获取登录信息"); $token = auth('union')->tokenById($user->uuid); return $this->success('ok', compact('user', 'token')); } public function userInfo() { return $this->success('ok', auth('union')->user()); } }