Commit 4a8a31f9 4a8a31f935ae1214dccfd4fe2e7437c3fc6da97a by 文鑫

bug修改

1 parent c49817a2
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
36 <dependency> 36 <dependency>
37 <groupId>org.springframework.boot</groupId> 37 <groupId>org.springframework.boot</groupId>
38 <artifactId>spring-boot-starter-test</artifactId> 38 <artifactId>spring-boot-starter-test</artifactId>
39 <scope>test</scope>
40 </dependency> 39 </dependency>
41 <!--愉快办对接--> 40 <!--愉快办对接-->
42 <dependency> 41 <dependency>
......
1 package com.topdraw.dockingapi.config; 1 package com.topdraw.dockingapi.config;
2 2
3 import cn.hutool.core.bean.BeanUtil;
4 import cn.hutool.core.util.StrUtil;
5 import com.alibaba.fastjson.JSON;
6 import com.alibaba.fastjson.JSONObject;
7 import com.dtflys.forest.annotation.MethodLifeCycle; 3 import com.dtflys.forest.annotation.MethodLifeCycle;
8 import com.dtflys.forest.annotation.RequestAttributes; 4 import com.dtflys.forest.annotation.RequestAttributes;
9 import com.dtflys.forest.http.ForestRequest;
10 import com.dtflys.forest.http.ForestResponse;
11 import com.dtflys.forest.lifecycles.MethodAnnotationLifeCycle;
12 import com.dtflys.forest.reflection.ForestMethod;
13 import com.topdraw.dockingapi.util.DecryptUtils;
14 import lombok.SneakyThrows;
15 5
16 import java.lang.annotation.*; 6 import java.lang.annotation.*;
17 7
...@@ -21,7 +11,7 @@ import java.lang.annotation.*; ...@@ -21,7 +11,7 @@ import java.lang.annotation.*;
21 * @date 2024/5/23 下午5:45 11 * @date 2024/5/23 下午5:45
22 */ 12 */
23 @Documented 13 @Documented
24 @MethodLifeCycle(Decode.DecodeLifeCycle.class) 14 @MethodLifeCycle(DecodeLifeCycle.class)
25 @RequestAttributes 15 @RequestAttributes
26 @Retention(RetentionPolicy.RUNTIME) 16 @Retention(RetentionPolicy.RUNTIME)
27 @Target({ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER}) 17 @Target({ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER})
...@@ -29,30 +19,5 @@ public @interface Decode { ...@@ -29,30 +19,5 @@ public @interface Decode {
29 19
30 String value(); 20 String value();
31 21
32 class DecodeLifeCycle implements MethodAnnotationLifeCycle<Decode, Object> {
33 private String key;
34 22
35 @Override
36 public void onMethodInitialized(ForestMethod method, Decode annotation) {
37 this.key = annotation.value();
38 }
39
40 @SneakyThrows
41 @Override
42 public void onSuccess(Object data, ForestRequest request, ForestResponse response) {
43 String value = (String) getAttribute(request, "value");
44 String content = response.getContent();
45 ForestMethod<?> method = request.getMethod();
46 Class<?> returnClass = method.getReturnClass();
47 JSONObject responseData = JSON.parseObject(content, JSONObject.class);
48 if (StrUtil.isNotBlank(responseData.getString("errcode"))) {
49 data = BeanUtil.copyProperties(responseData, returnClass);
50 } else {
51 String encrypt = responseData.getString("encrypt");
52 String bodyJson = DecryptUtils.decode(value, encrypt);
53 data = BeanUtil.copyProperties(JSONObject.parseObject(bodyJson), returnClass);
54 }
55 response.setResult(data);
56 }
57 }
58 } 23 }
......
1 package com.topdraw.dockingapi.config;
2
3 import cn.hutool.core.bean.BeanUtil;
4 import cn.hutool.core.util.StrUtil;
5 import com.alibaba.fastjson.JSON;
6 import com.alibaba.fastjson.JSONObject;
7 import com.dtflys.forest.http.ForestRequest;
8 import com.dtflys.forest.http.ForestResponse;
9 import com.dtflys.forest.lifecycles.MethodAnnotationLifeCycle;
10 import com.dtflys.forest.reflection.ForestMethod;
11 import com.topdraw.dockingapi.util.DecryptUtils;
12 import lombok.SneakyThrows;
13
14 /**
15 * @author wenxin
16 * @version 1.0
17 * @date 2024/5/28 下午2:46
18 */
19 public class DecodeLifeCycle implements MethodAnnotationLifeCycle<Decode, Object> {
20
21
22 @Override
23 public void onMethodInitialized(ForestMethod method, Decode annotation) {
24
25 }
26
27 @SneakyThrows
28 @Override
29 @SuppressWarnings("all")
30 public void onSuccess(Object data, ForestRequest request, ForestResponse response) {
31 String value = (String) getAttribute(request, "value");
32 String content = response.getContent();
33 ForestMethod<?> method = request.getMethod();
34 Class<?> returnClass = method.getReturnClass();
35 JSONObject responseData = JSON.parseObject(content, JSONObject.class);
36 if (StrUtil.isNotBlank(responseData.getString("errcode"))) {
37 data = BeanUtil.copyProperties(responseData, returnClass);
38 } else {
39 String encrypt = responseData.getString("encrypt");
40 String bodyJson = DecryptUtils.decode(value, encrypt);
41 data = BeanUtil.copyProperties(JSONObject.parseObject(bodyJson), returnClass);
42 }
43 response.setResult(data);
44 }
45 }
...\ No newline at end of file ...\ No newline at end of file
1 package com.topdraw.dockingapi.config; 1 package com.topdraw.dockingapi.config;
2 2
3 import com.alibaba.fastjson.JSON;
4 import com.dtflys.forest.annotation.MethodLifeCycle; 3 import com.dtflys.forest.annotation.MethodLifeCycle;
5 import com.dtflys.forest.annotation.RequestAttributes; 4 import com.dtflys.forest.annotation.RequestAttributes;
6 import com.dtflys.forest.http.ForestBody;
7 import com.dtflys.forest.http.ForestRequest;
8 import com.dtflys.forest.lifecycles.MethodAnnotationLifeCycle;
9 import com.dtflys.forest.reflection.ForestMethod;
10 import com.topdraw.dockingapi.entity.EncryptEntity;
11 import com.topdraw.dockingapi.util.DecryptUtils;
12 import lombok.SneakyThrows;
13 5
14 import java.lang.annotation.*; 6 import java.lang.annotation.*;
15 import java.lang.reflect.Parameter;
16 7
17 /** 8 /**
18 * 用Forest自定义注解实现一个自定义的签名加密注解 9 * 用Forest自定义注解实现一个自定义的签名加密注解
...@@ -21,7 +12,7 @@ import java.lang.reflect.Parameter; ...@@ -21,7 +12,7 @@ import java.lang.reflect.Parameter;
21 * 可以将此注解用在接口类和方法上 12 * 可以将此注解用在接口类和方法上
22 */ 13 */
23 @Documented 14 @Documented
24 @MethodLifeCycle(Encode.EncodeLifeCycle.class) 15 @MethodLifeCycle(EncodeLifeCycle.class)
25 @RequestAttributes 16 @RequestAttributes
26 @Retention(RetentionPolicy.RUNTIME) 17 @Retention(RetentionPolicy.RUNTIME)
27 @Target({ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER}) 18 @Target({ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER})
...@@ -30,42 +21,5 @@ public @interface Encode { ...@@ -30,42 +21,5 @@ public @interface Encode {
30 String value() default ""; 21 String value() default "";
31 22
32 23
33 class EncodeLifeCycle implements MethodAnnotationLifeCycle<Encode, Object> {
34
35
36 /**
37 * 当方法调用时调用此方法,此时还没有执行请求发送
38 * 此方法可以获得请求对应的方法调用信息,以及动态传入的方法调用参数列表
39 */
40 @SneakyThrows
41 @Override
42 public void onInvokeMethod(ForestRequest request, ForestMethod method, Object[] args) {
43 String value = (String) getAttribute(request, "value");
44 for (Object arg : args) {
45 Parameter[] parameters = method.getMethod().getParameters();
46 for (int i = 0; i < parameters.length; i++) {
47 Encode annotation = parameters[i].getAnnotation(Encode.class);
48 if (annotation != null) {
49 Object body = args[i];
50 String jsonString = JSON.toJSONString(body);
51 String encode = DecryptUtils.encode(value, jsonString);
52 EncryptEntity encodeBody = new EncryptEntity(encode);
53 ForestBody forestBody = request.getBody();
54 //替换body
55 forestBody.clear();
56 request.addBody(encodeBody);
57 }
58 }
59 }
60 }
61
62
63 @Override
64 public void onMethodInitialized(ForestMethod method, Encode annotation) {
65
66 }
67 }
68
69
70 } 24 }
71 25
......
1 package com.topdraw.dockingapi.config;
2
3 import com.dtflys.forest.annotation.Body;
4
5 import java.lang.annotation.*;
6
7 /**
8 * @author wenxin
9 * @version 1.0
10 * @date 2024/5/28 下午2:58
11 */
12 @Documented
13 @Retention(RetentionPolicy.RUNTIME)
14 @Target({ElementType.PARAMETER, ElementType.TYPE})
15 // 被组合的注解
16 @Body
17 public @interface EncodeBody {
18 }
1 package com.topdraw.dockingapi.config;
2
3 import com.alibaba.fastjson.JSON;
4 import com.dtflys.forest.http.ForestBody;
5 import com.dtflys.forest.http.ForestRequest;
6 import com.dtflys.forest.lifecycles.MethodAnnotationLifeCycle;
7 import com.dtflys.forest.reflection.ForestMethod;
8 import com.topdraw.dockingapi.entity.EncryptEntity;
9 import com.topdraw.dockingapi.util.DecryptUtils;
10 import lombok.SneakyThrows;
11
12 import java.lang.reflect.Parameter;
13
14 /**
15 * @author wenxin
16 * @version 1.0
17 * @date 2024/5/28 下午2:46
18 */
19 public class EncodeLifeCycle implements MethodAnnotationLifeCycle<Encode, Object> {
20
21
22 /**
23 * 当方法调用时调用此方法,此时还没有执行请求发送
24 * 此方法可以获得请求对应的方法调用信息,以及动态传入的方法调用参数列表
25 */
26 @SneakyThrows
27 @Override
28 public void onInvokeMethod(ForestRequest request, ForestMethod method, Object[] args) {
29 String value = (String) getAttribute(request, "value");
30 Parameter[] parameters = method.getMethod().getParameters();
31 for (int i = 0; i < parameters.length; i++) {
32 EncodeBody annotation = parameters[i].getAnnotation(EncodeBody.class);
33 if (annotation != null) {
34 Object body = args[i];
35 String jsonString = JSON.toJSONString(body);
36 String encode = DecryptUtils.encode(value, jsonString);
37 EncryptEntity encodeBody = new EncryptEntity(encode);
38 ForestBody forestBody = request.getBody();
39 //替换body
40 forestBody.clear();
41 request.addBody(encodeBody);
42 }
43 }
44 }
45
46
47 @Override
48 public void onMethodInitialized(ForestMethod method, Encode annotation) {
49
50 }
51 }
1 package com.topdraw.dockingapi.controller; 1 package com.topdraw.dockingapi.controller;
2 2
3 import cn.hutool.core.map.MapBuilder; 3 import cn.hutool.core.map.MapBuilder;
4 import cn.hutool.core.util.StrUtil;
4 import com.alibaba.fastjson.JSONArray; 5 import com.alibaba.fastjson.JSONArray;
5 import com.alibaba.fastjson.JSONObject; 6 import com.alibaba.fastjson.JSONObject;
6 import com.digital.szzz.gateway.sdk.api.GatewaySender; 7 import com.digital.szzz.gateway.sdk.api.GatewaySender;
...@@ -8,11 +9,11 @@ import com.digital.szzz.gateway.sdk.bean.GatewayResponse; ...@@ -8,11 +9,11 @@ import com.digital.szzz.gateway.sdk.bean.GatewayResponse;
8 import com.topdraw.dockingapi.config.EnvConfiguration; 9 import com.topdraw.dockingapi.config.EnvConfiguration;
9 import com.topdraw.dockingapi.entity.DecodeBody; 10 import com.topdraw.dockingapi.entity.DecodeBody;
10 import com.topdraw.dockingapi.http.UserService; 11 import com.topdraw.dockingapi.http.UserService;
11 import lombok.RequiredArgsConstructor;
12 import lombok.extern.slf4j.Slf4j; 12 import lombok.extern.slf4j.Slf4j;
13 import org.springframework.web.bind.annotation.*; 13 import org.springframework.web.bind.annotation.*;
14 14
15 import javax.annotation.PostConstruct; 15 import javax.annotation.PostConstruct;
16 import javax.annotation.Resource;
16 import java.util.HashMap; 17 import java.util.HashMap;
17 import java.util.Map; 18 import java.util.Map;
18 import java.util.Optional; 19 import java.util.Optional;
...@@ -27,20 +28,22 @@ import java.util.Optional; ...@@ -27,20 +28,22 @@ import java.util.Optional;
27 @RestController 28 @RestController
28 @Slf4j 29 @Slf4j
29 @RequestMapping("/api") 30 @RequestMapping("/api")
30 @RequiredArgsConstructor 31
31 @CrossOrigin 32 @CrossOrigin
32 public class ApiController { 33 public class ApiController {
33 private final EnvConfiguration configuration; 34 @Resource
34 35 EnvConfiguration configuration;
35 private final UserService userService; 36 @Resource
37 private
38 UserService userService;
36 39
37 String url; 40 String url;
38 String appId; 41 String appId;
39 String iv; 42 String iv;
40 String appKey; 43 String appKey;
41 String appSecretKey; 44 String appSecretKey;
42 int readTimeout = 1000; 45 int readTimeout = 5000;
43 int connTimeout = 1000; 46 int connTimeout = 5000;
44 47
45 @PostConstruct 48 @PostConstruct
46 public void init() { 49 public void init() {
...@@ -90,6 +93,27 @@ public class ApiController { ...@@ -90,6 +93,27 @@ public class ApiController {
90 readTimeout, connTimeout); 93 readTimeout, connTimeout);
91 } 94 }
92 95
96
97 private String getPhone(String authCode) {
98 String method = "app.ykb.uc.oauth.userInfo";
99 JSONObject param = new JSONObject();
100 param.put("authCode", authCode);
101 Map<String, String> headerMap = new HashMap<>();
102 GatewayResponse send = GatewaySender.send(url, appId, method,
103 iv, appKey, appSecretKey, param, authCode,
104 headerMap, readTimeout, connTimeout);
105 log.info("获取手机号返回的结果是:{}", JSONArray.toJSONString(send));
106 String data = send.getData();
107 return Optional.ofNullable(JSONObject.parseObject(data, JSONObject.class))
108 .map(t -> t.getJSONObject("data"))
109 .map(t -> t.getJSONObject("userInfo"))
110 .map(t -> t.getString("phone"))
111 .filter(StrUtil::isNotBlank)
112 .orElseThrow(() -> new RuntimeException("获取手机号失败"));
113
114 }
115
116
93 /** 117 /**
94 * 获取用户脱敏信息 118 * 获取用户脱敏信息
95 * 119 *
...@@ -99,20 +123,15 @@ public class ApiController { ...@@ -99,20 +123,15 @@ public class ApiController {
99 @PostMapping("/user/info") 123 @PostMapping("/user/info")
100 public DecodeBody<Object> getUserInfoByAuthCode(@RequestBody JSONObject data) { 124 public DecodeBody<Object> getUserInfoByAuthCode(@RequestBody JSONObject data) {
101 //通过authCode获取用户手机号 125 //通过authCode获取用户手机号
102 JSONObject userInfoByAuthCode = userService.getUserInfoByAuthCode(data); 126 String phone = getPhone(data.getString("authCode"));
103 String phone = Optional.ofNullable(userInfoByAuthCode)
104 .map(t -> t.getJSONObject("data"))
105 .map(t -> t.getJSONObject("userInfo"))
106 .map(t -> t.getString("phone"))
107 .orElseThrow(() -> new RuntimeException("获取用户信息失败"));
108 //判断手机号是否已经注册 127 //判断手机号是否已经注册
109 DecodeBody<JSONObject> register = userService.checkIsRegisterByPhoneNum(MapBuilder.<String, String>create() 128 DecodeBody<JSONObject> register = userService.checkIsRegisterByPhoneNum(MapBuilder.<String, String>create()
110 .put("phone", phone).build()); 129 .put("phoneNum", phone).build());
111 String isRegister = register.getData().getString("isRegister"); 130 String isRegister = register.getData().getString("isRegister");
112 if ("0".equals(isRegister)) { 131 if ("0".equals(isRegister)) {
113 //注册用户 132 //注册用户
114 DecodeBody<Object> body = userService.privateRegister(MapBuilder.<String, String>create() 133 DecodeBody<Object> body = userService.privateRegister(MapBuilder.<String, String>create()
115 .put("phone", phone) 134 .put("phoneNum", phone)
116 .put("token", "") 135 .put("token", "")
117 .build()); 136 .build());
118 String errcode = body.getErrcode(); 137 String errcode = body.getErrcode();
...@@ -123,7 +142,7 @@ public class ApiController { ...@@ -123,7 +142,7 @@ public class ApiController {
123 } 142 }
124 //获取用户信息 143 //获取用户信息
125 return userService.privateLogin(MapBuilder.<String, String>create() 144 return userService.privateLogin(MapBuilder.<String, String>create()
126 .put("phone", phone) 145 .put("phoneNum", phone)
127 .put("token", "").build()); 146 .put("token", "").build());
128 } 147 }
129 } 148 }
......
...@@ -2,10 +2,10 @@ package com.topdraw.dockingapi.http; ...@@ -2,10 +2,10 @@ package com.topdraw.dockingapi.http;
2 2
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
4 import com.dtflys.forest.annotation.BaseRequest; 4 import com.dtflys.forest.annotation.BaseRequest;
5 import com.dtflys.forest.annotation.Body;
6 import com.dtflys.forest.annotation.Post; 5 import com.dtflys.forest.annotation.Post;
7 import com.topdraw.dockingapi.config.Decode; 6 import com.topdraw.dockingapi.config.Decode;
8 import com.topdraw.dockingapi.config.Encode; 7 import com.topdraw.dockingapi.config.Encode;
8 import com.topdraw.dockingapi.config.EncodeBody;
9 import com.topdraw.dockingapi.entity.DecodeBody; 9 import com.topdraw.dockingapi.entity.DecodeBody;
10 10
11 import java.util.Map; 11 import java.util.Map;
...@@ -19,8 +19,7 @@ import java.util.Map; ...@@ -19,8 +19,7 @@ import java.util.Map;
19 baseURL = "{baseUrl}", // 默认域名 19 baseURL = "{baseUrl}", // 默认域名
20 headers = { 20 headers = {
21 "Content-Type:application/json" // 默认请求头 21 "Content-Type:application/json" // 默认请求头
22 }, 22 }
23 sslProtocol = "TLS" // 默认单向SSL协议
24 ) 23 )
25 public interface UserService { 24 public interface UserService {
26 /** 25 /**
...@@ -36,7 +35,7 @@ public interface UserService { ...@@ -36,7 +35,7 @@ public interface UserService {
36 @Post("/cpc-ms-service-user/user/yk/checkIsRegisterByPhoneNum") 35 @Post("/cpc-ms-service-user/user/yk/checkIsRegisterByPhoneNum")
37 @Encode("${key}") 36 @Encode("${key}")
38 @Decode("${key}") 37 @Decode("${key}")
39 DecodeBody<JSONObject> checkIsRegisterByPhoneNum(@Body @Encode Map<String,?> body); 38 DecodeBody<JSONObject> checkIsRegisterByPhoneNum(@EncodeBody Map<String, ?> body);
40 39
41 /** 40 /**
42 * 用户注册 41 * 用户注册
...@@ -52,7 +51,7 @@ public interface UserService { ...@@ -52,7 +51,7 @@ public interface UserService {
52 @Post("/cpc-ms-service-user/user/yk/privateRegister") 51 @Post("/cpc-ms-service-user/user/yk/privateRegister")
53 @Encode("${key}") 52 @Encode("${key}")
54 @Decode("${key}") 53 @Decode("${key}")
55 DecodeBody<Object> privateRegister(@Body @Encode Map<String,?> body); 54 DecodeBody<Object> privateRegister(@EncodeBody Map<String, ?> body);
56 55
57 /** 56 /**
58 * 用户登录获取用户信息 57 * 用户登录获取用户信息
...@@ -68,17 +67,7 @@ public interface UserService { ...@@ -68,17 +67,7 @@ public interface UserService {
68 @Post("/cpc-ms-service-user/login/yk/privateLogin") 67 @Post("/cpc-ms-service-user/login/yk/privateLogin")
69 @Encode("${key}") 68 @Encode("${key}")
70 @Decode("${key}") 69 @Decode("${key}")
71 DecodeBody<Object> privateLogin(@Body @Encode Map<String,?> body); 70 DecodeBody<Object> privateLogin(@EncodeBody Map<String, ?> body);
72
73
74 /**
75 * 获取用户手机号码
76 *
77 * @param body authCode
78 * @return 手机号
79 */
80 @Post("/cpc-ms-service-user/user/yk/getUserInfoByAuthCode")
81 JSONObject getUserInfoByAuthCode(@Body JSONObject body);
82 71
83 72
84 } 73 }
......
1
2 # 指定启动的时候springboot的激活环境 1 # 指定启动的时候springboot的激活环境
3 spring.profiles.active=test 2 spring.profiles.active=test
3 # Forest配置
4 # 后端HTTP框架(默认为 okhttp3)
5 forest.backend=okhttp3
6 # 连接池最大连接数(默认为 500)
7 forest.max-connections=1000
8 # 每个路由的最大连接数(默认为 500)
9 forest.max-route-connections=500
10 # 最大请求等待队列大小
11 forest.max-request-queue-size=100
12 # 最大异步线程数
13 forest.max-async-thread-size=300
14 # 最大异步线程池队列大小
15 forest.max-async-queue-size=16
16 # 连接超时时间,单位为毫秒(默认为 timeout)
17 forest.connect-timeout=30000
18 # 数据读取超时时间,单位为毫秒(默认为 timeout)
19 forest.read-timeout=30000
20 # 请求失败后重试次数(默认为 0 次不重试)
21 forest.max-retry-count=1
22 # 单向验证的HTTPS的默认TLS协议(默认为 TLS)
23 forest.ssl-protocol=TLS
24 # 打开或关闭日志(默认为 true)
25 forest.log-enabled=true
26 # 打开/关闭Forest请求日志(默认为 true)
27 forest.log-request=true
28 # 打开/关闭Forest响应状态日志(默认为 true)
29 forest.log-response-status=true
30 # 打开/关闭Forest响应内容日志(默认为 false)
31 forest.log-response-content=true
32 # 用户信息接口URL
33 forest.variables.userInfoUrl=https://cpcapi.cbg.cn
......
...@@ -5,10 +5,9 @@ forest: ...@@ -5,10 +5,9 @@ forest:
5 max-request-queue-size: 100 # [自v1.5.22版本起可用] 最大请求等待队列大小 5 max-request-queue-size: 100 # [自v1.5.22版本起可用] 最大请求等待队列大小
6 max-async-thread-size: 300 # [自v1.5.21版本起可用] 最大异步线程数 6 max-async-thread-size: 300 # [自v1.5.21版本起可用] 最大异步线程数
7 max-async-queue-size: 16 # [自v1.5.22版本起可用] 最大异步线程池队列大小 7 max-async-queue-size: 16 # [自v1.5.22版本起可用] 最大异步线程池队列大小
8 timeout: 3000 # [已不推荐使用] 请求超时时间,单位为毫秒(默认为 3000) 8 connect-timeout: 30000 # 连接超时时间,单位为毫秒(默认为 timeout)
9 connect-timeout: 3000 # 连接超时时间,单位为毫秒(默认为 timeout) 9 read-timeout: 30000 # 数据读取超时时间,单位为毫秒(默认为 timeout)
10 read-timeout: 3000 # 数据读取超时时间,单位为毫秒(默认为 timeout) 10 max-retry-count: 1 # 请求失败后重试次数(默认为 0 次不重试)
11 max-retry-count: 0 # 请求失败后重试次数(默认为 0 次不重试)
12 ssl-protocol: TLS # 单向验证的HTTPS的默认TLS协议(默认为 TLS) 11 ssl-protocol: TLS # 单向验证的HTTPS的默认TLS协议(默认为 TLS)
13 log-enabled: true # 打开或关闭日志(默认为 true) 12 log-enabled: true # 打开或关闭日志(默认为 true)
14 log-request: true # 打开/关闭Forest请求日志(默认为 true) 13 log-request: true # 打开/关闭Forest请求日志(默认为 true)
......
...@@ -25,7 +25,7 @@ public class ApiTest { ...@@ -25,7 +25,7 @@ public class ApiTest {
25 // 密钥 25 // 密钥
26 byte[] keyBytes = "wmsj2021".getBytes(StandardCharsets.UTF_8); // DES密钥长度为8字节 26 byte[] keyBytes = "wmsj2021".getBytes(StandardCharsets.UTF_8); // DES密钥长度为8字节
27 // 需要加密的数据 27 // 需要加密的数据
28 String text = "{\"phoneNum\":\"15983678047\"}"; 28 String text = "{\"phoneNum\":\"13627618074\"}";
29 byte[] data = text.getBytes(StandardCharsets.UTF_8); 29 byte[] data = text.getBytes(StandardCharsets.UTF_8);
30 // 创建密钥 30 // 创建密钥
31 SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "DES"); 31 SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "DES");
...@@ -53,7 +53,7 @@ public class ApiTest { ...@@ -53,7 +53,7 @@ public class ApiTest {
53 @SneakyThrows 53 @SneakyThrows
54 @Test 54 @Test
55 public void testEncode(){ 55 public void testEncode(){
56 String text = "{\"phoneNum\":\"15983678047\"}"; 56 String text = "{\"phoneNum\":\"13627618074\"}";
57 System.out.println(DecryptUtils.encode("wmsj2021", text)); 57 System.out.println(DecryptUtils.encode("wmsj2021", text));
58 String tt="U0ELEkckqqxwzutWXbySgJmGbWQovd9n7UZSWqYt5HpXOxOsQwTnrjGp7geAhD/Mp9Jy3okXkRtt0cuFDdlMjPDgsBK3SMu0"; 58 String tt="U0ELEkckqqxwzutWXbySgJmGbWQovd9n7UZSWqYt5HpXOxOsQwTnrjGp7geAhD/Mp9Jy3okXkRtt0cuFDdlMjPDgsBK3SMu0";
59 System.out.println(DecryptUtils.decode("wmsj2021", tt)); 59 System.out.println(DecryptUtils.decode("wmsj2021", tt));
......
1 package com.topdraw.dockingapi; 1 package com.topdraw.dockingapi;
2 2
3 import com.alibaba.fastjson.JSON;
3 import com.alibaba.fastjson.JSONObject; 4 import com.alibaba.fastjson.JSONObject;
5 import com.digital.szzz.gateway.sdk.bean.GatewayResponse;
6 import com.topdraw.dockingapi.controller.ApiController;
7 import com.topdraw.dockingapi.entity.DecodeBody;
4 import com.topdraw.dockingapi.http.UserService; 8 import com.topdraw.dockingapi.http.UserService;
5 import org.junit.jupiter.api.Test; 9 import org.junit.jupiter.api.Test;
6 import org.springframework.boot.test.context.SpringBootTest; 10 import org.springframework.boot.test.context.SpringBootTest;
...@@ -12,6 +16,8 @@ class DockingApiApplicationTests { ...@@ -12,6 +16,8 @@ class DockingApiApplicationTests {
12 16
13 @Resource 17 @Resource
14 private UserService userService; 18 private UserService userService;
19 @Resource
20 private ApiController apiController;
15 21
16 @Test 22 @Test
17 void contextLoads() { 23 void contextLoads() {
...@@ -20,4 +26,21 @@ class DockingApiApplicationTests { ...@@ -20,4 +26,21 @@ class DockingApiApplicationTests {
20 System.out.println(userService.checkIsRegisterByPhoneNum(param)); 26 System.out.println(userService.checkIsRegisterByPhoneNum(param));
21 } 27 }
22 28
29 @Test
30 void testApi() {
31 JSONObject param = new JSONObject();
32 param.put("userId","8798981653125");
33 GatewayResponse authCodeByUserId = apiController.getAuthCodeByUserId(param);
34 String data = authCodeByUserId.getData();
35 JSONObject j = JSON.parseObject(data, JSONObject.class);
36 String string = j.getJSONObject("data")
37 .getString("authCode");
38 JSONObject p = new JSONObject();
39 p.put("authCode",string);
40 DecodeBody<Object> userInfoByAuthCode = apiController.getUserInfoByAuthCode(p);
41 System.out.println("----------------------------------------------------");
42 System.out.println(JSON.toJSONString(userInfoByAuthCode));
43
44 }
45
23 } 46 }
......