Răsfoiți Sursa

fix(cfc-backend): wechatLogin use real code2Session API instead of mock openid

User 2 luni în urmă
părinte
comite
1170a3652c

+ 7 - 2
cfc-backend/src/main/java/com/etotem/cfc/service/UserService.java

@@ -58,8 +58,13 @@ private OnboardingService onboardingService;
 private FamilyInvitationService familyInvitationService;
 
     public LoginResultDTO wechatLogin(WechatLoginDTO dto) {
-        // 模拟微信登录,实际需要调用微信API获取openid
-        String openid = "mock_openid_" + dto.getCode();
+        // 通过code获取真实openid(调微信code2session接口)
+        Map<String, String> sessionData = wechatService.code2Session(dto.getCode());
+        String openid = sessionData.get("openid");
+        String unionid = sessionData.get("unionid");
+        if (openid == null || openid.isEmpty()) {
+            throw new RuntimeException("获取openid失败,请重试");
+        }
         
         // 查询用户是否存在
         User user = userMapper.selectOne(new LambdaQueryWrapper<User>()