update 江苏省平台接口

This commit is contained in:
Lemon
2023-10-20 17:20:31 +08:00
parent be44562253
commit 4c6277b36c
6 changed files with 65 additions and 49 deletions

View File

@@ -44,6 +44,8 @@ import com.jsowell.thirdparty.lianlian.util.HttpRequestUtil;
import com.jsowell.thirdparty.lianlian.vo.*;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -62,6 +64,8 @@ public class LianLianServiceImpl implements LianLianService {
// private static final String DATA_SECRET = "R1Hdq80mSWswwCzt"; // 消息密钥 R1Hdq80mSWswwCzt 1234567890abcdef
// private static final String DATA_SECRETIV = "LVpz3qHD8sM2PYjl"; // 消息密钥初始化向量 LVpz3qHD8sM2PYjl 1234567890abcdef
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private IPileMerchantInfoService pileMerchantInfoService;
@@ -779,6 +783,7 @@ public class LianLianServiceImpl implements LianLianService {
String response = HttpUtil.post(requestUrl, tokenRequest);
LianLianResultVO result = JSON.parseObject(response, LianLianResultVO.class);
logger.info("获取令牌 result:{}", result);
if (result.getRet() == 0) {
// 解密data
@@ -787,6 +792,7 @@ public class LianLianServiceImpl implements LianLianService {
String dataStr = new String(plainText, "UTF-8");
Map<String, String> resultMap = (Map<String, String>) JSON.parse(dataStr);
token = resultMap.get("AccessToken");
logger.info("token: {}", token);
}
} catch (Exception e) {
return token;

View File

@@ -157,11 +157,11 @@ public class HttpRequestUtil {
}
/**
* 南瑞平台发送请求
* 江苏平台发送请求
*
* TODO和联联平台一样的方法若测试通过则统一更换成上面的方法
*
* @param token 南瑞平台令牌
* @param token 江苏平台令牌
* @param data 要传输的JsonString格式数据
* @param url 请求地址
* @param dataSecret 消息密钥
@@ -172,7 +172,7 @@ public class HttpRequestUtil {
*/
public static String nrSendPost(String token, String data, String url, String dataSecret,
String dataSecretIV, String operatorId, String sigSecret){
log.info("南瑞平台发送请求 data:{}", data);
log.info("江苏平台发送请求 data:{}", data);
//加密
byte[] encryptText = Cryptos.aesEncrypt(data.getBytes(),
dataSecret.getBytes(), dataSecretIV.getBytes());
@@ -188,23 +188,25 @@ public class HttpRequestUtil {
params.put("Sig", sign);
String postData = JSON.toJSONString(params);
log.info("南瑞平台发送请求 最终提交数据:{}", postData);
log.info("江苏平台发送请求 最终提交数据:{}", postData);
// System.out.println("最终提交数据:" + postData);
String hutoolRequest = HttpRequest.post(url).header("Authorization", "Bearer " + token).body(postData).execute().body();
log.info("南瑞平台发送请求 接收到返回数据:{}", hutoolRequest);
log.info("江苏平台发送请求 接收到返回数据:{}", hutoolRequest);
// System.out.println("接收到返回数据:" + hutoolRequest);
if (StringUtils.isBlank(hutoolRequest)) {
return "SUCCESS";
}
Map<String, Object> map = (Map<String, Object>) JSON.parse(hutoolRequest);
log.info("南瑞平台发送请求 返回数据map:{}", JSON.toJSONString(map));
log.info("江苏平台发送请求 返回数据map:{}", JSON.toJSONString(map));
int ret = (int) map.get("Ret");
String resultMsg = (String) map.get("Msg");
if (ret != 0) {
// 表示请求有异常
log.error("南瑞平台发送请求 error:{}, 源数据:{}", resultMsg, data);
log.error("江苏平台发送请求 error:{}, 源数据:{}", resultMsg, data);
return resultMsg;
}
String rData = (String) map.get("Data");
@@ -218,7 +220,7 @@ public class HttpRequestUtil {
e.printStackTrace();
}
log.info("南瑞平台发送请求 解密数据:{}", plainData);
log.info("江苏平台发送请求 解密数据:{}", plainData);
// System.out.println("解密数据:" + plainData);
return resultMsg;
}