RopManager.java
4.27 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
package com.gsc4cloud.agentmanage.manager;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gsc4cloud.agentmanage.config.RopApiConfig;
import com.gsc4cloud.agentmanage.utils.GLRopApiUtils;
import com.gsc4cloud.agentmanage.utils.ThreadLocalCache;
import com.gsc4cloud.agentmanage.response.rop.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
/**
* @Description todo
* @Author yelq
* @Date 2025/7/28-19:24
* @Version 1.0
*/
@Component
public class RopManager {
@Autowired
private RopApiConfig ropApiConfig;
public void saveLoginInfo(String sessionId) throws Exception {
if (ropApiConfig.getContextPath() == null || ropApiConfig.getContextPath().isEmpty())
throw new Exception("缺少必要的rop配置");
if ("rop-dj-car-boutique".equals(ropApiConfig.getContextPath())){
ropDjCarBoutiqueHandler(sessionId);
return;
}
if ("rop-dj-smartcarlife".equals(ropApiConfig.getContextPath())){
ropDjSmartCarLifeHandler(sessionId);
return;
}
}
private void ropDjSmartCarLifeHandler(String sessionId) throws Exception {
//请求地址,区分环境
String url = ropApiConfig.getUrl();
String appKey = ropApiConfig.getAppKey();
String secret = ropApiConfig.getSecret();
//项目名称
String contextPath = ropApiConfig.getContextPath();
// 默认拼装路径
url = url.concat(contextPath).concat("/router");
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(4);
// 版本号,必填,默认1.0.0
params.add("v", "1.0.0");
// 接口名称,必填
params.add("method", ropApiConfig.getMethod());
// 参数,根据接口添加
params.add("sessionId", sessionId);
// post请求
RopResponse<Object> post = GLRopApiUtils.post(url, params, RopResponse.class, appKey, secret);
if (post.getData() != null) {
String data = JSON.toJSONString(post.getData());
// json字符串转换对象
UserInfoResponse loginObj = JSONObject.parseObject(data, UserInfoResponse.class);
if (loginObj != null && loginObj.getLoginAccount() != null ) {
LoginAccountResponse loginUserInfo = loginObj.getLoginAccount();
// 存储到当前线程
ThreadLocalCache.setLoginAccountInfo(loginUserInfo);
}
} else {
throw new Exception("用户信息获取失败: " + post.getMessage());
}
}
private void ropDjCarBoutiqueHandler(String sessionId) throws Exception {
//请求地址,区分环境
String url = ropApiConfig.getUrl();
String appKey = ropApiConfig.getAppKey();
String secret = ropApiConfig.getSecret();
//项目名称
String contextPath = ropApiConfig.getContextPath();
// 默认拼装路径
url = url.concat(contextPath).concat("/router");
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(4);
// 版本号,必填,默认1.0.0
params.add("v", "1.0.0");
// 接口名称,必填
params.add("method", ropApiConfig.getMethod());
// 参数,根据接口添加
params.add("sessionId", sessionId);
// post请求
RopResponse<Object> post = GLRopApiUtils.post(url, params, RopResponse.class, appKey, secret);
if (post.getData() != null) {
String data = JSON.toJSONString(post.getData());
// json字符串转换对象
LoginObjResponse loginObj = JSONObject.parseObject(data, LoginObjResponse.class);
if (loginObj != null && loginObj.getLoginUserInfoList() != null && !loginObj.getLoginUserInfoList().isEmpty()) {
LoginUserInfoResponse loginUserInfo = loginObj.getLoginUserInfoList().get(0);
// 存储到当前线程
ThreadLocalCache.setLoginInfo(loginUserInfo);
}
} else {
throw new Exception("用户信息获取失败: " + post.getMessage());
}
}
}