diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/JWTUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/JWTUtils.java index 4af94b228..39fff47c1 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/util/JWTUtils.java +++ b/jsowell-common/src/main/java/com/jsowell/common/util/JWTUtils.java @@ -48,6 +48,9 @@ public class JWTUtils { private static final Long MILLIS_MINUTE_TEN = 20 * 60 * 1000L; + // 第三方平台token过期时间 24小时 + public static final long ttlMillis = 60 * 60 * 24 * 1000; + /** * 生成Jwt的方法 * diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/ThirdPartyPlatformService.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/ThirdPartyPlatformService.java index ec61b6ed9..9f3d4d52f 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/ThirdPartyPlatformService.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/ThirdPartyPlatformService.java @@ -38,6 +38,10 @@ public interface ThirdPartyPlatformService { throw new UnsupportedOperationException("This method is not yet implemented"); } + default Map queryToken(String operatorId, String operatorSecret) { + throw new UnsupportedOperationException("This method is not yet implemented"); + } + // =================================================================================== // // ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ 由我方平台实现此接口,对方平台调用的查询接口 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ // // =================================================================================== // diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/lianlian/service/LianLianPlatformServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/lianlian/service/LianLianPlatformServiceImpl.java index 9d0b4f2c5..7b73c5b93 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/lianlian/service/LianLianPlatformServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/lianlian/service/LianLianPlatformServiceImpl.java @@ -14,7 +14,9 @@ import com.jsowell.common.enums.thirdparty.BusinessInformationExchangeEnum; import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum; import com.jsowell.common.enums.ykc.OrderPayModeEnum; import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum; +import com.jsowell.common.exception.BusinessException; import com.jsowell.common.util.DateUtils; +import com.jsowell.common.util.JWTUtils; import com.jsowell.common.util.PageUtils; import com.jsowell.common.util.StringUtils; import com.jsowell.pile.domain.*; @@ -28,10 +30,11 @@ import com.jsowell.pile.vo.lianlian.PushStationFeeVO; import com.jsowell.pile.vo.uniapp.BillingPriceVO; import com.jsowell.pile.vo.web.PileStationVO; import com.jsowell.thirdparty.lianlian.domain.*; +import com.jsowell.thirdparty.lianlian.vo.AccessTokenVO; +import com.jsowell.thirdparty.platform.ThirdPartyPlatformService; import com.jsowell.thirdparty.platform.util.Cryptos; import com.jsowell.thirdparty.platform.util.GBSignUtils; import com.jsowell.thirdparty.platform.util.HttpRequestUtil; -import com.jsowell.thirdparty.platform.ThirdPartyPlatformService; import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -104,6 +107,84 @@ public class LianLianPlatformServiceImpl implements ThirdPartyPlatformService { return resultMap; } + // @Override + public Map queryTokenV2(CommonParamsDTO dto) { + String operatorId = dto.getOperatorID(); + // 通过operatorId 查出 operatorSecret + ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorId); + if (platformConfig == null) { + throw new BusinessException("1", "无此对接平台"); + } + + String operatorSecret = platformConfig.getOperatorSecret(); + String dataSecret = platformConfig.getDataSecret(); + String dataSecretIv = platformConfig.getDataSecretIv(); + String signSecret = platformConfig.getSignSecret(); + + // 解密data 获取参数中的OperatorSecret + try { + String decrypt = Cryptos.decrypt(dto.getData(), dataSecret, dataSecretIv); + String inputOperatorSecret = null; + if (StringUtils.isNotBlank(decrypt)) { + inputOperatorSecret = JSON.parseObject(decrypt).getString("OperatorSecret"); + } + if (!StringUtils.equals(operatorSecret, inputOperatorSecret)) { + throw new RuntimeException("密钥不一致"); + } + } catch (RuntimeException e) { + throw new BusinessException("2", "密钥错误"); + } + + // 生成token + String token = JWTUtils.createToken(operatorId, operatorSecret, JWTUtils.ttlMillis); + + // 组装返回参数 + AccessTokenVO vo = new AccessTokenVO(); + vo.setAccessToken(token); + vo.setOperatorID(operatorId); + vo.setTokenAvailableTime((int) (JWTUtils.ttlMillis / 1000)); + vo.setFailReason(0); + vo.setSuccStat(0); + + Map resultMap = Maps.newLinkedHashMap(); + // 加密数据 + String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(vo), dataSecret, dataSecretIv); + resultMap.put("Data", encryptData); + // 生成sig + String resultSign = GBSignUtils.sign(resultMap, signSecret); + resultMap.put("Sig", resultSign); + return resultMap; + } + + public static void main(String[] args) { + // 中电联平台 + String operatorId = "14405899X"; + String operatorSecret = "EOub5WNbERyOedvk"; + String dataSecret = "vj3RWNsWIxT5MC0K"; + String dataSecretIv = "jjkySnGlM3pbOUki"; + String signSecret = "NbELMbWtbHikNSlu"; + + String data = "JdVMdw0JVYvouzS4WA9APlqKyQJuTuvh43lDYGaVccrvMboNTVajQdkvtLfqq3+lxlUXkokSkGSDsmxNkUT/SQ=="; + String Seq = "0029"; + String sig = "C6410BF5C7185CAE8594846E006740E1"; + String timeStamp = "2024-03-27 16:18:39"; + + // 解密data 获取参数中的OperatorSecret + try { + String decrypt = Cryptos.decrypt(data, dataSecret, dataSecretIv); + String inputOperatorSecret = null; + if (StringUtils.isNotBlank(decrypt)) { + inputOperatorSecret = JSON.parseObject(decrypt).getString("OperatorSecret"); + } + if (!StringUtils.equals(operatorSecret, inputOperatorSecret)) { + throw new RuntimeException("密钥不一致"); + } + } catch (RuntimeException e) { + throw new BusinessException("2", "密钥错误"); + } + + } + /** * 查询充电站信息 query_stations_info * 此接口用于查询对接平台的充电站的信息 diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/util/Cryptos.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/util/Cryptos.java index 267182c91..03388e589 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/util/Cryptos.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/platform/util/Cryptos.java @@ -34,6 +34,7 @@ public class Cryptos { private static SecureRandom random = new SecureRandom(); private static final String AES_CIPHER_ALGORITHM = "AES/CBC/PKCS5Padding"; + /** * 数据加密方法 * @param data 待加密的数据