mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 11:35:12 +08:00
update
This commit is contained in:
@@ -1,15 +1,28 @@
|
||||
package com.jsowell.thirdparty.yongchengboche.service.impl;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.jsowell.common.util.DateUtils;
|
||||
import com.jsowell.pile.dto.*;
|
||||
import com.jsowell.thirdparty.lianlian.dto.CommonParamsDTO;
|
||||
import com.jsowell.thirdparty.lianlian.service.LianLianService;
|
||||
import com.jsowell.thirdparty.lianlian.util.Cryptos;
|
||||
import com.jsowell.thirdparty.lianlian.util.Encodes;
|
||||
import com.jsowell.thirdparty.lianlian.util.GBSignUtils;
|
||||
import com.jsowell.thirdparty.lianlian.vo.LianLianResultVO;
|
||||
import com.jsowell.thirdparty.yongchengboche.dto.YCBCGetTokenDTO;
|
||||
import com.jsowell.thirdparty.yongchengboche.service.YCBCService;
|
||||
import com.jsowell.thirdparty.zhongdianlian.service.ZDLService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -27,6 +40,8 @@ public class YCBCServiceImpl implements YCBCService {
|
||||
@Autowired
|
||||
private LianLianService lianLianService;
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
|
||||
/**
|
||||
* 获取令牌
|
||||
@@ -35,7 +50,60 @@ public class YCBCServiceImpl implements YCBCService {
|
||||
*/
|
||||
@Override
|
||||
public String YCBCGetToken(YCBCGetTokenDTO dto) {
|
||||
return zdlService.ZDLGetToken(dto);
|
||||
String dataSecret = dto.getDataSecret();
|
||||
String dataSecretIv = dto.getDataSecretIv();
|
||||
String operatorId = dto.getOperatorId();
|
||||
String operatorSecret = dto.getOperatorSecret();
|
||||
String urlAddress = dto.getUrlAddress();
|
||||
String signSecret = dto.getSignSecret();
|
||||
|
||||
String token = "";
|
||||
try {
|
||||
// 请求地址
|
||||
String requestUrl = urlAddress + "query_token";
|
||||
|
||||
// 请求data
|
||||
Map<String, String> data = new HashMap<>();
|
||||
data.put("OperatorID", operatorId);
|
||||
data.put("OperatorSecret", operatorSecret);
|
||||
data.put("DataSecretIV", dataSecretIv);
|
||||
String dataJson = JSONUtil.toJsonStr(data);
|
||||
|
||||
// 加密
|
||||
byte[] encryptText = Cryptos.aesEncrypt(dataJson.getBytes("UTF-8"),
|
||||
dataSecret.getBytes(), dataSecretIv.getBytes());
|
||||
String strData = Encodes.encodeBase64(encryptText);
|
||||
|
||||
Map<String, String> request = new LinkedHashMap<>();
|
||||
request.put("OperatorID", 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("Portname", "wcc-pro"); // 此处是与其他获取令牌方法唯一不同之处,甬城泊车获取令牌需要添加此字段
|
||||
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, "UTF-8");
|
||||
Map<String, String> resultMap = (Map<String, String>) JSON.parse(dataStr);
|
||||
token = resultMap.get("AccessToken");
|
||||
logger.info("甬城泊车 token: {}", token);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return token;
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user