update 内蒙古平台Service

This commit is contained in:
Lemon
2025-04-08 10:16:43 +08:00
parent ee92864b19
commit b641e5cb86
4 changed files with 77 additions and 6 deletions

View File

@@ -7,6 +7,7 @@ import com.google.common.collect.Maps;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.JWTUtils;
import com.jsowell.common.util.StringUtils;

View File

@@ -1,13 +1,17 @@
package com.jsowell.thirdparty.platform.service.impl;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.thirdparty.BusinessInformationExchangeEnum;
import com.jsowell.common.enums.thirdparty.ThirdPartyOperatorIdEnum;
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
@@ -16,6 +20,7 @@ import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.*;
import com.jsowell.common.util.bean.BeanUtils;
import com.jsowell.pile.domain.OrderBasicInfo;
import com.jsowell.pile.domain.OrderDetail;
import com.jsowell.pile.domain.ThirdPartyPlatformConfig;
@@ -41,15 +46,13 @@ import com.jsowell.thirdparty.lianlian.domain.ConnectorChargeStatusInfo;
import com.jsowell.thirdparty.lianlian.domain.ConnectorStatusInfo;
import com.jsowell.thirdparty.lianlian.domain.StationStatusInfo;
import com.jsowell.thirdparty.lianlian.vo.AccessTokenVO;
import com.jsowell.thirdparty.lianlian.vo.LianLianResultVO;
import com.jsowell.thirdparty.lianlian.vo.QueryChargingStatusVO;
import com.jsowell.thirdparty.platform.domain.*;
import com.jsowell.thirdparty.platform.service.ThirdPartyPlatformService;
import com.jsowell.thirdparty.platform.factory.ThirdPartyPlatformFactory;
import com.jsowell.thirdparty.platform.util.Cryptos;
import com.jsowell.thirdparty.platform.util.Encodes;
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;
@@ -61,6 +64,7 @@ import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
@@ -545,10 +549,75 @@ public class NeiMengGuPlatformServiceImpl implements ThirdPartyPlatformService {
String jsonString = JSON.toJSONString(info);
// 获取令牌
String token = getToken(urlAddress, operatorId, operatorSecret, dataSecretIv, signSecret, dataSecret);
String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret);
String result = HttpRequestUtil.sendPost(token, jsonString, url, dataSecret, dataSecretIv, operatorId, signSecret, secretInfoVO.getPlatformType());
return result;
}
@Override
public String getToken(String urlAddress, String operatorId, String operatorSecret, String dataSecretIv, String signSecret, String dataSecret) {
String token = "";
// 先查询缓存有没有token
String tokenKey = CacheConstants.THIRD_PARTY_TOKEN_BY_OPERATOR_SECRET + operatorSecret;
RedisCache redisCache = BeanUtils.getBean(RedisCache.class);
String cacheToken = redisCache.getCacheObject(tokenKey);
if (StringUtils.isNotBlank(cacheToken)) {
token = cacheToken;
return token;
}
try {
// 请求地址
String requestUrl = urlAddress + "query_token";
// 请求data
Map<String, String> data = new HashMap<>();
data.put("PlatformID", 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("PlatformID", 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);
String response = HttpUtil.post(requestUrl, tokenRequest);
LianLianResultVO result = JSON.parseObject(response, LianLianResultVO.class);
// logger.info("获取令牌 result:{}", result);
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"));
if (resultMap.get("TokenAvailableTime") != null) {
int tokenAvailableTime = Integer.parseInt(String.valueOf(resultMap.get("TokenAvailableTime")));
// 将token存入缓存
redisCache.setCacheObject(tokenKey, token, tokenAvailableTime, TimeUnit.SECONDS);
}
// logger.info("token: {}", token);
}
// logger.info("获取令牌 result:{}, token: {}", result, token);
} catch (Exception e) {
return token;
}
return token;
}
/**
* 充电订单推送 notification_charge_order_info
*

View File

@@ -146,6 +146,7 @@ public class HttpRequestUtil {
}
if (ThirdPlatformTypeEnum.NEI_MENG_GU_PLATFORM.getTypeCode().equals(thirdPlatformType)) {
// 内蒙古平台
params.remove("OperatorID");
params.put("PlatformID", operatorId);
}