bugfix 修复获取甬城泊车平台获取令牌错误

This commit is contained in:
Lemon
2023-11-23 11:46:11 +08:00
parent 2d3459c67b
commit 1cf38cd8e4
2 changed files with 27 additions and 5 deletions

View File

@@ -14,6 +14,7 @@ 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.yongchengboche.dto.YCBCGetTokenDTO;
import com.jsowell.thirdparty.yongchengboche.service.YCBCService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -58,6 +59,24 @@ public class YCBCController extends BaseController {
}
}
/**
* 获取token接口
* http://localhost:8080/ycbc/v1/query_token
*/
@PostMapping("/v1/ycbcQuery_token")
public String ycbcQueryToken(@RequestBody YCBCGetTokenDTO dto) {
logger.info("请求甬城泊车平台令牌 params:{}", JSONObject.toJSONString(dto));
String token = "";
try {
token = ycbcService.YCBCGetToken(dto);
logger.info("请求甬城泊车平台令牌 result:{}", token);
} catch (Exception e) {
logger.error("请求甬城泊车平台令牌接口 异常");
return "";
}
return token;
}
/**
* 甬城泊车平台查询充电站信息

View File

@@ -3,6 +3,7 @@ package com.jsowell.thirdparty.yongchengboche.service.impl;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
@@ -116,19 +117,21 @@ public class YCBCServiceImpl implements YCBCService {
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);
int succStat = Integer.parseInt(resultMap.get("SuccStat"));
JSONObject resultJson = (JSONObject) JSON.parse(dataStr);
logger.info("获取甬城泊车平台令牌 resultJson:{}", resultJson);
int succStat = resultJson.getInteger("SuccStat");
if (succStat != 0) {
logger.error("获取甬城泊车平台令牌 error:{}", result.getMsg());
return token;
}
token = resultMap.get("AccessToken");
token = resultJson.getString("AccessToken");
logger.info("甬城泊车 token: {}", token);
// 存入缓存
int tokenAvailableTime = Integer.parseInt(resultMap.get("TokenAvailableTime"));
redisCache.setCacheObject(redisKey, token, tokenAvailableTime, TimeUnit.SECONDS);
long tokenAvailableTime = resultJson.getLong("TokenAvailableTime");
redisCache.setCacheObject(redisKey, token, (int) tokenAvailableTime, TimeUnit.SECONDS);
}
} catch (Exception e) {
logger.error("获取甬城泊车平台令牌 error:", e);
return token;
}
return token;