mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-05 10:30:12 +08:00
update 苏州市平台
This commit is contained in:
@@ -43,7 +43,7 @@ public class SuZhouPlatformController extends ThirdPartyBaseController{
|
||||
try {
|
||||
Map<String, String> map = platformLogic.queryToken(dto);
|
||||
logger.info("{}-请求令牌, params:{}, result:{}", platformName, JSON.toJSONString(dto), JSON.toJSONString(map));
|
||||
return CommonResult.success(0, "请求令牌成功!", map.get("Data"), map.get("Sig"));
|
||||
return CommonResult.success(map);
|
||||
} catch (Exception e) {
|
||||
logger.error("{}-获取token接口, 异常, params:{}", platformName, JSON.toJSONString(dto), e);
|
||||
return CommonResult.failed("获取token发生异常");
|
||||
@@ -76,7 +76,7 @@ public class SuZhouPlatformController extends ThirdPartyBaseController{
|
||||
// 执行逻辑
|
||||
Map<String, String> map = platformLogic.queryStationsInfo(queryStationInfoDTO);
|
||||
|
||||
return CommonResult.success(0, "查询充电站信息成功!", map.get("Data"), map.get("Sig"));
|
||||
return CommonResult.success(map);
|
||||
} catch (Exception e) {
|
||||
logger.info("{}-查询充电站信息 error:", platformName, e);
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public class SuZhouPlatformController extends ThirdPartyBaseController{
|
||||
// 执行逻辑
|
||||
Map<String, String> map = platformLogic.queryStationStatus(queryStationInfoDTO);
|
||||
|
||||
return CommonResult.success(0, "查询充电站状态信息成功!", map.get("Data"), map.get("Sig"));
|
||||
return CommonResult.success(map);
|
||||
} catch (Exception e) {
|
||||
logger.error("{}-查询充电站状态信息 error:", platformName, e);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.jsowell.common.enums.thirdparty.ThirdPartyReturnCodeEnum;
|
||||
import com.jsowell.thirdparty.lianlian.common.enums.ResultCode;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 接口返回类
|
||||
*
|
||||
@@ -48,6 +51,10 @@ public class CommonResult<T> {
|
||||
return new CommonResult<T>(ret, msg, data, sig);
|
||||
}
|
||||
|
||||
public static <T> CommonResult<T> success(Map<String, String> map) {
|
||||
return new CommonResult<T>(Integer.parseInt(map.get("Ret")), map.get("Msg"), (T) map.get("Data"), map.get("Sig"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败返回结果
|
||||
*
|
||||
|
||||
@@ -96,52 +96,46 @@ public class SuZhouPlatformServiceImpl implements ThirdPartyPlatformService {
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> queryToken(CommonParamsDTO dto) {
|
||||
AccessTokenVO vo = new AccessTokenVO();
|
||||
// 0:成功;1:失败
|
||||
int succStat = 0;
|
||||
// 0:无;1:无此对接平台;2:密钥错误; 3~99:自定义
|
||||
int failReason = 0;
|
||||
|
||||
String operatorId = dto.getOperatorID();
|
||||
// 通过operatorId 查出 operatorSecret
|
||||
ThirdPartySecretInfoVO suZhouSecretInfo = getSuZhouSecretInfo();
|
||||
|
||||
String operatorSecret = suZhouSecretInfo.getOurOperatorSecret();
|
||||
String dataSecret = suZhouSecretInfo.getOurDataSecret();
|
||||
String dataSecretIv = suZhouSecretInfo.getOurDataSecretIv();
|
||||
String signSecret = suZhouSecretInfo.getOurSigSecret();
|
||||
|
||||
// 解密data 获取参数中的OperatorSecret
|
||||
try {
|
||||
ThirdPartySecretInfoVO thirdPartySecretInfoVO = getSuZhouSecretInfo();
|
||||
if (thirdPartySecretInfoVO == null) {
|
||||
failReason = 1;
|
||||
succStat = 1;
|
||||
} else {
|
||||
String ourOperatorSecret = thirdPartySecretInfoVO.getOurOperatorSecret();
|
||||
String dataSecret = thirdPartySecretInfoVO.getOurDataSecret();
|
||||
String dataSecretIv = thirdPartySecretInfoVO.getOurDataSecretIv();
|
||||
// 解密data 获取参数中的OperatorSecret
|
||||
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("密钥不一致");
|
||||
// 对比密钥
|
||||
if (!StringUtils.equals(ourOperatorSecret, inputOperatorSecret)) {
|
||||
failReason = 1;
|
||||
succStat = 1;
|
||||
} else {
|
||||
// 生成token
|
||||
String token = JWTUtils.createToken(operatorId, ourOperatorSecret, JWTUtils.ttlMillis);
|
||||
vo.setAccessToken(token);
|
||||
vo.setTokenAvailableTime((int) (JWTUtils.ttlMillis / 1000));
|
||||
}
|
||||
} 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<String, String> resultMap = Maps.newLinkedHashMap();
|
||||
// 加密数据
|
||||
byte[] encryptText = Cryptos.aesEncrypt(JSON.toJSONString(vo).getBytes(),
|
||||
dataSecret.getBytes(), dataSecretIv.getBytes());
|
||||
String encryptData = Encodes.encodeBase64(encryptText); // data
|
||||
resultMap.put("Ret", "0");
|
||||
resultMap.put("Msg", "请求令牌成功!");
|
||||
resultMap.put("Data", encryptData);
|
||||
// 生成sig
|
||||
String resultSign = GBSignUtils.sign(resultMap, signSecret);
|
||||
resultMap.put("Sig", resultSign);
|
||||
vo.setFailReason(failReason);
|
||||
vo.setSuccStat(succStat);
|
||||
|
||||
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(vo, thirdPartySecretInfoVO.getOurDataSecret()
|
||||
, thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getOurSigSecret());
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
@@ -214,7 +208,8 @@ public class SuZhouPlatformServiceImpl implements ThirdPartyPlatformService {
|
||||
map.put("PageCount", pageInfo.getPages());
|
||||
map.put("ItemSize", pageInfo.getTotal());
|
||||
map.put("StationInfos", resultList);
|
||||
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMap(map, thirdPartySecretInfoVO);
|
||||
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret()
|
||||
, thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getOurSigSecret());
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
@@ -324,7 +319,8 @@ public class SuZhouPlatformServiceImpl implements ThirdPartyPlatformService {
|
||||
map.put("Total", total);
|
||||
map.put("StationStatusInfos", collect);
|
||||
|
||||
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMap(map, thirdPartySecretInfoVO);
|
||||
Map<String, String> resultMap = ThirdPartyPlatformUtils.generateResultMapV2(map, thirdPartySecretInfoVO.getOurDataSecret()
|
||||
, thirdPartySecretInfoVO.getOurDataSecretIv(), thirdPartySecretInfoVO.getOurSigSecret());
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
@@ -556,9 +552,8 @@ public class SuZhouPlatformServiceImpl implements ThirdPartyPlatformService {
|
||||
// 调用联联平台接口
|
||||
String url = urlAddress + BusinessInformationExchangeEnum.NOTIFICATION_STATION_INFO.getValue();
|
||||
|
||||
String jsonStr = JSON.toJSONString(info);
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("StationInfo", jsonStr);
|
||||
data.put("StationInfo", info);
|
||||
|
||||
String jsonString = JSON.toJSONString(data);
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import javax.crypto.Mac;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class GBSignUtils {
|
||||
@@ -32,6 +33,57 @@ public class GBSignUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 经过测试,此版本方法与上面方法得到的结果相同
|
||||
* @param paramValues
|
||||
* @param secret
|
||||
* @return
|
||||
*/
|
||||
public static String signV2(Map<String, Object> paramValues, String secret) {
|
||||
try {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Object value : paramValues.values()) {
|
||||
if (StringUtils.isNotBlank((String) value)) {
|
||||
sb.append(value);
|
||||
}
|
||||
}
|
||||
logger.debug("需要签名的内容:{},密钥{}", sb.toString(), secret);
|
||||
byte[] md5Digest = HmacMD5Encrypt(sb.toString(), secret);
|
||||
String result = Encodes.encodeHex(md5Digest).toUpperCase();
|
||||
logger.debug("HmacSHA1的签名内容:{}", result);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("数据签名出错", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Map<String, String> paramValues = new LinkedHashMap<>();
|
||||
paramValues.put("Ret", "0");
|
||||
paramValues.put("Msg", "123456");
|
||||
paramValues.put("Data", "123456888888");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String value : paramValues.values()) {
|
||||
if (StringUtils.isNotBlank(value)) {
|
||||
sb.append(value);
|
||||
}
|
||||
}
|
||||
System.out.println(sb);
|
||||
|
||||
System.out.println("----------------------------------------");
|
||||
Map<String, Object> paramValues1 = new LinkedHashMap<>();
|
||||
paramValues1.put("Ret", 0);
|
||||
paramValues1.put("Msg", "123456");
|
||||
paramValues1.put("Data", "123456888888");
|
||||
StringBuilder sb1 = new StringBuilder();
|
||||
for (Object value : paramValues1.values()) {
|
||||
if (StringUtils.isNotBlank(String.valueOf(value))) {
|
||||
sb1.append(value);
|
||||
}
|
||||
}
|
||||
System.out.println(sb1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用 HMAC-MD5 签名方法对对encryptText进行签名
|
||||
*
|
||||
|
||||
@@ -54,6 +54,19 @@ public class ThirdPartyPlatformUtils {
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
public static Map<String, String> generateResultMapV2(Object obj, String dataSecret, String dataSecretIv, String signSecret) {
|
||||
Map<String, String> resultMap = Maps.newHashMap();
|
||||
// 加密数据
|
||||
String encryptData = Cryptos.aesEncrypt(JSON.toJSONString(obj), dataSecret, dataSecretIv);
|
||||
resultMap.put("Ret", "0");
|
||||
resultMap.put("Msg", "查询成功!");
|
||||
resultMap.put("Data", encryptData);
|
||||
// 生成sig
|
||||
String resultSign = GBSignUtils.sign(resultMap, signSecret);
|
||||
resultMap.put("Sig", resultSign);
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从给定的URL字符串中提取充电桩枪口号。
|
||||
*
|
||||
|
||||
@@ -124,9 +124,12 @@
|
||||
@click="clickNotificationStationStatus">推送</el-button>
|
||||
</div>
|
||||
<el-form ref="notificationForm" :model="notificationForm" label-width="20%">
|
||||
<el-form-item label="充电桩编号" class="getCard">
|
||||
<el-input v-model="notificationForm.pileSn"></el-input>
|
||||
<el-form-item label="充电桩枪口号" class="getCard">
|
||||
<el-input v-model="notificationForm.pileConnectorCode"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="枪口状态" class="getCard">
|
||||
<el-input v-model="notificationForm.connectorStatus"></el-input>
|
||||
</el-form-item>
|
||||
<!--<el-form-item>
|
||||
<el-button type="primary" @click="clickNotificationStationStatus">推送设备状态</el-button>
|
||||
</el-form-item>-->
|
||||
@@ -144,11 +147,8 @@
|
||||
@click="clickNotificationConnectorChargeStatus">推送</el-button>
|
||||
</div>
|
||||
<el-form ref="notificationForm" :model="notificationForm" label-width="20%">
|
||||
<el-form-item label="充电枪口编号">
|
||||
<el-input v-model="notificationForm.pileConnectorCode"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="充电枪口状态" class="getCard">
|
||||
<el-input v-model="notificationForm.status"></el-input>
|
||||
<el-form-item label="订单编号" class="getCard">
|
||||
<el-input v-model="notificationForm.orderCode1"></el-input>
|
||||
</el-form-item>
|
||||
<!--<el-form-item>
|
||||
<el-button type="primary" @click="clickNotificationConnectorChargeStatus">推送设备充电中状态</el-button>
|
||||
@@ -228,6 +228,7 @@ export default {
|
||||
rules: {},
|
||||
stationList: [],
|
||||
platformType: null,
|
||||
connectorStatus: null,
|
||||
drawer: false,
|
||||
direction: 'rtl',
|
||||
drawerTitle: null,
|
||||
@@ -253,17 +254,28 @@ export default {
|
||||
},
|
||||
// 点出推送设备状态
|
||||
clickNotificationStationStatus() {
|
||||
this.notificationForm.stationId = this.notificationStationId;
|
||||
this.notificationForm.platformType = this.platformType;
|
||||
notificationStationStatus(this.notificationForm).then(response => {
|
||||
// this.notificationForm.stationId = this.notificationStationId;
|
||||
// this.notificationForm.platformType = this.platformType;
|
||||
const params = {
|
||||
stationId: this.notificationStationId,
|
||||
platformType: this.platformType,
|
||||
pileConnectorCode: this.notificationForm.pileConnectorCode,
|
||||
status: this.notificationForm.connectorStatus
|
||||
}
|
||||
notificationStationStatus(params).then(response => {
|
||||
this.$modal.msgSuccess("操作成功");
|
||||
});
|
||||
},
|
||||
// 点击推送设备充电中状态
|
||||
clickNotificationConnectorChargeStatus() {
|
||||
this.notificationForm.stationId = this.notificationStationId;
|
||||
this.notificationForm.platformType = this.platformType;
|
||||
notificationConnectorChargeStatus(this.notificationForm).then(response => {
|
||||
// this.notificationForm.stationId = this.notificationStationId;
|
||||
// this.notificationForm.platformType = this.platformType;
|
||||
const params = {
|
||||
stationId: this.notificationStationId,
|
||||
platformType: this.platformType,
|
||||
orderCode: this.notificationForm.orderCode1
|
||||
}
|
||||
notificationConnectorChargeStatus(params).then(response => {
|
||||
this.$modal.msgSuccess("操作成功");
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user