Ver Fonte

登录修改

skyline há 1 mês atrás
pai
commit
4d008b7ba9

+ 5 - 4
haha-service/src/main/java/com/haha/service/impl/LoginServiceImpl.java

@@ -188,19 +188,20 @@ public class LoginServiceImpl implements LoginService {
             }
             
             // 使用手机号获取凭证换取手机号
-            // 根据微信官方文档,access_token应该在URL参数中
             String url = String.format(
                 "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=%s",
                 accessToken
             );
             
-            Map<String, String> requestBody = new HashMap<>();
-            requestBody.put("code", phoneCode);
+            // 构建JSON请求体字符串,确保Content-Length正确
+            String requestBody = String.format("{\"code\":\"%s\"}", phoneCode);
             
             HttpHeaders headers = new HttpHeaders();
             headers.set("Content-Type", "application/json");
             headers.set("Accept", "application/json");
-            HttpEntity<Map<String, String>> entity = new HttpEntity<>(requestBody, headers);
+            headers.setContentLength(requestBody.getBytes(java.nio.charset.StandardCharsets.UTF_8).length);
+            
+            HttpEntity<String> entity = new HttpEntity<>(requestBody, headers);
             
             log.info("[微信API] 请求获取手机号 - phoneCode: {}", 
                     phoneCode != null ? phoneCode.substring(0, Math.min(10, phoneCode.length())) + "..." : "null");