From 1eeb095eaddc43fe976d5cdd2422083c3723e16f Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Mar 2026 16:07:22 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20#3918=20=E3=80=90=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E3=80=91=E6=9C=8D=E5=8A=A1=E5=95=86=E9=80=80?= =?UTF-8?q?=E6=AC=BE=EF=BC=88V3=EF=BC=89=E8=AF=B7=E6=B1=82=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E8=A1=A5=E9=BD=90=E7=BC=BA=E5=A4=B1=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=20(sp=5Fappid=20=E5=92=8C=20sub=5Fappid)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/WxPayPartnerRefundV3Request.java | 29 +++++++++- .../service/impl/BaseWxPayServiceImpl.java | 6 ++ .../WxPayPartnerRefundV3RequestTest.java | 55 +++++++++++++++++++ 3 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/request/WxPayPartnerRefundV3RequestTest.java diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayPartnerRefundV3Request.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayPartnerRefundV3Request.java index 8f3e8ebd1..a565388e6 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayPartnerRefundV3Request.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayPartnerRefundV3Request.java @@ -11,15 +11,38 @@ import java.io.Serializable; * 微信支付服务商退款请求 * 文档见:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_1_9.shtml * - * @author Pursuer - * @version 1.0 - * @date 2023/3/2 */ @Data @NoArgsConstructor @Accessors(chain = true) public class WxPayPartnerRefundV3Request extends WxPayRefundV3Request implements Serializable { private static final long serialVersionUID = -1L; + /** + *
+ * 字段名:服务商应用ID + * 变量名:sp_appid + * 是否必填:是 + * 类型:string[1, 32] + * 描述: + * 服务商申请的公众号或移动应用appid。 + * 示例值:wx8888888888888888 + *+ */ + @SerializedName(value = "sp_appid") + private String spAppid; + /** + *
+ * 字段名:子商户应用ID + * 变量名:sub_appid + * 是否必填:否 + * 类型:string[1, 32] + * 描述: + * 子商户申请的公众号或移动应用appid。如果传了sub_appid,那sub_appid对应的订单必须存在。 + * 示例值:wx8888888888888888 + *+ */ + @SerializedName(value = "sub_appid") + private String subAppid; /** *
* 字段名:退款资金来源
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java
index 06c7a2485..36987f637 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java
@@ -404,6 +404,12 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
@Override
public WxPayRefundV3Result partnerRefundV3(WxPayPartnerRefundV3Request request) throws WxPayException {
+ if (StringUtils.isBlank(request.getSpAppid())) {
+ request.setSpAppid(this.getConfig().getAppId());
+ }
+ if (StringUtils.isBlank(request.getSubAppid()) && StringUtils.isNotBlank(this.getConfig().getSubAppId())) {
+ request.setSubAppid(this.getConfig().getSubAppId());
+ }
if (StringUtils.isBlank(request.getNotifyUrl())) {
request.setNotifyUrl(this.getConfig().getRefundNotifyUrl());
}
diff --git a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/request/WxPayPartnerRefundV3RequestTest.java b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/request/WxPayPartnerRefundV3RequestTest.java
new file mode 100644
index 000000000..ebdc99208
--- /dev/null
+++ b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/request/WxPayPartnerRefundV3RequestTest.java
@@ -0,0 +1,55 @@
+package com.github.binarywang.wxpay.bean.request;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import org.testng.annotations.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * {@link WxPayPartnerRefundV3Request} 单元测试
+ *
+ */
+public class WxPayPartnerRefundV3RequestTest {
+
+ @Test
+ public void testSpAppidAndSubAppidSerialization() {
+ WxPayPartnerRefundV3Request request = new WxPayPartnerRefundV3Request();
+ request.setSpAppid("wx8888888888888888");
+ request.setSubAppid("wxd678efh567hg6999");
+ request.setSubMchid("1230000109");
+ request.setOutRefundNo("1217752501201407033233368018");
+ request.setFundsAccount("AVAILABLE");
+
+ Gson gson = new Gson();
+ String json = gson.toJson(request);
+ JsonObject jsonObject = gson.fromJson(json, JsonObject.class);
+
+ assertThat(jsonObject.has("sp_appid")).isTrue();
+ assertThat(jsonObject.get("sp_appid").getAsString()).isEqualTo("wx8888888888888888");
+ assertThat(jsonObject.has("sub_appid")).isTrue();
+ assertThat(jsonObject.get("sub_appid").getAsString()).isEqualTo("wxd678efh567hg6999");
+ assertThat(jsonObject.has("sub_mchid")).isTrue();
+ assertThat(jsonObject.get("sub_mchid").getAsString()).isEqualTo("1230000109");
+ assertThat(jsonObject.has("out_refund_no")).isTrue();
+ assertThat(jsonObject.get("out_refund_no").getAsString()).isEqualTo("1217752501201407033233368018");
+ assertThat(jsonObject.has("funds_account")).isTrue();
+ assertThat(jsonObject.get("funds_account").getAsString()).isEqualTo("AVAILABLE");
+ }
+
+ @Test
+ public void testSubAppidIsOptional() {
+ WxPayPartnerRefundV3Request request = new WxPayPartnerRefundV3Request();
+ request.setSpAppid("wx8888888888888888");
+ request.setSubMchid("1230000109");
+ request.setOutRefundNo("1217752501201407033233368018");
+
+ Gson gson = new Gson();
+ String json = gson.toJson(request);
+ JsonObject jsonObject = gson.fromJson(json, JsonObject.class);
+
+ assertThat(jsonObject.has("sp_appid")).isTrue();
+ assertThat(jsonObject.get("sp_appid").getAsString()).isEqualTo("wx8888888888888888");
+ assertThat(jsonObject.has("sub_appid")).isFalse();
+ }
+}