Zhangbw 3 месяцев назад
Родитель
Сommit
a2abdbc10c

+ 13 - 8
LOGIN_FLOW.md

@@ -12,7 +12,7 @@
 
 **流程**:
 1. 前端调用 `wx.login()` 获取 `code`
-2. 发送到后端:`POST /auth/sys/miniapp/custom/openid`
+2. 发送到后端:`POST /v1/auth/wx/silent-login`
 3. 后端用 `code` 调用微信API获取 `openid`
 4. 根据 `openid` 查询数据库
 5. 返回结果:
@@ -27,7 +27,7 @@
 1. 用户点击授权按钮(`open-type="getPhoneNumber"`)
 2. 微信弹窗授权,获取 `encryptedData` 和 `iv`
 3. 重新调用 `wx.login()` 获取新的 `code`
-4. 发送到后端:`POST /auth/sys/miniapp/custom/check`
+4. 发送到后端:`POST /v1/auth/wx/phone-verify`
    ```json
    {
      "loginCode": "新的code",
@@ -50,7 +50,7 @@
 1. 弹出用户信息弹窗
 2. 用户输入昵称、选择头像
 3. 上传头像到服务器
-4. 发送到后端:`POST /auth/sys/miniapp/custom/login`
+4. 发送到后端:`POST /v1/auth/wx/register`
    ```json
    {
      "openid": "用户openid",
@@ -94,11 +94,16 @@ String decryptedData = new String(decryptedBytes, "UTF-8");
 
 | 接口 | 方法 | 说明 |
 |------|------|------|
-| `/auth/sys/miniapp/custom/openid` | POST | 第一步:静默登录 |
-| `/auth/sys/miniapp/custom/check` | POST | 第二步:手机号验证 |
-| `/auth/sys/miniapp/custom/login` | POST | 第三步:完善信息 |
-| `/wd/miniapp-member/bizBigMember/getMemberInfoByToken` | GET | 获取用户信息 |
-| `/jeecg-boot/mg/sys/oss/file/upload` | POST | 上传头像 |
+| `/v1/auth/wx/silent-login` | POST | 第一步:静默登录 |
+| `/v1/auth/wx/phone-verify` | POST | 第二步:手机号验证 |
+| `/v1/auth/wx/register` | POST | 第三步:完善信息 |
+| `/v1/user/info` | GET | 获取用户信息 |
+| `/v1/file/upload` | POST | 上传头像 |
+| `/v1/stock/search` | POST | 股票搜索 |
+| `/v1/stock/suggestion` | GET | 搜索建议 |
+| `/v1/user/profile` | PUT | 更新用户资料 |
+| `/v1/user/portfolio` | GET | 获取用户资产(待实现) |
+| `/v1/rank/leaderboard` | GET | 排行榜(待实现) |
 
 ## 优势
 

+ 14 - 19
src/main/java/com/yingpai/gupiao/controller/AuthController.java

@@ -11,29 +11,25 @@ import org.springframework.web.bind.annotation.*;
 
 /**
  * 认证控制器
- * 处理用户登录、注册、验证码等请求
- * 
- * 完整登录流程:
- * 1. /auth/sys/miniapp/custom/openid - 检查是否为老用户(静默登录)
- * 2. /auth/sys/miniapp/custom/check - 验证手机号(新用户)
- * 3. /auth/sys/miniapp/custom/login - 完善用户信息(首次登录)
+ * 处理用户登录、注册相关请求
+ *
  */
 @Slf4j
 @RestController
 @RequiredArgsConstructor
-@RequestMapping("/auth/sys/miniapp")
+@RequestMapping("/v1/auth/wx")
 public class AuthController {
     
     private final AuthService authService;
     
     /**
      * 第一步:微信静默登录(检查是否为老用户)
-     * 接口路径:/auth/sys/miniapp/custom/openid
+     * 接口路径:POST /v1/auth/wx/silent-login
      * 
      * @param dto 包含 loginCode
      * @return 老用户返回 { isSign: "true", token },新用户返回 { isSign: "false" }
      */
-    @PostMapping("/custom/openid")
+    @PostMapping("/silent-login")
     public Result<WxLoginCheckVO> wxSilentLogin(@RequestBody WxSilentLoginDTO dto) {
         log.info("【第一步】微信静默登录,loginCode: {}", dto.getLoginCode());
         
@@ -52,22 +48,21 @@ public class AuthController {
     
     /**
      * 第二步:手机号授权验证(新用户)
-     * 接口路径:/auth/sys/miniapp/custom/check
+     * 接口路径:POST /v1/auth/wx/phone-verify
      * 
      * @param dto 包含 loginCode, phoneCode, encryptedData, iv
      * @return 已注册返回 { isSign: "true", token },未注册返回 { isSign: "false", openid, unionid, phoneNumber }
      */
-    @PostMapping("/custom/check")
-    public Result<WxLoginCheckVO> wxPhoneCheck(@RequestBody WxPhoneLoginDTO dto) {
-        log.info("【第二步】手机号授权验证,loginCode: {}, phoneCode: {}", 
-                dto.getLoginCode(), dto.getPhoneCode());
+    @PostMapping("/phone-verify")
+    public Result<WxLoginCheckVO> wxPhoneVerify(@RequestBody WxPhoneLoginDTO dto) {
+        log.info("【第二步】手机号授权验证,loginCode: {}", dto.getLoginCode());
         
         if (dto.getLoginCode() == null || dto.getLoginCode().isEmpty()) {
             return Result.error("登录code不能为空");
         }
         
-        if (dto.getPhoneCode() == null || dto.getPhoneCode().isEmpty()) {
-            return Result.error("手机号授权code不能为空");
+        if (dto.getEncryptedData() == null || dto.getIv() == null) {
+            return Result.error("手机号加密数据不能为空");
         }
         
         try {
@@ -81,13 +76,13 @@ public class AuthController {
     
     /**
      * 第三步:完善用户信息(首次登录)
-     * 接口路径:/auth/sys/miniapp/custom/login
+     * 接口路径:POST /v1/auth/wx/register
      * 
      * @param dto 包含 openid, unionid, phoneNumber, nickname, avatarUrl
      * @return 返回 { token }
      */
-    @PostMapping("/custom/login")
-    public Result<LoginVO> wxCompleteUserInfo(@RequestBody WxCompleteUserInfoDTO dto) {
+    @PostMapping("/register")
+    public Result<LoginVO> wxRegister(@RequestBody WxCompleteUserInfoDTO dto) {
         log.info("【第三步】完善用户信息,openid: {}, phone: {}, nickname: {}", 
                 dto.getOpenid(), dto.getPhoneNumber(), dto.getNickname());
         

+ 3 - 2
src/main/java/com/yingpai/gupiao/controller/FileUploadController.java

@@ -24,6 +24,7 @@ import java.util.UUID;
 @Slf4j
 @RestController
 @RequiredArgsConstructor
+@RequestMapping("/v1/file")
 public class FileUploadController {
     
     /**
@@ -50,12 +51,12 @@ public class FileUploadController {
     
     /**
      * 文件上传接口
-     * 接口路径:/jeecg-boot/mg/sys/oss/file/upload
+     * 接口路径:POST /v1/file/upload
      * 
      * @param file 上传的文件
      * @return 文件访问URL
      */
-    @PostMapping("/jeecg-boot/mg/sys/oss/file/upload")
+    @PostMapping("/upload")
     public Result<Map<String, String>> uploadFile(@RequestParam("file") MultipartFile file) {
         log.info("文件上传请求,文件名: {}, 大小: {} bytes", file.getOriginalFilename(), file.getSize());
         

+ 7 - 26
src/main/java/com/yingpai/gupiao/controller/UserController.java

@@ -16,41 +16,20 @@ import org.springframework.web.bind.annotation.*;
 @Slf4j
 @RestController
 @RequiredArgsConstructor
+@RequestMapping("/v1/user")
 public class UserController {
     
     private final UserService userService;
     private final JwtUtil jwtUtil;
     
     /**
-     * 第四步:获取用户完整信息(通过token)
-     * 接口路径:/wd/miniapp-member/bizBigMember/getMemberInfoByToken
+     * 获取用户信息(通过token)
+     * 接口路径:GET /v1/user/info
      * 
      * @param authorization 请求头中的token
      * @return 用户完整信息
      */
-    @GetMapping("/wd/miniapp-member/bizBigMember/getMemberInfoByToken")
-    public Result<LoginVO.UserInfoVO> getMemberInfoByToken(@RequestHeader("Authorization") String authorization) {
-        try {
-            // 从token中获取用户ID
-            String token = authorization.replace("Bearer ", "");
-            Long userId = jwtUtil.getUserIdFromToken(token);
-            
-            log.info("【第四步】获取用户完整信息,userId: {}", userId);
-            
-            LoginVO.UserInfoVO userInfo = userService.getUserInfo(userId);
-            return Result.success(userInfo);
-        } catch (Exception e) {
-            log.error("获取用户信息失败", e);
-            return Result.error("获取用户信息失败:" + e.getMessage());
-        }
-    }
-    
-    /**
-     * 获取用户信息(原有接口)
-     * @param authorization 请求头中的token
-     * @return 用户信息
-     */
-    @GetMapping("/v1/user/info")
+    @GetMapping("/info")
     public Result<LoginVO.UserInfoVO> getUserInfo(@RequestHeader("Authorization") String authorization) {
         try {
             // 从token中获取用户ID
@@ -69,11 +48,13 @@ public class UserController {
     
     /**
      * 更新用户资料
+     * 接口路径:PUT /v1/user/profile
+     * 
      * @param authorization 请求头中的token
      * @param updateProfileDTO 更新资料DTO
      * @return 更新后的用户信息
      */
-    @PutMapping("/v1/user/profile")
+    @PutMapping("/profile")
     public Result<LoginVO.UserInfoVO> updateProfile(
             @RequestHeader("Authorization") String authorization,
             @RequestBody UpdateProfileDTO updateProfileDTO) {

+ 1 - 1
src/main/java/com/yingpai/gupiao/service/impl/AuthServiceImpl.java

@@ -117,7 +117,7 @@ public class AuthServiceImpl implements AuthService {
             String phone = null;
             
             if (dto.getEncryptedData() != null && dto.getIv() != null && sessionKey != null) {
-                // 使用旧版解密方式(不需要开通手机号快速验证组件)
+                // 使用本地解密方式
                 log.info("使用encryptedData解密手机号");
                 phone = wxApiUtil.decryptPhoneNumber(dto.getEncryptedData(), sessionKey, dto.getIv());
                 log.info("解密手机号成功: {}", phone);