This commit is contained in:
YAS\29473
2025-06-27 16:35:00 +08:00
parent 5eb115098a
commit 41d255b201

View File

@@ -1,5 +1,7 @@
package com.jsowell.thirdparty.platform.service.impl;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
@@ -38,9 +40,7 @@ import com.jsowell.thirdparty.platform.domain.*;
import com.jsowell.thirdparty.platform.dto.SupStationInfoDTO;
import com.jsowell.thirdparty.platform.factory.ThirdPartyPlatformFactory;
import com.jsowell.thirdparty.platform.service.ThirdPartyPlatformService;
import com.jsowell.thirdparty.platform.util.Cryptos;
import com.jsowell.thirdparty.platform.util.HttpRequestUtil;
import com.jsowell.thirdparty.platform.util.ThirdPartyPlatformUtils;
import com.jsowell.thirdparty.platform.util.*;
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService;
import com.yi.business.geo.GeoCodeInfo;
import com.yi.business.geo.TermRelationTreeCoordinate;
@@ -51,6 +51,7 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -100,6 +101,55 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
ThirdPartyPlatformFactory.register(thirdPlatformType, this);
}
@Override
public String getToken(String urlAddress, String operatorId, String operatorSecret, String dataSecretIv, String signSecret, String dataSecret) {
String token = "";
log.info("operatorId:{}, operatorSecret:{}, dataSecretIv:{}, signSecret:{}, dataSecret:{}", operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
try {
// 请求地址
String requestUrl = urlAddress + "query_token";
// 请求data
Map<String, String> data = new HashMap<>();
data.put("OperatorID", operatorId);
data.put("OperatorSecret", operatorSecret);
data.put("DataSecretIV", dataSecretIv);
String dataJson = JSONUtil.toJsonStr(data);
// 加密
byte[] encryptText = Cryptos.aesEncrypt(dataJson.getBytes(StandardCharsets.UTF_8),
dataSecret.getBytes(), dataSecretIv.getBytes());
String strData = Encodes.encodeBase64(encryptText);
Map<String, String> request = new LinkedHashMap<>();
request.put("OperatorID", operatorId);
request.put("Data", strData);
request.put("TimeStamp", DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, new Date()));
request.put("Seq", "0001");
// 生成签名
String sig = GBSignUtils.sign(request, signSecret);
request.put("Sig", sig);
String tokenRequest = JSONUtil.toJsonStr(request);
log.info("请求参数:{}", tokenRequest);
String response = HttpUtil.post(requestUrl, tokenRequest);
LianLianResultVO result = JSON.parseObject(response, LianLianResultVO.class);
log.info("返回参数:{}", response);
if (result.getRet() == 0) {
// 解密data
byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64((String) result.getData()),
dataSecret.getBytes(), dataSecretIv.getBytes());
String dataStr = new String(plainText, StandardCharsets.UTF_8);
Map<String, Object> resultMap = (Map<String, Object>) JSON.parse(dataStr);
token = String.valueOf(resultMap.get("AccessToken"));
}
} catch (Exception e) {
return token;
}
return token;
}
/**
* query_token 获取token提供给第三方平台使用
@@ -453,6 +503,7 @@ public class SiChuanPlatformServiceImpl implements ThirdPartyPlatformService {
// 获取令牌
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
log.info("token : " + token);
String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
return result;