|
@@ -7,7 +7,7 @@ import cn.hutool.crypto.digest.HmacAlgorithm;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.kym.common.annotation.DynamicCache;
|
|
import com.kym.common.annotation.DynamicCache;
|
|
|
import com.kym.common.constant.ResponseEnum;
|
|
import com.kym.common.constant.ResponseEnum;
|
|
|
-import com.kym.common.enums.EnPlusApi;
|
|
|
|
|
|
|
+import com.kym.service.enplus.EnPlusApi;
|
|
|
import com.kym.common.exception.BusinessException;
|
|
import com.kym.common.exception.BusinessException;
|
|
|
import com.kym.common.exception.EnPushException;
|
|
import com.kym.common.exception.EnPushException;
|
|
|
import com.kym.common.utils.CommUtil;
|
|
import com.kym.common.utils.CommUtil;
|
|
@@ -39,13 +39,6 @@ public class PlatformApiServiceImpl implements PlatformApiService {
|
|
|
static OkHttpClient HTTP_CLIENT = new OkHttpClient.Builder().build();
|
|
static OkHttpClient HTTP_CLIENT = new OkHttpClient.Builder().build();
|
|
|
private final RedisTemplate<String, String> redisTemplate;
|
|
private final RedisTemplate<String, String> redisTemplate;
|
|
|
|
|
|
|
|
- @Value("${en-plus.operatorId}")
|
|
|
|
|
- private String OperatorId;
|
|
|
|
|
- @Value("${en-plus.operatorSecret}")
|
|
|
|
|
- private String OperatorSecret;
|
|
|
|
|
- @Value("${en-plus.sigSecret}")
|
|
|
|
|
- private String SigSecret;
|
|
|
|
|
-
|
|
|
|
|
public PlatformApiServiceImpl(RedisTemplate<String, String> redisTemplate) {
|
|
public PlatformApiServiceImpl(RedisTemplate<String, String> redisTemplate) {
|
|
|
this.redisTemplate = redisTemplate;
|
|
this.redisTemplate = redisTemplate;
|
|
|
}
|
|
}
|
|
@@ -117,7 +110,7 @@ public class PlatformApiServiceImpl implements PlatformApiService {
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public String queryPlatformToken(String platformName) {
|
|
public String queryPlatformToken(String platformName) {
|
|
|
- log.info("查询互联互通平台token:{}", platformName);
|
|
|
|
|
|
|
+ log.info("查询互联互通平台{}token", platformName);
|
|
|
var token = redisTemplate.opsForValue().get(RedisKeys.EN_PLUS_TOKEN + platformName);
|
|
var token = redisTemplate.opsForValue().get(RedisKeys.EN_PLUS_TOKEN + platformName);
|
|
|
if (CommUtil.isNotEmptyAndNull(token)) {
|
|
if (CommUtil.isNotEmptyAndNull(token)) {
|
|
|
// 不同平台不同key
|
|
// 不同平台不同key
|
|
@@ -129,11 +122,11 @@ public class PlatformApiServiceImpl implements PlatformApiService {
|
|
|
"OperatorID":"%s",
|
|
"OperatorID":"%s",
|
|
|
"OperatorSecret":"%s"
|
|
"OperatorSecret":"%s"
|
|
|
}
|
|
}
|
|
|
- """.formatted(OperatorId, OperatorSecret);
|
|
|
|
|
|
|
+ """.formatted(PlatformCache.INSTANCE.getPlatformByName(platformName).getOperatorId(), PlatformCache.INSTANCE.getPlatformByName(platformName).getOperatorSecret());
|
|
|
|
|
|
|
|
var requestParams = buildPlatformParams(platformName, data);
|
|
var requestParams = buildPlatformParams(platformName, data);
|
|
|
|
|
|
|
|
- var response = platformGetToken(EnPlusApi.EN_PLUS_QUERY_TOKEN.getApi(), requestParams);
|
|
|
|
|
|
|
+ var response = platformGetToken(EnPlusApi.EN_PLUS_QUERY_TOKEN.getApi(platformName), requestParams);
|
|
|
|
|
|
|
|
if (response != null && 0 == response.getRet()) {
|
|
if (response != null && 0 == response.getRet()) {
|
|
|
// 解密Data获取token
|
|
// 解密Data获取token
|
|
@@ -177,15 +170,17 @@ public class PlatformApiServiceImpl implements PlatformApiService {
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public String buildPlatformParams(String platformName, String params) {
|
|
public String buildPlatformParams(String platformName, String params) {
|
|
|
|
|
+ var platform = PlatformCache.INSTANCE.getPlatformByName(platformName);
|
|
|
// 使用DataSecret对data加密
|
|
// 使用DataSecret对data加密
|
|
|
- var dataStr = PlatformAesUtil.encrypt(PlatformCache.INSTANCE.getPlatformByName(platformName), params);
|
|
|
|
|
|
|
+// var dataStr = PlatformAesUtil.encrypt(platform, params);
|
|
|
|
|
+ var dataStr = PlatformAesUtil.encrypt(platform, params);
|
|
|
// 时间戳
|
|
// 时间戳
|
|
|
var timeStamp = LocalDateTimeUtil.format(LocalDateTime.now(), DatePattern.PURE_DATETIME_PATTERN);
|
|
var timeStamp = LocalDateTimeUtil.format(LocalDateTime.now(), DatePattern.PURE_DATETIME_PATTERN);
|
|
|
// 自增序列
|
|
// 自增序列
|
|
|
var seq = timeStamp.substring(timeStamp.length() - 4);
|
|
var seq = timeStamp.substring(timeStamp.length() - 4);
|
|
|
// 使用SigSecret以HMAC-MD5算法对消息体签名(签名顺序:OperatorId、Data、TimeStamp、Seq)
|
|
// 使用SigSecret以HMAC-MD5算法对消息体签名(签名顺序:OperatorId、Data、TimeStamp、Seq)
|
|
|
- var signString = OperatorId + dataStr + timeStamp + seq;
|
|
|
|
|
- HMac mac = new HMac(HmacAlgorithm.HmacMD5, SigSecret.getBytes());
|
|
|
|
|
|
|
+ var signString = platform.getOperatorId() + dataStr + timeStamp + seq;
|
|
|
|
|
+ HMac mac = new HMac(HmacAlgorithm.HmacMD5, platform.getSigSecret().getBytes());
|
|
|
// 签名(转为大写)
|
|
// 签名(转为大写)
|
|
|
var sign = mac.digestHex(signString).toUpperCase();
|
|
var sign = mac.digestHex(signString).toUpperCase();
|
|
|
return """
|
|
return """
|
|
@@ -196,7 +191,7 @@ public class PlatformApiServiceImpl implements PlatformApiService {
|
|
|
"Seq":"%s",
|
|
"Seq":"%s",
|
|
|
"Sig":"%s"
|
|
"Sig":"%s"
|
|
|
}
|
|
}
|
|
|
- """.formatted(OperatorId, dataStr, timeStamp, seq, sign);
|
|
|
|
|
|
|
+ """.formatted(platform.getOperatorId(), dataStr, timeStamp, seq, sign);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -208,6 +203,7 @@ public class PlatformApiServiceImpl implements PlatformApiService {
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public String signValidation(String platformName, JSONObject json) {
|
|
public String signValidation(String platformName, JSONObject json) {
|
|
|
|
|
+ var platform = PlatformCache.INSTANCE.getPlatformByName(platformName);
|
|
|
// 验签 解密数据
|
|
// 验签 解密数据
|
|
|
var OperatorID = json.getString("OperatorID");
|
|
var OperatorID = json.getString("OperatorID");
|
|
|
var Data = json.getString("Data");
|
|
var Data = json.getString("Data");
|
|
@@ -215,12 +211,12 @@ public class PlatformApiServiceImpl implements PlatformApiService {
|
|
|
var Seq = json.getString("Seq");
|
|
var Seq = json.getString("Seq");
|
|
|
var Sig = json.getString("Sig");
|
|
var Sig = json.getString("Sig");
|
|
|
var signString = OperatorID + Data + TimeStamp + Seq;
|
|
var signString = OperatorID + Data + TimeStamp + Seq;
|
|
|
- HMac mac = new HMac(HmacAlgorithm.HmacMD5, SigSecret.getBytes());
|
|
|
|
|
|
|
+ HMac mac = new HMac(HmacAlgorithm.HmacMD5, platform.getSigSecret().getBytes());
|
|
|
// 签名(转为大写)
|
|
// 签名(转为大写)
|
|
|
var sign = mac.digestHex(signString).toUpperCase();
|
|
var sign = mac.digestHex(signString).toUpperCase();
|
|
|
if (sign.equals(Sig)) {
|
|
if (sign.equals(Sig)) {
|
|
|
// 解密数据
|
|
// 解密数据
|
|
|
- return PlatformAesUtil.decrypt(PlatformCache.INSTANCE.getPlatformByName(platformName), Data);
|
|
|
|
|
|
|
+ return PlatformAesUtil.decrypt(platform, Data);
|
|
|
} else {
|
|
} else {
|
|
|
// 验签失败
|
|
// 验签失败
|
|
|
PlatformResponse enResponse = new PlatformResponse();
|
|
PlatformResponse enResponse = new PlatformResponse();
|
|
@@ -249,7 +245,7 @@ public class PlatformApiServiceImpl implements PlatformApiService {
|
|
|
"ConnectorID":"%s"
|
|
"ConnectorID":"%s"
|
|
|
}
|
|
}
|
|
|
""".formatted(equipAuthSeq, connectorId);
|
|
""".formatted(equipAuthSeq, connectorId);
|
|
|
- var response = platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_EQUIP_AUTH.getApi(), buildPlatformParams(platformName, param));
|
|
|
|
|
|
|
+ var response = platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_EQUIP_AUTH.getApi(platformName), buildPlatformParams(platformName, param));
|
|
|
|
|
|
|
|
return parsePlatformResponseData(response, platformName);
|
|
return parsePlatformResponseData(response, platformName);
|
|
|
}
|
|
}
|
|
@@ -272,7 +268,7 @@ public class PlatformApiServiceImpl implements PlatformApiService {
|
|
|
"ConnectorID":"%s"
|
|
"ConnectorID":"%s"
|
|
|
}
|
|
}
|
|
|
""".formatted(equipBizSeq, connectorId);
|
|
""".formatted(equipBizSeq, connectorId);
|
|
|
- var response = platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_EQUIP_BUSINESS_POLICY.getApi(), buildPlatformParams(platformName, param));
|
|
|
|
|
|
|
+ var response = platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_EQUIP_BUSINESS_POLICY.getApi(platformName), buildPlatformParams(platformName, param));
|
|
|
return parsePlatformResponseData(response, platformName);
|
|
return parsePlatformResponseData(response, platformName);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -296,7 +292,7 @@ public class PlatformApiServiceImpl implements PlatformApiService {
|
|
|
"amount":"%d"
|
|
"amount":"%d"
|
|
|
}
|
|
}
|
|
|
""".formatted(startChargeSeq, connectorId, qrCode, amount);
|
|
""".formatted(startChargeSeq, connectorId, qrCode, amount);
|
|
|
- var response = platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_START_CHARGE.getApi(), buildPlatformParams(platformName, param));
|
|
|
|
|
|
|
+ var response = platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_START_CHARGE.getApi(platformName), buildPlatformParams(platformName, param));
|
|
|
return parsePlatformResponseData(response, platformName);
|
|
return parsePlatformResponseData(response, platformName);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -314,7 +310,7 @@ public class PlatformApiServiceImpl implements PlatformApiService {
|
|
|
"StartChargeSeq":"%s"
|
|
"StartChargeSeq":"%s"
|
|
|
}
|
|
}
|
|
|
""".formatted(startChargeSeq);
|
|
""".formatted(startChargeSeq);
|
|
|
- var response = platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_EQUIP_CHARGE_STATUS.getApi(), buildPlatformParams(platformName, param));
|
|
|
|
|
|
|
+ var response = platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_EQUIP_CHARGE_STATUS.getApi(platformName), buildPlatformParams(platformName, param));
|
|
|
return parsePlatformResponseData(response, platformName);
|
|
return parsePlatformResponseData(response, platformName);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -334,7 +330,7 @@ public class PlatformApiServiceImpl implements PlatformApiService {
|
|
|
"amount":%d
|
|
"amount":%d
|
|
|
}
|
|
}
|
|
|
""".formatted(startChargeSeq, amount);
|
|
""".formatted(startChargeSeq, amount);
|
|
|
- var response = platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_EQUIP_CHARGE_STATUS.getApi(), buildPlatformParams(platformName, param));
|
|
|
|
|
|
|
+ var response = platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_EQUIP_CHARGE_STATUS.getApi(platformName), buildPlatformParams(platformName, param));
|
|
|
return parsePlatformResponseData(response, platformName);
|
|
return parsePlatformResponseData(response, platformName);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -354,7 +350,7 @@ public class PlatformApiServiceImpl implements PlatformApiService {
|
|
|
"ConnectorID":"%s"
|
|
"ConnectorID":"%s"
|
|
|
}
|
|
}
|
|
|
""".formatted(startChargeSeq, connectorId);
|
|
""".formatted(startChargeSeq, connectorId);
|
|
|
- var response = platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_STOP_CHARGE.getApi(), buildPlatformParams(platformName, param));
|
|
|
|
|
|
|
+ var response = platformPost(platformName, EnPlusApi.EN_PLUS_QUERY_STOP_CHARGE.getApi(platformName), buildPlatformParams(platformName, param));
|
|
|
return parsePlatformResponseData(response, platformName);
|
|
return parsePlatformResponseData(response, platformName);
|
|
|
}
|
|
}
|
|
|
|
|
|