pom
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<groupId>com.ysk</groupId>
|
||||
<artifactId>czg-pay</artifactId>
|
||||
|
||||
<properties>
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.czg.entity.CzgBaseReqParams;
|
||||
import com.czg.entity.CzgBaseRespParams;
|
||||
import com.czg.entity.req.*;
|
||||
import com.czg.enums.CzgPayEnum;
|
||||
import com.czg.resp.CzgRespCode;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.utils.MD5Util;
|
||||
import lombok.NonNull;
|
||||
@@ -134,21 +135,22 @@ public class CzgPayUtils {
|
||||
* @param dataJsonStr 带解析数据
|
||||
* @param clazz 返回的实体类
|
||||
*/
|
||||
public static <T> T getCzg(String dataJsonStr, Class<T> clazz) throws Exception {
|
||||
public static <T> T getCzg(String dataJsonStr, Class<T> clazz) {
|
||||
if (StrUtil.isNotEmpty(dataJsonStr)) {
|
||||
CzgBaseRespParams respParams = JSONObject.parseObject(dataJsonStr, CzgBaseRespParams.class);
|
||||
log.info("超掌柜交易请求响应,{}", respParams);
|
||||
if (!"000000".equals(respParams.getCode())) {
|
||||
log.error("超掌柜回调响应失败,{}", respParams);
|
||||
throw new Exception("超掌柜回调响应失败");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(respParams.getSign())) {
|
||||
validateSign(respParams.getSign(), respParams.getBizData());
|
||||
if (!validateSign(respParams.getSign(), respParams.getBizData())) {
|
||||
log.error("超掌柜回调 验签失败,{}", respParams);
|
||||
}
|
||||
}
|
||||
return JSONObject.parseObject(respParams.getBizData(), clazz);
|
||||
} else {
|
||||
throw new Exception("超掌柜回调接收内容异常");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,16 +180,20 @@ public class CzgPayUtils {
|
||||
result.setCode("000000".equals(respParams.getCode()) ? 200 : Integer.parseInt(respParams.getCode()));
|
||||
result.setMsg(respParams.getMsg());
|
||||
if ("000000".equals(respParams.getCode()) && StrUtil.isNotBlank(respParams.getSign())) {
|
||||
validateSign(respParams.getSign(), respParams.getBizData());
|
||||
if (!validateSign(respParams.getSign(), respParams.getBizData())) {
|
||||
result.setCode(CzgRespCode.FAILURE.getCode());
|
||||
result.setMsg("验签失败");
|
||||
}
|
||||
result.setData(respParams.getBizData());
|
||||
}
|
||||
} else {
|
||||
throw new Exception("超掌柜交易请求异常");
|
||||
result.setCode(resp.getStatus());
|
||||
result.setMsg("超掌柜交易请求失败");
|
||||
log.error("超掌柜交易请求失败,状态码: {}", resp.getStatus());
|
||||
}
|
||||
} else {
|
||||
result.setCode(resp.getStatus());
|
||||
result.setMsg("超掌柜交易请求失败");
|
||||
log.error("超掌柜交易请求失败,状态码: {}", resp.getStatus());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("超掌柜交易请求异常", e);
|
||||
@@ -198,14 +204,15 @@ public class CzgPayUtils {
|
||||
/**
|
||||
* @param sign 签名
|
||||
* @param dataJsonStr 业务数据
|
||||
* @throws Exception 验签失败
|
||||
* @return true 验签通过 false 验签失败
|
||||
*/
|
||||
private static void validateSign(String sign, String dataJsonStr) throws Exception {
|
||||
private static boolean validateSign(String sign, String dataJsonStr) {
|
||||
Map dataMap = JSONObject.parseObject(dataJsonStr, Map.class);
|
||||
String newSign = MD5Util.md5AsHex(sortFields(new TreeMap<>(dataMap)));
|
||||
if (!sign.equals(newSign)) {
|
||||
throw new Exception("验签失败");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static String sortFields(TreeMap<String, Object> map) {
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
package com.czg.entity.resp;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* @author ww
|
||||
* @description H5支付响应参数
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class CzgH5PayResp extends CzgBaseResp{
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user