update 对接lianlian平台

This commit is contained in:
2024-05-08 19:02:54 +08:00
parent 7f342435fa
commit 541cdc1cc1
4 changed files with 26 additions and 11 deletions

View File

@@ -6,6 +6,7 @@ import com.google.common.collect.Maps;
import com.jsowell.common.annotation.Anonymous;
import com.jsowell.common.core.controller.BaseController;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.JWTUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.thirdparty.CommonParamsDTO;
import com.jsowell.pile.vo.ThirdPartySecretInfoVO;
@@ -51,6 +52,23 @@ public class ThirdPartyBaseController extends BaseController {
// }
// }
/**
* 验证token
*/
protected boolean verifyToken(String token) {
if (StringUtils.equals(token, "jsowellTest")) {
// 为了方便测试token为jsowellTest校验通过
return true;
}
boolean result;
try {
result = JWTUtils.checkThirdPartyToken(token);
} catch (Exception e) {
result = false;
}
return result;
}
/**
* 验证签名
*/

View File

@@ -3,6 +3,7 @@ package com.jsowell.web.controller.thirdparty.lianlian;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.jsowell.common.annotation.Anonymous;
import com.jsowell.common.enums.thirdparty.ThirdPartyReturnCodeEnum;
import com.jsowell.common.enums.thirdparty.ThirdPlatformTypeEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
@@ -417,17 +418,17 @@ public class LianLianController extends ThirdPartyBaseController {
logger.info("联联平台请求启动充电 params :{}", JSON.toJSONString(dto));
try {
// 校验令牌
String token = request.getHeader("Authorization");
if (!JWTUtils.checkThirdPartyToken(token)) {
boolean verifyToken = verifyToken(request.getHeader("Authorization"));
if (!verifyToken) {
// 校验失败
return CommonResult.failed("令牌校验错误");
return CommonResult.failed(ThirdPartyReturnCodeEnum.TOKEN_ERROR);
}
// 校验签名
boolean verifySign = verifySign(dto);
if (!verifySign) {
// 签名错误
return CommonResult.failed("签名校验错误");
return CommonResult.failed(ThirdPartyReturnCodeEnum.SIGN_ERROR);
}
// 解析入参

View File

@@ -138,11 +138,6 @@ public class JWTUtils {
* @return
*/
public static boolean checkThirdPartyToken(String token) {
if (StringUtils.equals(token, "jsowellTest")) {
// 为了方便测试token为jsowellTest校验通过
return true;
}
token = getToken(token);
if (StringUtils.isBlank(token)) {
throw new BusinessException(ReturnCodeEnum.CODE_TOKEN_ERROR);

View File

@@ -2,6 +2,7 @@ package com.jsowell.thirdparty.lianlian.common;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.jsowell.common.enums.thirdparty.ThirdPartyReturnCodeEnum;
import com.jsowell.thirdparty.lianlian.common.enums.ResultCode;
/**
@@ -54,8 +55,8 @@ public class CommonResult<T> {
* @param <T>
* @return
*/
public static <T> CommonResult<T> failed(ResultCode resultCode) {
return new CommonResult<T>(resultCode.getCode(), resultCode.getMsg(), null, null);
public static <T> CommonResult<T> failed(ThirdPartyReturnCodeEnum resultCode) {
return new CommonResult<T>(Long.parseLong(resultCode.getRet()), resultCode.getMsg(), null, null);
}
/**