diff --git a/app/Service/v3/Implementations/UserInfoService.php b/app/Service/v3/Implementations/UserInfoService.php index 09b30ed..0b08a39 100644 --- a/app/Service/v3/Implementations/UserInfoService.php +++ b/app/Service/v3/Implementations/UserInfoService.php @@ -29,40 +29,45 @@ class UserInfoService implements UserInfoServiceInterface public function do($userId, $iv, $encryptedData) { - $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - $user = $ssdb->exec('hgetall', SsdbKeys::USER_INFO.$userId); + try { + $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); + $user = $ssdb->exec('hgetall', SsdbKeys::USER_INFO.$userId); - // 微信登录 - $config = config('applet'); - $app = Factory::miniProgram($config); - $app['guzzle_handler'] = CoroutineHandler::class; - $decryptedData = $app->encryptor->decryptData($user['session_key'], $iv, $encryptedData); + // 微信登录 + $config = config('applet'); + $app = Factory::miniProgram($config); + $app['guzzle_handler'] = CoroutineHandler::class; + $decryptedData = $app->encryptor->decryptData($user['session_key'], $iv, $encryptedData); - $data = [ - 'nick_name' => $decryptedData['nickName'], - 'avatar' => $decryptedData['avatarUrl'], - 'openid' => $decryptedData['openId'], - 'unionid' => $decryptedData['unionId'], - 'country' => $decryptedData['country'], - 'province' => $decryptedData['province'], - 'city' => $decryptedData['city'], - 'gender' => $decryptedData['gender'], - 'language' => $decryptedData['language'], - ]; - $user = User::query()->find($userId); - $res = $user->fill($data)->save(); - - if (!$res) { - $logArr = [ - 'userId' => $userId, - 'iv' => $iv, - 'encryptedData' => $encryptedData, - '$decryptedData' => $decryptedData + $data = [ + 'nick_name' => $decryptedData['nickName'], + 'avatar' => $decryptedData['avatarUrl'], + 'openid' => $decryptedData['openId'], + 'unionid' => $decryptedData['unionId'], + 'country' => $decryptedData['country'], + 'province' => $decryptedData['province'], + 'city' => $decryptedData['city'], + 'gender' => $decryptedData['gender'], + 'language' => $decryptedData['language'], ]; - throw new ErrorCodeException(ErrorCode::USER_INFO_UPDATE_ERROR,'更新用户信息失败',$logArr); + $user = User::query()->find($userId); + $res = $user->fill($data)->save(); + + if (!$res) { + $logArr = [ + 'userId' => $userId, + 'iv' => $iv, + 'encryptedData' => $encryptedData, + '$decryptedData' => $decryptedData + ]; + throw new ErrorCodeException(ErrorCode::USER_INFO_UPDATE_ERROR,'更新用户信息失败',$logArr); + } + + return $res; + } catch (\Exception $e) { + throw new ErrorCodeException(ErrorCode::USER_INFO_UPDATE_ERROR,'更新用户信息失败',['error_msg' => $e->getMessage()]); } - return $res; } public function check($userId)