mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-25 05:25:12 +08:00
update 第三方平台相关方法
This commit is contained in:
@@ -166,11 +166,11 @@ public interface LianLianService {
|
||||
* @return
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException;
|
||||
// Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* 校验签名
|
||||
* @param dto
|
||||
*/
|
||||
Map<String, String> checkoutSign(CommonParamsDTO dto);
|
||||
// Map<String, String> checkoutSign(CommonParamsDTO dto);
|
||||
}
|
||||
|
||||
@@ -16,10 +16,8 @@ import com.jsowell.common.enums.lianlian.StationPaymentEnum;
|
||||
import com.jsowell.common.enums.thirdparty.BusinessInformationExchangeEnum;
|
||||
import com.jsowell.common.enums.thirdparty.ThirdPartyOperatorIdEnum;
|
||||
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
|
||||
import com.jsowell.common.enums.ykc.OrderPayModeEnum;
|
||||
import com.jsowell.common.enums.ykc.OrderStatusEnum;
|
||||
import com.jsowell.common.enums.ykc.PileConnectorDataBaseStatusEnum;
|
||||
import com.jsowell.common.enums.ykc.PileStatusEnum;
|
||||
import com.jsowell.common.enums.ykc.*;
|
||||
import com.jsowell.common.exception.BusinessException;
|
||||
import com.jsowell.common.util.*;
|
||||
import com.jsowell.pile.domain.*;
|
||||
import com.jsowell.pile.domain.ykcCommond.StartChargingCommand;
|
||||
@@ -29,6 +27,7 @@ import com.jsowell.pile.thirdparty.CommonParamsDTO;
|
||||
import com.jsowell.pile.thirdparty.ConnectorInfo;
|
||||
import com.jsowell.pile.thirdparty.EquipmentInfo;
|
||||
import com.jsowell.pile.util.MerchantUtils;
|
||||
import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
|
||||
import com.jsowell.pile.vo.base.*;
|
||||
import com.jsowell.pile.vo.lianlian.AccumulativeInfoVO;
|
||||
import com.jsowell.pile.vo.lianlian.PushStationFeeVO;
|
||||
@@ -43,10 +42,8 @@ import com.jsowell.thirdparty.lianlian.vo.*;
|
||||
import com.jsowell.thirdparty.platform.common.ChargeDetail;
|
||||
import com.jsowell.thirdparty.platform.common.OrderInfo;
|
||||
import com.jsowell.thirdparty.platform.common.StationInfo;
|
||||
import com.jsowell.thirdparty.platform.util.Cryptos;
|
||||
import com.jsowell.thirdparty.platform.util.Encodes;
|
||||
import com.jsowell.thirdparty.platform.util.GBSignUtils;
|
||||
import com.jsowell.thirdparty.platform.util.HttpRequestUtil;
|
||||
import com.jsowell.thirdparty.platform.util.*;
|
||||
import com.jsowell.thirdparty.service.ThirdpartySecretInfoService;
|
||||
import com.jsowell.thirdparty.yongchengboche.dto.YCBCGetTokenDTO;
|
||||
import com.jsowell.thirdparty.yongchengboche.service.YCBCService;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
@@ -103,10 +100,7 @@ public class LianLianServiceImpl implements LianLianService {
|
||||
private PileBillingTemplateService pileBillingTemplateService;
|
||||
|
||||
@Autowired
|
||||
private ThirdPartySettingInfoService thirdPartySettingInfoService;
|
||||
|
||||
@Autowired
|
||||
private ThirdPartyPlatformConfigService thirdPartyPlatformConfigService;
|
||||
private ThirdpartySecretInfoService thirdpartySecretInfoService;
|
||||
|
||||
@Autowired
|
||||
private ThirdPartyStationRelationService thirdPartyStationRelationService;
|
||||
@@ -134,14 +128,14 @@ public class LianLianServiceImpl implements LianLianService {
|
||||
// 通过第三方配置类型查询相关配置信息
|
||||
ThirdPartySettingInfo settingInfo = new ThirdPartySettingInfo();
|
||||
settingInfo.setType(dto.getThirdPartyType());
|
||||
ThirdPartySettingInfo thirdPartySettingInfo = thirdPartySettingInfoService.selectSettingInfo(settingInfo);
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
|
||||
|
||||
String operatorId = thirdPartySettingInfo.getOperatorId();
|
||||
String operatorSecret = thirdPartySettingInfo.getOperatorSecret();
|
||||
String signSecret = thirdPartySettingInfo.getSignSecret();
|
||||
String dataSecret = thirdPartySettingInfo.getDataSecret();
|
||||
String dataSecretIv = thirdPartySettingInfo.getDataSecretIv();
|
||||
String urlAddress = thirdPartySettingInfo.getUrlAddress();
|
||||
String operatorId = thirdPartySecretInfoVO.getTheirOperatorId();
|
||||
String operatorSecret = thirdPartySecretInfoVO.getTheirOperatorSecret();
|
||||
String signSecret = thirdPartySecretInfoVO.getTheirSigSecret();
|
||||
String dataSecret = thirdPartySecretInfoVO.getTheirDataSecret();
|
||||
String dataSecretIv = thirdPartySecretInfoVO.getTheirDataSecretIv();
|
||||
String urlAddress = thirdPartySecretInfoVO.getTheirUrlPrefix();
|
||||
|
||||
// 组装联联平台所需要的数据格式
|
||||
StationInfo info = StationInfo.builder()
|
||||
@@ -302,10 +296,8 @@ public class LianLianServiceImpl implements LianLianService {
|
||||
// 未查到数据
|
||||
return null;
|
||||
}
|
||||
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
|
||||
if (configInfo == null) {
|
||||
return null;
|
||||
}
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
|
||||
|
||||
PageInfo<ThirdPartyStationInfoVO> pageInfo = new PageInfo<>(stationInfos);
|
||||
for (ThirdPartyStationInfoVO pileStationInfo : pageInfo.getList()) {
|
||||
StationInfo stationInfo = new StationInfo();
|
||||
@@ -361,17 +353,8 @@ public class LianLianServiceImpl implements LianLianService {
|
||||
// .list(resultList)
|
||||
// .build();
|
||||
// 加密
|
||||
Map<String, String> resultMap = Maps.newLinkedHashMap();
|
||||
// 加密数据
|
||||
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).getBytes(),
|
||||
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
|
||||
String encryptData = Encodes.encodeBase64(encryptText);
|
||||
|
||||
resultMap.put("Data", encryptData);
|
||||
// 生成sig
|
||||
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
|
||||
resultMap.put("Sig", resultSign);
|
||||
|
||||
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
|
||||
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
@@ -387,10 +370,8 @@ public class LianLianServiceImpl implements LianLianService {
|
||||
List<String> stationIds = dto.getStationIds();
|
||||
List<StationStatusInfo> StationStatusInfos = new ArrayList<>();
|
||||
List<Object> ConnectorStatusInfos = new ArrayList<>();
|
||||
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
|
||||
if (configInfo == null) {
|
||||
return null;
|
||||
}
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
|
||||
|
||||
ConnectorStatusInfo connectorStatusInfo;
|
||||
for (String stationId : stationIds) {
|
||||
StationStatusInfo stationStatusInfo= new StationStatusInfo();
|
||||
@@ -454,17 +435,8 @@ public class LianLianServiceImpl implements LianLianService {
|
||||
map.put("StationStatusInfos", collect);
|
||||
|
||||
// 加密
|
||||
Map<String, String> resultMap = Maps.newLinkedHashMap();
|
||||
// 加密数据
|
||||
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).getBytes(),
|
||||
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
|
||||
String encryptData = Encodes.encodeBase64(encryptText);
|
||||
|
||||
resultMap.put("Data", encryptData);
|
||||
// 生成sig
|
||||
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
|
||||
resultMap.put("Sig", resultSign);
|
||||
|
||||
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
|
||||
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
@@ -476,10 +448,8 @@ public class LianLianServiceImpl implements LianLianService {
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> query_station_stats(QueryStationInfoDTO dto) {
|
||||
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
|
||||
if (configInfo == null) {
|
||||
return null;
|
||||
}
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
|
||||
|
||||
// 根据站点id 查出这段时间的充电量
|
||||
List<AccumulativeInfoVO> list = orderBasicInfoService.getAccumulativeInfoForLianLian(dto);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
@@ -553,17 +523,8 @@ public class LianLianServiceImpl implements LianLianService {
|
||||
map.put("StationStats", stationStatsInfo);
|
||||
|
||||
// 加密
|
||||
Map<String, String> resultMap = Maps.newLinkedHashMap();
|
||||
// 加密数据
|
||||
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).getBytes(),
|
||||
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
|
||||
String encryptData = Encodes.encodeBase64(encryptText);
|
||||
|
||||
resultMap.put("Data", encryptData);
|
||||
// 生成sig
|
||||
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
|
||||
resultMap.put("Sig", resultSign);
|
||||
|
||||
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
|
||||
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
@@ -575,16 +536,13 @@ public class LianLianServiceImpl implements LianLianService {
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> query_equip_auth(QueryEquipmentDTO dto) {
|
||||
Map<String, String> resultMap = Maps.newLinkedHashMap();
|
||||
EquipmentAuthVO vo = new EquipmentAuthVO();
|
||||
|
||||
String equipAuthSeq = dto.getEquipAuthSeq(); // MA1X78KH5202311071202015732
|
||||
String pileConnectorCode = dto.getConnectorID();
|
||||
// 先查询配置密钥相关信息
|
||||
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorID());
|
||||
if (configInfo == null) {
|
||||
return null;
|
||||
}
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
|
||||
|
||||
// 根据桩编号查询数据
|
||||
// String merchantId = StringUtils.substring(equipAuthSeq, 0, 9);
|
||||
// String pileSn = StringUtils.substring(pileConnectorCode, 0, 14);
|
||||
@@ -612,15 +570,8 @@ public class LianLianServiceImpl implements LianLianService {
|
||||
vo.setFailReasonMsg("未查到该桩的数据");
|
||||
}
|
||||
// 加密数据
|
||||
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(vo).getBytes(),
|
||||
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
|
||||
String encryptData = Encodes.encodeBase64(encryptText);
|
||||
|
||||
resultMap.put("Data", encryptData);
|
||||
// 生成sig
|
||||
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
|
||||
resultMap.put("Sig", resultSign);
|
||||
|
||||
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(),
|
||||
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
@@ -638,10 +589,8 @@ public class LianLianServiceImpl implements LianLianService {
|
||||
// 平台已存在订单
|
||||
return null;
|
||||
}
|
||||
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
|
||||
if (configInfo == null) {
|
||||
return null;
|
||||
}
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
|
||||
|
||||
// 生成订单
|
||||
Map<String, Object> map = orderBasicInfoService.generateOrderForThirdParty(dto);
|
||||
String orderCode = (String) map.get("orderCode");
|
||||
@@ -675,19 +624,9 @@ public class LianLianServiceImpl implements LianLianService {
|
||||
}
|
||||
|
||||
// 加密
|
||||
Map<String, String> resultMap = Maps.newLinkedHashMap();
|
||||
// 加密数据
|
||||
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(vo).getBytes(),
|
||||
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
|
||||
String encryptData = Encodes.encodeBase64(encryptText);
|
||||
|
||||
resultMap.put("Data", encryptData);
|
||||
// 生成sig
|
||||
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
|
||||
resultMap.put("Sig", resultSign);
|
||||
|
||||
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret(),
|
||||
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
|
||||
return resultMap;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -707,11 +646,8 @@ public class LianLianServiceImpl implements LianLianService {
|
||||
if (orderInfo == null) {
|
||||
return null;
|
||||
}
|
||||
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorID);
|
||||
// logger.info(operatorName + "查询密钥信息 configInfo:{}", configInfo);
|
||||
if (configInfo == null) {
|
||||
return null;
|
||||
}
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
|
||||
|
||||
OrderDetail orderDetail = orderBasicInfoService.getOrderDetailByOrderCode(orderInfo.getOrderCode());
|
||||
// 通过订单号查询实时数据
|
||||
List<RealTimeMonitorData> realTimeData = orderBasicInfoService.getChargingRealTimeData(orderInfo.getTransactionCode());
|
||||
@@ -762,17 +698,8 @@ public class LianLianServiceImpl implements LianLianService {
|
||||
}
|
||||
|
||||
// 加密
|
||||
Map<String, String> resultMap = Maps.newLinkedHashMap();
|
||||
// 加密数据
|
||||
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(vo).getBytes(),
|
||||
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
|
||||
String encryptData = Encodes.encodeBase64(encryptText);
|
||||
|
||||
resultMap.put("Data", encryptData);
|
||||
// 生成sig
|
||||
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
|
||||
resultMap.put("Sig", resultSign);
|
||||
|
||||
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(),
|
||||
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
@@ -793,10 +720,8 @@ public class LianLianServiceImpl implements LianLianService {
|
||||
if (orderInfo == null) {
|
||||
return null;
|
||||
}
|
||||
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
|
||||
if (configInfo == null) {
|
||||
return null;
|
||||
}
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
|
||||
|
||||
// 若状态为充电中,则发送停机指令
|
||||
if (StringUtils.equals(OrderStatusEnum.IN_THE_CHARGING.getValue(), orderInfo.getOrderStatus())) {
|
||||
// 充电中
|
||||
@@ -818,17 +743,8 @@ public class LianLianServiceImpl implements LianLianService {
|
||||
vo.setStartChargeSeqStat(3);
|
||||
}
|
||||
// 加密
|
||||
Map<String, String> resultMap = Maps.newLinkedHashMap();
|
||||
// 加密数据
|
||||
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(vo).getBytes(),
|
||||
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
|
||||
String encryptData = Encodes.encodeBase64(encryptText);
|
||||
|
||||
resultMap.put("Data", encryptData);
|
||||
// 生成sig
|
||||
String resultSign = GBSignUtils.sign(resultMap, configInfo.getSignSecret());
|
||||
resultMap.put("Sig", resultSign);
|
||||
|
||||
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret(),
|
||||
thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getTheirSigSecret());
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
@@ -1195,9 +1111,10 @@ public class LianLianServiceImpl implements LianLianService {
|
||||
}
|
||||
String data = map.get("Data");
|
||||
// 解密data (此处解密需用 thirdparty_platform_config 的密钥配置)
|
||||
ThirdPartyPlatformConfig configInfo = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorIdByType);
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
|
||||
|
||||
byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(data),
|
||||
configInfo.getDataSecret().getBytes(), configInfo.getDataSecretIv().getBytes());
|
||||
thirdPartySecretInfoVO.getOurDataSecret().getBytes(), thirdPartySecretInfoVO.getOurDataSecretIv().getBytes());
|
||||
String dataStr = new String(plainText, StandardCharsets.UTF_8);
|
||||
// 转成对应的对象
|
||||
QueryChargingStatusVO vo = JSONObject.parseObject(dataStr, QueryChargingStatusVO.class);
|
||||
@@ -1397,11 +1314,8 @@ public class LianLianServiceImpl implements LianLianService {
|
||||
if (orderInfo == null || orderDetail == null) {
|
||||
return null;
|
||||
}
|
||||
// 通过operatorID 查出 operatorSecret
|
||||
ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(dto.getOperatorId());
|
||||
if (platformConfig == null) {
|
||||
return null;
|
||||
}
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
|
||||
|
||||
// orderInfo 和 orderDetail 都不为空,再根据传过来的数据进行修改数据库信息
|
||||
confirmResult = Constants.zero;
|
||||
orderDetail.setTotalUsedElectricity(dto.getTotalPower()); // 累计充电量
|
||||
@@ -1414,12 +1328,12 @@ public class LianLianServiceImpl implements LianLianService {
|
||||
Map<String, String> resultMap = Maps.newLinkedHashMap();
|
||||
// 加密数据
|
||||
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(map).getBytes(),
|
||||
platformConfig.getDataSecret().getBytes(), platformConfig.getDataSecretIv().getBytes());
|
||||
thirdPartySecretInfoVO.getOurDataSecret().getBytes(), thirdPartySecretInfoVO.getOurDataSecretIv().getBytes());
|
||||
String encryptData = Encodes.encodeBase64(encryptText);
|
||||
|
||||
resultMap.put("Data", encryptData);
|
||||
// 生成sig
|
||||
String resultSign = GBSignUtils.sign(resultMap, platformConfig.getSignSecret());
|
||||
String resultSign = GBSignUtils.sign(resultMap, thirdPartySecretInfoVO.getOurSigSecret());
|
||||
resultMap.put("Sig", resultSign);
|
||||
|
||||
return resultMap;
|
||||
@@ -1670,107 +1584,104 @@ public class LianLianServiceImpl implements LianLianService {
|
||||
* @return
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException {
|
||||
String operatorId = dto.getOperatorID();
|
||||
// 通过operatorId 查出 operatorSecret
|
||||
ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorId);
|
||||
if (platformConfig == null) {
|
||||
return null;
|
||||
}
|
||||
String operatorSecret = platformConfig.getOperatorSecret();
|
||||
String dataSecret = platformConfig.getDataSecret();
|
||||
String dataSecretIv = platformConfig.getDataSecretIv();
|
||||
String signSecret = platformConfig.getSignSecret();
|
||||
// 校验签名
|
||||
Map<String, String> checkResultMap = checkoutSign(dto);
|
||||
if (checkResultMap == null) {
|
||||
// 校验失败
|
||||
return null;
|
||||
}
|
||||
String dataString = checkResultMap.get("Data");
|
||||
// 解密data
|
||||
byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIv.getBytes());
|
||||
String dataStr = new String(plainText, StandardCharsets.UTF_8);
|
||||
Map<String, String> resMap = (Map<String, String>) JSON.parse(dataStr);
|
||||
String secret = resMap.get("OperatorSecret");
|
||||
|
||||
// 对比解出来的密钥是否和数据库中保存的一致
|
||||
if (!StringUtils.equals(operatorSecret, secret)) {
|
||||
System.out.println("密钥不一致");
|
||||
return null;
|
||||
}
|
||||
System.out.println("密钥校验通过!! 密钥为: " + operatorSecret);
|
||||
|
||||
// 生成token返回 eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI0MjUwMTA3NjUiLCJpYXQiOjE2ODUwOTcxMTYsInN1YiI6IjEyMzEyMzEyMzEyM2FhYWEiLCJleHAiOjY4NjkwOTcxMTZ9.NyxOUIZmgsqtfex7oiMRR2LaWePTA56WHVMXIkWWt2w
|
||||
long ttlMillis = 60 * 60 * 24 * 1000;
|
||||
String token = JWTUtils.createToken(operatorId, operatorSecret, ttlMillis);
|
||||
System.out.println("生成的token:" + token);
|
||||
|
||||
// 组装返回参数
|
||||
AccessTokenVO vo = new AccessTokenVO();
|
||||
vo.setAccessToken(token);
|
||||
vo.setOperatorID(operatorId);
|
||||
vo.setTokenAvailableTime((int) (ttlMillis / 1000));
|
||||
vo.setFailReason(0);
|
||||
vo.setSuccStat(0);
|
||||
|
||||
Map<String, String> resultMap = Maps.newLinkedHashMap();
|
||||
// 加密数据
|
||||
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(vo).getBytes(),
|
||||
dataSecret.getBytes(), dataSecretIv.getBytes());
|
||||
String encryptData = Encodes.encodeBase64(encryptText);
|
||||
|
||||
resultMap.put("Data", encryptData);
|
||||
// 生成sig
|
||||
String resultSign = GBSignUtils.sign(resultMap, signSecret);
|
||||
resultMap.put("Sig", resultSign);
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
// @Override
|
||||
// public Map<String, String> generateToken(CommonParamsDTO dto) throws UnsupportedEncodingException {
|
||||
// String operatorId = dto.getOperatorID();
|
||||
// ThirdPartySecretInfoVO thirdPartySecretInfoVO = getLianLianPlatformSecretInfo();
|
||||
//
|
||||
// String operatorSecret = thirdPartySecretInfoVO.getOurOperatorSecret();
|
||||
// String dataSecret = thirdPartySecretInfoVO.getOurDataSecret();
|
||||
// String dataSecretIv = thirdPartySecretInfoVO.getOurDataSecretIv();
|
||||
// String signSecret = thirdPartySecretInfoVO.getOurSigSecret();
|
||||
// // 校验签名
|
||||
// Map<String, String> checkResultMap = checkoutSign(dto);
|
||||
// if (checkResultMap == null) {
|
||||
// // 校验失败
|
||||
// return null;
|
||||
// }
|
||||
// String dataString = checkResultMap.get("Data");
|
||||
// // 解密data
|
||||
// byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dataString), dataSecret.getBytes(), dataSecretIv.getBytes());
|
||||
// String dataStr = new String(plainText, StandardCharsets.UTF_8);
|
||||
// Map<String, String> resMap = (Map<String, String>) JSON.parse(dataStr);
|
||||
// String secret = resMap.get("OperatorSecret");
|
||||
//
|
||||
// // 对比解出来的密钥是否和数据库中保存的一致
|
||||
// if (!StringUtils.equals(operatorSecret, secret)) {
|
||||
// System.out.println("密钥不一致");
|
||||
// return null;
|
||||
// }
|
||||
// System.out.println("密钥校验通过!! 密钥为: " + operatorSecret);
|
||||
//
|
||||
// // 生成token返回 eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI0MjUwMTA3NjUiLCJpYXQiOjE2ODUwOTcxMTYsInN1YiI6IjEyMzEyMzEyMzEyM2FhYWEiLCJleHAiOjY4NjkwOTcxMTZ9.NyxOUIZmgsqtfex7oiMRR2LaWePTA56WHVMXIkWWt2w
|
||||
// long ttlMillis = 60 * 60 * 24 * 1000;
|
||||
// String token = JWTUtils.createToken(operatorId, operatorSecret, ttlMillis);
|
||||
// System.out.println("生成的token:" + token);
|
||||
//
|
||||
// // 组装返回参数
|
||||
// AccessTokenVO vo = new AccessTokenVO();
|
||||
// vo.setAccessToken(token);
|
||||
// vo.setOperatorID(operatorId);
|
||||
// vo.setTokenAvailableTime((int) (ttlMillis / 1000));
|
||||
// vo.setFailReason(0);
|
||||
// vo.setSuccStat(0);
|
||||
//
|
||||
// Map<String, String> resultMap = Maps.newLinkedHashMap();
|
||||
// // 加密数据
|
||||
// byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(vo).getBytes(),
|
||||
// dataSecret.getBytes(), dataSecretIv.getBytes());
|
||||
// String encryptData = Encodes.encodeBase64(encryptText);
|
||||
//
|
||||
// resultMap.put("Data", encryptData);
|
||||
// // 生成sig
|
||||
// String resultSign = GBSignUtils.sign(resultMap, signSecret);
|
||||
// resultMap.put("Sig", resultSign);
|
||||
//
|
||||
// return resultMap;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 校验签名并返回data(未解密)
|
||||
* @param dto
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> checkoutSign(CommonParamsDTO dto){
|
||||
String operatorID = dto.getOperatorID();
|
||||
// 通过operatorID 查出 operatorSecret
|
||||
ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorID);
|
||||
if (platformConfig == null) {
|
||||
return null;
|
||||
}
|
||||
String operatorSecret = platformConfig.getOperatorSecret();
|
||||
String signSecret = platformConfig.getSignSecret();
|
||||
|
||||
Map<String, String> map = Maps.newLinkedHashMap();
|
||||
map.put("OperatorID", dto.getOperatorID());
|
||||
map.put("Data", dto.getData());
|
||||
map.put("TimeStamp", dto.getTimeStamp());
|
||||
map.put("Seq", dto.getSeq());
|
||||
String sign = GBSignUtils.sign(map, signSecret);
|
||||
System.out.println(sign);
|
||||
|
||||
// 验证签名 得到请求方传过来的签名sig->自己拿到请求体后,再按双方约定的协议生成一个sig->对比两个sig是否一致
|
||||
if (!StringUtils.equals(dto.getSig(), sign)) {
|
||||
System.out.println("签名校验==失败");
|
||||
return null;
|
||||
}
|
||||
System.out.println("签名校验通过!!!");
|
||||
|
||||
// 解密data
|
||||
// byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dto.getData()), operatorSecret.getBytes(), operatorSecret.getBytes());
|
||||
// String dataStr = new String(plainText, "UTF-8");
|
||||
// Map<String, String> resMap = (Map<String, String>) JSON.parse(dataStr);
|
||||
// return resMap;
|
||||
Map<String, String> resultMap = new LinkedHashMap<>();
|
||||
resultMap.put("Data", dto.getData());
|
||||
resultMap.put("OperatorSecret", operatorSecret);
|
||||
resultMap.put("DataSecret", platformConfig.getDataSecret());
|
||||
resultMap.put("DataSecretIV", platformConfig.getDataSecretIv());
|
||||
return resultMap;
|
||||
}
|
||||
// @Override
|
||||
// public Map<String, String> checkoutSign(CommonParamsDTO dto){
|
||||
// String operatorID = dto.getOperatorID();
|
||||
// // 通过operatorID 查出 operatorSecret
|
||||
// ThirdPartyPlatformConfig platformConfig = thirdPartyPlatformConfigService.getInfoByOperatorId(operatorID);
|
||||
// if (platformConfig == null) {
|
||||
// return null;
|
||||
// }
|
||||
// String operatorSecret = platformConfig.getOperatorSecret();
|
||||
// String signSecret = platformConfig.getSignSecret();
|
||||
//
|
||||
// Map<String, String> map = Maps.newLinkedHashMap();
|
||||
// map.put("OperatorID", dto.getOperatorID());
|
||||
// map.put("Data", dto.getData());
|
||||
// map.put("TimeStamp", dto.getTimeStamp());
|
||||
// map.put("Seq", dto.getSeq());
|
||||
// String sign = GBSignUtils.sign(map, signSecret);
|
||||
// System.out.println(sign);
|
||||
//
|
||||
// // 验证签名 得到请求方传过来的签名sig->自己拿到请求体后,再按双方约定的协议生成一个sig->对比两个sig是否一致
|
||||
// if (!StringUtils.equals(dto.getSig(), sign)) {
|
||||
// System.out.println("签名校验==失败");
|
||||
// return null;
|
||||
// }
|
||||
// System.out.println("签名校验通过!!!");
|
||||
//
|
||||
// // 解密data
|
||||
// // byte[] plainText = Cryptos.aesDecrypt(Encodes.decodeBase64(dto.getData()), operatorSecret.getBytes(), operatorSecret.getBytes());
|
||||
// // String dataStr = new String(plainText, "UTF-8");
|
||||
// // Map<String, String> resMap = (Map<String, String>) JSON.parse(dataStr);
|
||||
// // return resMap;
|
||||
// Map<String, String> resultMap = new LinkedHashMap<>();
|
||||
// resultMap.put("Data", dto.getData());
|
||||
// resultMap.put("OperatorSecret", operatorSecret);
|
||||
// resultMap.put("DataSecret", platformConfig.getDataSecret());
|
||||
// resultMap.put("DataSecretIV", platformConfig.getDataSecretIv());
|
||||
// return resultMap;
|
||||
// }
|
||||
|
||||
/**
|
||||
* TODO 请求打印充电小票
|
||||
@@ -1870,4 +1781,19 @@ public class LianLianServiceImpl implements LianLianService {
|
||||
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取联联平台配置密钥信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private ThirdPartySecretInfoVO getLianLianPlatformSecretInfo() {
|
||||
// 通过第三方平台类型查询相关配置信息
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = thirdpartySecretInfoService.queryByThirdPlatformType(ThirdPlatformTypeEnum.LIAN_LIAN_PLATFORM.getTypeCode());
|
||||
if (thirdPartySecretInfoVO == null) {
|
||||
throw new BusinessException(ReturnCodeEnum.CODE_SELECT_INFO_IS_NULL);
|
||||
}
|
||||
thirdPartySecretInfoVO.setOurOperatorId(Constants.OPERATORID_JIANG_SU);
|
||||
return thirdPartySecretInfoVO;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user