Переглянути джерело

增加第三方接口-验证-获取用户列表

sunxbiao 1 рік тому
батько
коміт
6e55679ed4

+ 76 - 0
gateWay_server/src/main/java/com/bjtdba/gateWay/filter/ApiAuthFilter.java

@@ -0,0 +1,76 @@
1
+package com.bjtdba.gateWay.filter;
2
+// ApiAuthFilter.java
3
+import org.springframework.beans.factory.annotation.Value;
4
+import org.springframework.cloud.gateway.filter.GatewayFilter;
5
+import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
6
+import org.springframework.http.HttpStatus;
7
+import org.springframework.stereotype.Component;
8
+import org.springframework.util.DigestUtils;
9
+import org.springframework.web.server.ServerWebExchange;
10
+import reactor.core.publisher.Mono;
11
+
12
+@Component
13
+public class ApiAuthFilter extends AbstractGatewayFilterFactory<ApiAuthFilter.Config> {
14
+
15
+    @Value("${external.api.secret}")
16
+    private String apiSecret;  // 从配置文件注入密钥
17
+
18
+    private static final long TIMESTAMP_THRESHOLD = 300000;  // 5分钟有效期
19
+
20
+    public ApiAuthFilter() {
21
+        super(Config.class);
22
+    }
23
+
24
+    @Override
25
+    public GatewayFilter apply(Config config) {
26
+        return (exchange, chain) -> {
27
+            // 仅处理/external路径的请求
28
+            if (!exchange.getRequest().getPath().value().startsWith("/external")) {
29
+                return chain.filter(exchange);
30
+            }
31
+
32
+            // 1. 获取认证头信息
33
+            String apiKey = exchange.getRequest().getHeaders().getFirst("X-API-KEY");
34
+            String timestamp = exchange.getRequest().getHeaders().getFirst("X-TIMESTAMP");
35
+            String signature = exchange.getRequest().getHeaders().getFirst("X-SIGNATURE");
36
+
37
+            // 2. 验证必要头信息存在
38
+            if (apiKey == null || timestamp == null || signature == null) {
39
+                return unauthorized(exchange, "Missing authentication headers");
40
+            }
41
+
42
+            // 3. 验证时间戳有效性
43
+            try {
44
+                long requestTime = Long.parseLong(timestamp);
45
+                long currentTime = System.currentTimeMillis();
46
+
47
+                if (Math.abs(currentTime - requestTime) > TIMESTAMP_THRESHOLD) {
48
+                    return unauthorized(exchange, "Timestamp expired");
49
+                }
50
+            } catch (NumberFormatException e) {
51
+                return unauthorized(exchange, "Invalid timestamp format");
52
+            }
53
+
54
+            // 4. 生成并验证签名
55
+//            String expectedSignature = generateSignature(apiKey, timestamp);
56
+//            if (!expectedSignature.equalsIgnoreCase(signature)) {
57
+//                return unauthorized(exchange, "Invalid signature");
58
+//            }
59
+            System.out.println("Forwarding to: " + exchange.getRequest().getURI());
60
+            return chain.filter(exchange);
61
+        };
62
+    }
63
+
64
+    private Mono<Void> unauthorized(ServerWebExchange exchange, String reason) {
65
+        exchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED);
66
+        exchange.getResponse().getHeaders().add("X-Auth-Error", reason);
67
+        return exchange.getResponse().setComplete();
68
+    }
69
+
70
+    private String generateSignature(String apiKey, String timestamp) {
71
+        String data = apiKey + "|" + timestamp + "|" + apiSecret;
72
+        return DigestUtils.md5DigestAsHex(data.getBytes());
73
+    }
74
+
75
+    public static class Config {}
76
+}

+ 13 - 0
gateWay_server/src/main/resources/application-dev.yml

@@ -7,6 +7,14 @@
7 7
     gateway:
