jiangping
2025-04-07 c25eabb1f91a05d35f3d56e1c27eb58ca6d60510
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.doumee.api.web;
 
import com.doumee.config.Jwt.JwtProperties;
import com.doumee.config.Jwt.JwtTokenUtil;
import com.doumee.config.annotation.LoginRequired;
import com.doumee.core.annotation.pr.PreventRepeat;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.ApiResponse;
import com.doumee.dao.business.model.Member;
import com.doumee.dao.web.dto.LoginH5DTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ServerWebExchange;
 
import javax.annotation.Resource;
 
/**
 * JWT获取令牌和刷新令牌接口
 */
@RestController
@Api(tags ="web端用户相关接口")
@RequestMapping("/web/member")
public class WebMemberController {
    @Resource
    private JwtTokenUtil jwtTokenUtil;
    @PreventRepeat(limit = 10, lockTime = 10000)
    @ApiOperation("H5业务登录")
    @PostMapping("/loginH5")
    public ApiResponse<Member> loginH5 (@Validated @RequestBody LoginH5DTO dto, ServerWebExchange serverWebExchange) {
        try {
            ServerHttpRequest request = serverWebExchange.getRequest();
            //---------TODO-----任康---做用户登录逻辑处理-------start-------
            //拿CODE换qwid,先查下本系统是否存在,存在直接返回member,否则用qwid查询企业用户数据,插入数据库(member)
            Member user =  new Member();
 
            //---------TODO--------做用户登录逻辑处理-------end-------
            String token = jwtTokenUtil.generateToken(user);
            user.setToken(token);
            return ApiResponse.success(user);
        }catch (BusinessException e){
            return ApiResponse.failed(e.getCode(),e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return ApiResponse.failed(ResponseStatus.SERVER_ERROR);
        }
    }
    @ApiOperation("更新用户信息")
    @PostMapping("/upateInfo")
    public ApiResponse<String> upateInfo (@Validated @RequestBody LoginH5DTO dto, ServerWebExchange serverWebExchange) {
        try {
            ServerHttpRequest request = serverWebExchange.getRequest();
            //---------TODO-----任康---做用户信息更新(邮箱)处理-------start-------
            Member user =  new Member();
 
            //---------TODO--------做用户信息更新(邮箱)处理-------end-------
            String token = jwtTokenUtil.generateToken(user);
            return ApiResponse.success(token);
        }catch (BusinessException e){
            return ApiResponse.failed(e.getCode(),e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return ApiResponse.failed(ResponseStatus.SERVER_ERROR);
        }
    }
    /**
     * 刷新JWT令牌,用旧的令牌换新的令牌
     */
    @GetMapping("/getMemberInfo")
    @ApiOperation("获取当前登陆用户")
    @LoginRequired
    public ApiResponse<Member> getMemberInfo(@RequestHeader(JwtTokenUtil.HEADER_KEY) String token){
        try {
            Member user =jwtTokenUtil.getUserInfoByToken(token);
            //---------TODO------任康--检查用户信息当前是否合法-------start-------
 
            //---------TODO--------检查用户信息当前是否合法-------end-------
            jwtTokenUtil.refreshToken(token);//每次更新token有效期
           if(user !=null){
               return ApiResponse.success( user);
           }
        }catch (BusinessException e){
            return ApiResponse.failed(e.getCode(),e.getMessage());
        }catch (Exception e){
            return ApiResponse.failed(ResponseStatus.SERVER_ERROR);
        }
        return ApiResponse.failed( "登录已失效");
    }
 
}