소스 검색

fixed:用户端->微信-回调

刘学玺 4 달 전
부모
커밋
a3612a50aa
1개의 변경된 파일5개의 추가작업 그리고 3개의 파일을 삭제
  1. 5 3
      app/Services/Client/WechatService.php

+ 5 - 3
app/Services/Client/WechatService.php

@@ -76,7 +76,8 @@ class WechatService
             $user = $this->socialite->userFromCode($code);
 
             // 验证openid
-            abort_if(empty($user->getId()), 400, '获取微信openid失败');
+            $openid = $user->getId();
+            abort_if(empty($openid), 400, '获取微信openid失败');
 
             // 整理用户信息
             $userInfo = $this->formatUserInfo($user);
@@ -87,7 +88,7 @@ class WechatService
             }
 
             // 执行登录
-            return $this->accountService->wxLogin($user->getId(), $userInfo);
+            return $this->accountService->wxLogin($openid, $userInfo);
         } catch (BusinessException $e) {
             throw $e;
         } catch (\Exception $e) {
@@ -96,6 +97,7 @@ class WechatService
                 'state' => $state,
                 'invite_code' => $inviteCode,
                 'user_info' => $user ?? null,
+                'openid' => $openid ?? null,
             ]);
             throw new BusinessException('微信授权失败,请稍后重试');
         }
@@ -183,7 +185,7 @@ class WechatService
     /**
      * 格式化性别信息
      *
-     * @param  int|null  $gender  微信返回��性别值:1为男性,2为女性,0为未知
+     * @param  int|null  $gender  微信返回性别值:1为男性,2为女性,0为未知
      * @return string|null male/female/null
      */
     protected function formatGender(?int $gender): ?string