8 8
       # 路由数组:指当请求满足什么样的断言时,转发到哪个服务上
9 9
       routes:
10
+      # 新增外部系统专用路由(放在现有路由之前)
11
+      - id: external-api
12
+        uri: lb://userCenter-service
13
+        predicates:
14
+          - Path=/external/**  # 外部系统专用路径
15
+        filters:
16
+          - ApiAuthFilter  # 应用鉴权过滤器
17
+          - StripPrefix=1  # 移除/external前缀
10 18
       - id: wares
11 19
         uri: lb://wares-service # 路由对应的微服务转发地址   服务名称
12 20
         predicates:
@@ -85,3 +93,8 @@ logging:
85 93
     com:
86 94
       bjtdba:
87 95
         gateWay: DEBUG
96
+
97
+external:
98
+  api:
99
+    key: "EXTERNAL_SYSTEM_B_KEY"   # 分配给外部系统B的API Key
100
+    secret: "STRONG_SECRET_123456"  # 高强度密钥(实际使用中应更复杂)

+ 1 - 1
gateWay_server/src/main/resources/application.yml

@@ -1,5 +1,5 @@
1 1
 server:
2
-  port: 9000
2
+  port: 9002
3 3
 spring:
4 4
   application:
5 5
     name: gateWay-server

+ 1 - 1
thirdPartyWares_service/src/main/resources/static/baichuan.html

@@ -2,7 +2,7 @@
2 2
 <html lang="zh-CN">
3 3
 <head>
4 4
 <meta charset="utf-8">
5
-<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
5
+<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,userEntity-scalable=no"/>
6 6
 <title></title>
7 7
 </head>
8 8
 <body>

+ 4 - 0
userCenter_service/pom.xml

@@ -98,6 +98,10 @@
98 98
             <artifactId>hutool-all</artifactId>
99 99
             <version>4.4.5</version>
100 100
         </dependency>
101
+        <dependency>
102
+            <groupId>org.aspectj</groupId>
103
+            <artifactId>aspectjweaver</artifactId>
104
+        </dependency>
101 105
     </dependencies>
102 106
     <build>
103 107
         <plugins>

+ 9 - 0
userCenter_service/src/main/java/com/bjtdba/userCenter/controller/UserController.java

@@ -5,6 +5,9 @@ import com.bjtdba.entity.order.User;
5 5
 import com.bjtdba.entity.userCenter.UserAddress;
6 6
 import com.bjtdba.entity.userCenter.UserBill;
7 7
 import com.bjtdba.entity.userCenter.UserCertification;
8
+import com.bjtdba.userCenter.dto.request.GetUserListRequest;
9
+import com.bjtdba.userCenter.dto.response.common.PageResult;
10
+import com.bjtdba.userCenter.dto.response.common.UserDTO;
8 11
 import com.bjtdba.userCenter.service.UserAddressService;
9 12
 import com.bjtdba.userCenter.service.UserCertificationService;
10 13
 import com.bjtdba.userCenter.service.UserService;
@@ -13,8 +16,10 @@ import com.bjtdba.userCenter.vo.UserAddressVo;
13 16
 import com.bjtdba.userCenter.vo.UserInfoVo;
14 17
 import com.bjtdba.utils.ResponseUtil;
15 18
 import org.springframework.beans.factory.annotation.Autowired;
19
+import org.springframework.http.ResponseEntity;
16 20
 import org.springframework.web.bind.annotation.*;
17 21
 
22
+import javax.validation.Valid;
18 23
 import java.io.InputStream;
19 24
 import java.math.BigDecimal;
20 25
 import java.util.*;
@@ -594,4 +599,8 @@ public class UserController {
594 599
         return ResponseUtil.ok(data);
595 600
     }
596 601
 
602
+    @GetMapping("/getUserList")
603
+    public ResponseEntity<PageResult<UserDTO>> getUserList(@Valid GetUserListRequest request) {
604
+        return ResponseEntity.ok(userService.getUserList(request));
605
+    }
597 606
 }

+ 18 - 0
userCenter_service/src/main/java/com/bjtdba/userCenter/dao/UserDao.java

@@ -1,8 +1,10 @@
1 1
 package com.bjtdba.userCenter.dao;
2 2
 
3 3
 import com.bjtdba.entity.userCenter.User;
4
+import com.bjtdba.userCenter.entity.UserEntity;
4 5
 import com.bjtdba.userCenter.vo.UserInviteVo;
5 6
 import org.apache.ibatis.annotations.Mapper;
7
+import org.apache.ibatis.annotations.Param;
6 8
 import org.springframework.stereotype.Repository;
7 9
 
8 10
 import java.math.BigDecimal;
@@ -36,4 +38,20 @@ public interface UserDao {
36 38
     void updateUserMerIdByPhone(int mer_id, Integer uid);
37 39
 
38 40
     void updateSpreadCount(int uid, int spread_count);
41
+
42
+    List<UserEntity> getUserList(
43
+            @Param("phone") String phone,
44
+            @Param("nickname") String nickname,
45
+            @Param("uid") Long uid,
46
+            @Param("status") Integer status,
47
+            @Param("offset") int offset,
48
+            @Param("pageSize") int pageSize
49
+    );
50
+
51
+    long getUserListCount(
52
+            @Param("phone") String phone,
53
+            @Param("nickname") String nickname,
54
+            @Param("uid") Long uid,
55
+            @Param("status") Integer status
56
+    );
39 57
 }

+ 34 - 0
userCenter_service/src/main/java/com/bjtdba/userCenter/dto/request/GetUserListRequest.java

@@ -0,0 +1,34 @@
1
+package com.bjtdba.userCenter.dto.request;
2
+
3
+import lombok.Getter;
4
+import lombok.Setter;
5
+
6
+import javax.validation.constraints.Pattern;
7
+import javax.validation.constraints.Positive;
8
+
9
+@Getter
10
+@Setter
11
+public class GetUserListRequest {
12
+    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式错误")
13
+    private String phone;
14
+
15
+    private String nickname;
16
+
17
+    @Positive(message = "用户ID必须为正数")
18
+    private Long uid;
19
+
20
+    @Positive(message = "状态值必须为正数")
21
+    private Integer status;
22
+
23
+    @Positive(message = "页码必须为正数")
24
+    private Integer pageNum = 1;
25
+
26
+    @Positive(message = "每页数量必须为正数")
27
+    private Integer pageSize = 10;
28
+
29
+    // 分页偏移量计算
30
+    public int getOffset() {
31
+        return (pageNum - 1) * pageSize;
32
+    }
33
+
34
+}

+ 19 - 0
userCenter_service/src/main/java/com/bjtdba/userCenter/dto/response/common/PageResult.java

@@ -0,0 +1,19 @@
1
+package com.bjtdba.userCenter.dto.response.common;
2
+
3
+import lombok.Getter;
4
+import java.util.List;
5
+
6
+@Getter
7
+public class PageResult<T> {
8
+    private final List<T> list;
9
+    private final int pageNum;
10
+    private final int pageSize;
11
+    private final long total;
12
+
13
+    public PageResult(List<T> list, int pageNum, int pageSize, long total) {
14
+        this.list = list;
15
+        this.pageNum = pageNum;
16
+        this.pageSize = pageSize;
17
+        this.total = total;
18
+    }
19
+}

+ 25 - 0
userCenter_service/src/main/java/com/bjtdba/userCenter/dto/response/common/UserDTO.java

@@ -0,0 +1,25 @@
1
+package com.bjtdba.userCenter.dto.response.common;
2
+
3
+import com.fasterxml.jackson.annotation.JsonFormat;
4
+import lombok.Getter;
5
+import lombok.Setter;
6
+import java.math.BigDecimal;
7
+import java.sql.Timestamp;
8
+
9
+@Getter
10
+@Setter
11
+public class UserDTO {
12
+    private Long uid;
13
+    private String nickname;
14
+    private String avatar;
15
+    private String phone;
16
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
17
+    private Timestamp createTime;
18
+    private BigDecimal nowMoney;
19
+    private Integer status;
20
+    private String userType;
21
+    private Integer identity;
22
+    private BigDecimal contribute;
23
+    private BigDecimal jingdou;
24
+}
25
+

+ 114 - 0
userCenter_service/src/main/java/com/bjtdba/userCenter/entity/UserEntity.java

@@ -0,0 +1,114 @@
1
+package com.bjtdba.userCenter.entity;
2
+import lombok.Getter;
3
+import lombok.Setter;
4
+import java.math.BigDecimal;
5
+import java.sql.Timestamp;
6
+import java.util.Date;
7
+
8
+@Getter
9
+@Setter
10
+public class UserEntity {
11
+    private Long uid;
12
+    private String wechatUserId;
13
+    private String aliUserId;
14
+    private String account;
15
+    private String pwd; // 敏感字段,DTO中不返回
16
+    private String realName;
17
+    private Long spreadUid;
18
+    private Integer sex;
19
+    private Date birthday;
20
+    private String cardId; // 敏感字段
21
+    private String mark;
22
+    private String labelId;
23
+    private Integer groupId;
24
+    private String nickname;
25
+    private String avatar;
26
+    private String phone;
27
+    private String addres;
28
+    private Timestamp createTime;
29
+    private Timestamp lastTime;
30
+    private String lastIp;
31
+    private BigDecimal score;
32
+    private BigDecimal nowMoney;
33
+    private BigDecimal brokeragePrice;
34
+    private BigDecimal repurchasePrice;
35
+    private BigDecimal memberBrokeragePrice;
36
+    private Integer status;
37
+    private Timestamp spreadTime;
38
+    private String userType;
39
+    private Timestamp promoterTime;
40
+    private BigDecimal nowScore;
41
+    private Integer isPromoter;
42
+    private Long mainUid;
43
+    private Integer payCount;
44
+    private BigDecimal payPrice;
45
+    private Integer spreadCount;
46
+    private Integer adrId;
47
+    private Integer identity;
48
+    private Integer merId;
49
+    private Integer merTopping;
50
+    private String userName;
51
+    private BigDecimal annuityFrozen;
52
+    private Integer annuityNum;
53
+    private BigDecimal annuity;
54
+    private BigDecimal agentRebate;
55
+    private BigDecimal merRebate;
56
+    private BigDecimal promoterRebate;
57
+    private BigDecimal crossStore;
58
+    private BigDecimal jurisdiction;
59
+    private BigDecimal otherJurisdictions;
60
+    private BigDecimal advFee;
61
+    private BigDecimal xqxiaofei;
62
+    private Date birthday60;
63
+    private String cardNumber;
64
+    private BigDecimal annuityYiqu;
65
+    private String isNew;
66
+    private BigDecimal adminAgentRate;
67
+    private String locktime;
68
+    private String userNumber;
69
+    private Integer im;
70
+    private String imUuid;
71
+    private String imUserid;
72
+    private String imPassword;
73
+    private Integer testUser;
74
+    private Integer isChannel;
75
+    private Integer annuityOnce;
76
+    private Integer firstSign;
77
+    private Integer isDel;
78
+    private Integer firstShopping;
79
+    private Integer external;
80
+    private Integer externalId;
81
+    private BigDecimal scoreBeishengtang;
82
+    private Integer levelId;
83
+    private Integer level;
84
+    private Integer isShow;
85
+    private Integer userGroup;
86
+    private Timestamp upVipTime;
87
+    private Timestamp upAgencyTime;
88
+    private String manageAddress;
89
+    private Integer isShopPartner;
90
+    private BigDecimal contribute;
91
+    private BigDecimal jingdou;
92
+    private BigDecimal vr;
93
+    private BigDecimal pv;
94
+    private BigDecimal hongbao;
95
+    private BigDecimal oldVipLimit;
96
+    private Integer isOld;
97
+    private BigDecimal fugou;
98
+    private Integer jbpIdOld;
99
+    private String unameOld;
100
+    private BigDecimal amountOld;
101
+    private Integer spreadOld;
102
+    private Integer inviteIdOd;
103
+    private String isTeamOld;
104
+    private Integer serverIdOld;
105
+    private String parentIdsOld;
106
+    private Integer userLevelIdOld;
107
+    private Integer originatorIdOld;
108
+    private BigDecimal totalAmountOld;
109
+    private BigDecimal totalWithdrawQuotaOld;
110
+    private BigDecimal tobeAmountOld;
111
+    private BigDecimal perContribute;
112
+    private BigDecimal withdrawQuotaOld;
113
+    private Timestamp identityUpTime;
114
+}

+ 5 - 0
userCenter_service/src/main/java/com/bjtdba/userCenter/service/UserService.java

@@ -2,6 +2,9 @@ package com.bjtdba.userCenter.service;
2 2
 
3 3
 import com.bjtdba.entity.order.User;
4 4
 import com.bjtdba.entity.userCenter.UserBill;
5
+import com.bjtdba.userCenter.dto.request.GetUserListRequest;
6
+import com.bjtdba.userCenter.dto.response.common.PageResult;
7
+import com.bjtdba.userCenter.dto.response.common.UserDTO;
5 8
 
6 9
 import java.math.BigDecimal;
7 10
 import java.util.List;
@@ -35,4 +38,6 @@ public interface UserService {
35 38
     public Integer getUserBillCount(UserBill userBill);
36 39
 
37 40
     public BigDecimal getUserCommission(Integer uid);
41
+
42
+    PageResult<UserDTO> getUserList(GetUserListRequest request);
38 43
 }

+ 66 - 0
userCenter_service/src/main/java/com/bjtdba/userCenter/service/impl/UserServiceImpl.java

@@ -4,13 +4,21 @@ import com.bjtdba.entity.order.User;
4 4
 import com.bjtdba.entity.userCenter.UserBill;
5 5
 import com.bjtdba.userCenter.dao.MerchantDao;
6 6
 import com.bjtdba.userCenter.dao.UserBillDao;
7
+import com.bjtdba.userCenter.dao.UserDao;
7 8
 import com.bjtdba.userCenter.dao.UserInfoDao;
9
+import com.bjtdba.userCenter.dto.request.GetUserListRequest;
10
+import com.bjtdba.userCenter.dto.response.common.PageResult;
11
+import com.bjtdba.userCenter.dto.response.common.UserDTO;
12
+import com.bjtdba.userCenter.entity.UserEntity;
8 13
 import com.bjtdba.userCenter.service.UserService;
9 14
 import org.springframework.beans.factory.annotation.Autowired;
10 15
 import org.springframework.stereotype.Service;
16
+import org.springframework.util.CollectionUtils;
11 17
 
12 18
 import java.math.BigDecimal;
19
+import java.util.Collections;
13 20
 import java.util.List;
21
+import java.util.stream.Collectors;
14 22
 
15 23
 @Service("userService")
16 24
 public class UserServiceImpl  implements UserService {
@@ -20,6 +28,8 @@ public class UserServiceImpl  implements UserService {
20 28
     private MerchantDao merchantDao;
21 29
     @Autowired
22 30
     private UserBillDao userBillDao;
31
+    @Autowired
32
+    private UserDao userDao;
23 33
 
24 34
 
25 35
     public User queryByid(Integer uid){
@@ -52,4 +62,60 @@ public class UserServiceImpl  implements UserService {
52 62
         return  userBillDao.getUserCommission(uid);
53 63
     }
54 64
 
65
+    @Override
66
+    public PageResult<UserDTO> getUserList(GetUserListRequest request) {
67
+
68
+        // 查询数据
69
+        List<UserEntity> userEntityList = userDao.getUserList(
70
+                request.getPhone(),
71
+                request.getNickname(),
72
+                request.getUid(),
73
+                request.getStatus(),
74
+                request.getOffset(),
75
+                request.getPageSize()
76
+        );
77
+
78
+        // 转换DTO
79
+        List<UserDTO> dtoList = convertToDTOList(userEntityList);
80
+
81
+        // 查询总数
82
+        long total = userDao.getUserListCount(
83
+                request.getPhone(),
84
+                request.getNickname(),
85
+                request.getUid(),
86
+                request.getStatus()
87
+        );
88
+
89
+        return new PageResult<>(
90
+                dtoList,
91
+                request.getPageNum(),
92
+                request.getPageSize(),
93
+                total
94
+        );
95
+    }
96
+
97
+    private List<UserDTO> convertToDTOList(List<UserEntity> userEntityList) {
98
+        if (CollectionUtils.isEmpty(userEntityList)) {
99
+            return Collections.emptyList();
100
+        }
101
+        return userEntityList.stream()
102
+                .map(this::convertToBasicDTO)
103
+                .collect(Collectors.toList());
104
+    }
105
+
106
+    private UserDTO convertToBasicDTO(UserEntity userEntity) {
107
+        UserDTO dto = new UserDTO();
108
+        dto.setUid(userEntity.getUid());
109
+        dto.setNickname(userEntity.getNickname());
110
+        dto.setAvatar(userEntity.getAvatar());
111
+        dto.setPhone(userEntity.getPhone());
112
+        dto.setCreateTime(userEntity.getCreateTime());
113
+        dto.setNowMoney(userEntity.getNowMoney());
114
+        dto.setStatus(userEntity.getStatus());
115
+        dto.setUserType(userEntity.getUserType());
116
+        dto.setIdentity(userEntity.getIdentity());
117
+        dto.setContribute(userEntity.getContribute());
118
+        dto.setJingdou(userEntity.getJingdou());
119
+        return dto;
120
+    }
55 121
 }

+ 36 - 0
userCenter_service/src/main/resources/mapper/UserMapper.xml

@@ -175,4 +175,40 @@
175 175
         where uid=#{uid}
176 176
     </update>
177 177
 
178
+    <sql id="baseColumn">
179
+                uid, nickname, avatar, phone, create_time, now_money, status, user_type,
180
+                identity, contribute, jingdou
181
+    </sql>
182
+
183
+    <sql id="queryCondition">
184
+        <where>
185
+            is_del = 0
186
+            <if test="phone != null and phone != ''">
187
+                AND phone = #{phone}
188
+            </if>
189
+            <if test="nickname != null and nickname != ''">
190
+                AND nickname LIKE CONCAT('%', #{nickname}, '%')
191
+            </if>
192
+            <if test="uid != null">
193
+                AND uid = #{uid}
194
+            </if>
195
+            <if test="status != null">
196
+                AND status = #{status}
197
+            </if>
198
+        </where>
199
+    </sql>
200
+
201
+    <select id="getUserList" resultType="com.bjtdba.userCenter.entity.UserEntity">
202
+        SELECT <include refid="baseColumn"/>
203
+        FROM rrx_user
204
+        <include refid="queryCondition"/>
205
+        ORDER BY create_time DESC
206
+        LIMIT #{offset}, #{pageSize}
207
+    </select>
208
+
209
+    <select id="getUserListCount" resultType="long">
210
+        SELECT COUNT(uid)
211
+        FROM rrx_user
212
+        <include refid="queryCondition"/>
213
+    </select>
178 214
 </mapper>