From 91593d3d28f4fc3b5708cb0a283b0a811adef07f Mon Sep 17 00:00:00 2001
From: dzc <2388224167@qq.com>
Date: Fri, 22 Aug 2025 16:36:23 +0800
Subject: [PATCH] =?UTF-8?q?feat:=E5=90=88=E4=BD=9C=E4=BC=99=E4=BC=B4?=
=?UTF-8?q?=E6=94=AF=E4=BB=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../client/impl/weixin/WxPayClientConfig.java | 37 ++++++++++++++++++-
.../client/impl/weixin/WxPubPayClient.java | 14 +++++--
.../src/main/resources/application-local.yaml | 18 ++++-----
.../src/main/resources/application.yaml | 14 +++----
4 files changed, 62 insertions(+), 21 deletions(-)
diff --git a/yudao-module-pay/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/weixin/WxPayClientConfig.java b/yudao-module-pay/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/weixin/WxPayClientConfig.java
index 55a1716..1c015e3 100644
--- a/yudao-module-pay/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/weixin/WxPayClientConfig.java
+++ b/yudao-module-pay/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/weixin/WxPayClientConfig.java
@@ -31,7 +31,7 @@ public class WxPayClientConfig implements PayClientConfig {
/**
* 公众号或者小程序的 appid
- *
+ *
* 只有公众号或小程序需要该字段
*/
@NotBlank(message = "APPID 不能为空", groups = {V2.class, V3.class})
@@ -41,6 +41,25 @@ public class WxPayClientConfig implements PayClientConfig {
*/
@NotBlank(message = "商户号不能为空", groups = {V2.class, V3.class})
private String mchId;
+
+ /**
+ * 商户类型
+ */
+ @NotBlank(message = "商户类型 不能为空", groups = {Single.class, Cooperate.class})
+ private String mchType;
+
+ /**
+ * 子公众号或者小程序的 appid
+ *
+ * 只有公众号或小程序需要该字段
+ */
+ private String subAppId;
+
+ /**
+ * 子商户号
+ */
+ private String subMchId;
+
/**
* API 版本
*/
@@ -56,7 +75,7 @@ public class WxPayClientConfig implements PayClientConfig {
private String mchKey;
/**
* apiclient_cert.p12 证书文件的对应字符串【base64 格式】
- *
+ *
* 为什么采用 base64 格式?因为 p12 读取后是二进制,需要转换成 base64 格式才好传输和存储
*/
@NotBlank(message = "apiclient_cert.p12 不能为空", groups = V2.class)
@@ -94,6 +113,20 @@ public class WxPayClientConfig implements PayClientConfig {
public interface V3 {
}
+ /**
+ * 商户类型,单商户
+ */
+ public interface Single {
+
+ }
+
+ /**
+ * 商户类型,合作商户
+ */
+ public interface Cooperate {
+
+ }
+
@Override
public void validate(Validator validator) {
ValidationUtils.validate(validator, this,
diff --git a/yudao-module-pay/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/weixin/WxPubPayClient.java b/yudao-module-pay/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/weixin/WxPubPayClient.java
index 390c513..84c1ba9 100644
--- a/yudao-module-pay/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/weixin/WxPubPayClient.java
+++ b/yudao-module-pay/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/weixin/WxPubPayClient.java
@@ -1,7 +1,9 @@
package cn.iocoder.yudao.framework.pay.core.client.impl.weixin;
import cn.hutool.core.map.MapUtil;
+import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONUtil;
import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO;
import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO;
import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum;
@@ -15,12 +17,14 @@ import com.github.binarywang.wxpay.constant.WxPayConstants;
import com.github.binarywang.wxpay.exception.WxPayException;
import lombok.extern.slf4j.Slf4j;
+import java.util.Objects;
+
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.invalidParamException;
import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString;
/**
* 微信支付(公众号)的 PayClient 实现类
- *
+ *
* 文档:JSAPI 下单>
*
* @author 芋道源码
@@ -44,8 +48,12 @@ public class WxPubPayClient extends AbstractWxPayClient {
@Override
protected PayOrderRespDTO doUnifiedOrderV2(PayOrderUnifiedReqDTO reqDTO) throws WxPayException {
// 构建 WxPayUnifiedOrderRequest 对象
- WxPayUnifiedOrderRequest request = buildPayUnifiedOrderRequestV2(reqDTO)
- .setOpenid(getOpenid(reqDTO));
+ WxPayUnifiedOrderRequest request = buildPayUnifiedOrderRequestV2(reqDTO);
+ if (ObjectUtil.equals(config.getMchType(), "Cooperate")) {
+ request.setSubOpenid(getOpenid(reqDTO));
+ } else {
+ request.setOpenid(getOpenid(reqDTO));
+ }
// 执行请求
WxPayMpOrderResult response = client.createOrder(request);
diff --git a/yudao-server/src/main/resources/application-local.yaml b/yudao-server/src/main/resources/application-local.yaml
index 2745166..4285195 100644
--- a/yudao-server/src/main/resources/application-local.yaml
+++ b/yudao-server/src/main/resources/application-local.yaml
@@ -46,7 +46,7 @@ spring:
primary: master
datasource:
master:
- url: jdbc:mysql://47.96.250.9:3306/ydsp?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true # MySQL Connector/J 8.X 连接的示例
+ url: jdbc:mysql://123.157.250.162:37897/bdgwc?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true # MySQL Connector/J 8.X 连接的示例
# url: jdbc:mysql://127.0.0.1:3306/ruoyi-vue-pro?useSSL=true&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true # MySQL Connector/J 5.X 连接的示例
# url: jdbc:postgresql://127.0.0.1:5432/ruoyi-vue-pro # PostgreSQL 连接的示例
# url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例
@@ -54,8 +54,8 @@ spring:
# url: jdbc:dm://127.0.0.1:5236?schema=RUOYI_VUE_PRO # DM 连接的示例
# url: jdbc:kingbase8://127.0.0.1:54321/test # 人大金仓 KingbaseES 连接的示例
# url: jdbc:postgresql://127.0.0.1:5432/postgres # OpenGauss 连接的示例
- username: ydsp
- password: KriJww38zmszYE3w
+ username: bdgwc
+ password: T3DrcpS6RhftmJrX
# username: sa # SQL Server 连接的示例
# password: Yudao@2024 # SQL Server 连接的示例
# username: SYSDBA # DM 连接的示例
@@ -64,9 +64,9 @@ spring:
# password: Yudao@2024 # OpenGauss 连接的示例
slave: # 模拟从库,可根据自己需要修改
lazy: true # 开启懒加载,保证启动速度
- url: jdbc:mysql://47.96.250.9:3306/ydsp?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&rewriteBatchedStatements=true&nullCatalogMeansCurrent=true
- username: ydsp
- password: KriJww38zmszYE3w
+ url: jdbc:mysql://123.157.250.162:37897/bdgwc?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&rewriteBatchedStatements=true&nullCatalogMeansCurrent=true
+ username: bdgwc
+ password: T3DrcpS6RhftmJrX
# tdengine: # IoT 数据库(需要 IoT 物联网再开启噢!)
# url: jdbc:TAOS-RS://127.0.0.1:6041/ruoyi_vue_pro
# driver-class-name: com.taosdata.jdbc.rs.RestfulDriver
@@ -80,7 +80,7 @@ spring:
host: 127.0.0.1 # 地址
port: 6379 # 端口
database: 0 # 数据库索引
- password: 123456 # 密码,建议生产环境开启
+ # password: 123456 # 密码,建议生产环境开启
--- #################### 定时任务相关配置 ####################
@@ -209,8 +209,8 @@ wx:
# secret: 6f270509224a7ae1296bbf1c8cb97aed
# appid: wxc4598c446f8a9cb3 # 测试号(Kongdy 提供的)
# secret: 4a1a04e07f6a4a0751b39c3064a92c8b
- appid: wx66186af0759f47c9 # 测试号(puhui 提供的)
- secret: 3218bcbd112cbc614c7264ceb20144ac
+ appid: wx48555e58acd79c3d # 测试号(puhui 提供的)
+ secret: f0f5fd485bac7f377af6f5ca97636dd4
config-storage:
type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取
key-prefix: wa # Redis Key 的前缀
diff --git a/yudao-server/src/main/resources/application.yaml b/yudao-server/src/main/resources/application.yaml
index 4e8564d..ffbef4d 100644
--- a/yudao-server/src/main/resources/application.yaml
+++ b/yudao-server/src/main/resources/application.yaml
@@ -3,8 +3,8 @@ spring:
name: yudao-server
profiles:
- active: prod
-# active: local
+ # active: prod
+ active: local
main:
allow-circular-references: true # 允许循环依赖,因为项目是三层架构,无法避免这个情况。
@@ -71,9 +71,9 @@ mybatis-plus:
global-config:
db-config:
id-type: NONE # “智能”模式,基于 IdTypeEnvironmentPostProcessor + 数据源的类型,自动适配成 AUTO、INPUT 模式。
-# id-type: AUTO # 自增 ID,适合 MySQL 等直接自增的数据库
-# id-type: INPUT # 用户输入 ID,适合 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库
-# id-type: ASSIGN_ID # 分配 ID,默认使用雪花算法。注意,Oracle、PostgreSQL、Kingbase、DB2、H2 数据库时,需要去除实体类上的 @KeySequence 注解
+ # id-type: AUTO # 自增 ID,适合 MySQL 等直接自增的数据库
+ # id-type: INPUT # 用户输入 ID,适合 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库
+ # id-type: ASSIGN_ID # 分配 ID,默认使用雪花算法。注意,Oracle、PostgreSQL、Kingbase、DB2、H2 数据库时,需要去除实体类上的 @KeySequence 注解
logic-delete-value: 1 # 逻辑已删除值(默认为 1)
logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)
banner: false # 关闭控制台的 Banner 打印
@@ -219,13 +219,13 @@ yudao:
model: Baichuan4-Turbo
midjourney:
enable: true
- # base-url: https://api.holdai.top/mj-relax/mj
+ # base-url: https://api.holdai.top/mj-relax/mj
base-url: https://api.holdai.top/mj
api-key: sk-dZEPiVaNcT3FHhef51996bAa0bC74806BeAb620dA5Da10Bf
notify-url: http://java.nat300.top/admin-api/ai/image/midjourney/notify
suno:
enable: true
- # base-url: https://suno-55ishh05u-status2xxs-projects.vercel.app
+ # base-url: https://suno-55ishh05u-status2xxs-projects.vercel.app
base-url: http://127.0.0.1:3001
--- #################### 芋道相关配置 ####################