diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/thirdparty/ThirdPlatformTypeEnum.java b/jsowell-common/src/main/java/com/jsowell/common/enums/thirdparty/ThirdPlatformTypeEnum.java index 1ba6534a7..a304c6a4c 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/enums/thirdparty/ThirdPlatformTypeEnum.java +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/thirdparty/ThirdPlatformTypeEnum.java @@ -18,7 +18,7 @@ public enum ThirdPlatformTypeEnum { HAI_NAN_1_PLATFORM("7", "海南一张网(监管平台)", "578725200"), HAI_NAN_2_PLATFORM("8", "海南一张网(充电平台)", "MAA9A0PP1"), HUA_WEI("9", "华为平台", "MA5GTQ528"), - NEI_MENG_GU_PLATFORM("10", "内蒙古平台", ""), + NEI_MENG_GU_PLATFORM("10", "内蒙古平台", "MAB03NTXZ"), QING_HAI_PLATFORM("11", "青海平台", "630000000"), DIAN_XING_PLATFORM("12", "宁波点行停车平台", ""), NING_XIA_PLATFORM("13", "宁夏平台", "MA01H3BQ9"), diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/ThirdPartyPlatformService.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/ThirdPartyPlatformService.java index 8b1551d17..09517a058 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/ThirdPartyPlatformService.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/ThirdPartyPlatformService.java @@ -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; diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/NeiMengGuPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/NeiMengGuPlatformServiceImpl.java index 5ca48cccd..ee9d15700 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/NeiMengGuPlatformServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/service/impl/NeiMengGuPlatformServiceImpl.java @@ -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 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 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 resultMap = (Map) 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 * diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/util/HttpRequestUtil.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/util/HttpRequestUtil.java index 48a40a5a9..4e5d5bdf4 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/util/HttpRequestUtil.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/util/HttpRequestUtil.java @@ -146,6 +146,7 @@ public class HttpRequestUtil { } if (ThirdPlatformTypeEnum.NEI_MENG_GU_PLATFORM.getTypeCode().equals(thirdPlatformType)) { // 内蒙古平台 + params.remove("OperatorID"); params.put("PlatformID", operatorId); }