This commit is contained in:
wangw 2025-02-10 15:32:57 +08:00
parent 90f8472fcb
commit 3123fb75fa
12 changed files with 71 additions and 19 deletions

View File

@ -43,7 +43,7 @@
<dependency>
<groupId>com.czg</groupId>
<artifactId>api-config</artifactId>
<artifactId>cash-common-api-config</artifactId>
<version>1.0.0</version>
</dependency>

View File

@ -3,12 +3,12 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.czg</groupId>
<artifactId>cash-api</artifactId>
<artifactId>cash-common</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>api-config</artifactId>
<packaging>maven-plugin</packaging>
<artifactId>cash-common-api-config</artifactId>
<packaging>jar</packaging>
<name>api-config Maven Plugin</name>
@ -19,6 +19,20 @@
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>

View File

@ -7,13 +7,14 @@
<version>1.0.0</version>
</parent>
<groupId>com.czg</groupId>
<artifactId>cash-common</artifactId>
<packaging>pom</packaging>
<modules>
<module>cash-common-tools</module>
<module>cash-common-sa-token</module>
<module>cash-common-redis</module>
<module>cash-common-api-config</module>
</modules>
</project>

View File

@ -9,7 +9,6 @@
<version>1.0.0</version>
</parent>
<groupId>com.ysk</groupId>
<artifactId>czg-pay</artifactId>
<properties>

View File

@ -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) {

View File

@ -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{
}

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.czg</groupId>
<artifactId>cash-service</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>pay-service</artifactId>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.czg</groupId>
<artifactId>czg-pay</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>

View File

@ -18,6 +18,7 @@
<module>product-service</module>
<module>system-service</module>
<module>code-generator</module>
<module>pay-service</module>
</modules>
<properties>

View File

@ -26,8 +26,6 @@
<module>cash-service</module>
<module>cash-sdk</module>
<module>cash-dependencies</module>
<module>cash-api/api-config</module>
<module>cash-common/cash-common-redis</module>
</modules>
<properties>