Skip to content

Commit 8009b15

Browse files
Copilotbinarywang
andauthored
修复商家转账电子回单接口为新版fund-app路径
Agent-Logs-Url: https://github.com/binarywang/WxJava/sessions/8e47db93-4c11-4263-a22d-8823b3f7d2b8 Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
1 parent 96bda5c commit 8009b15

9 files changed

Lines changed: 141 additions & 18 deletions

File tree

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/marketing/transfer/BillReceiptResult.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public String toString() {
3838
* 示例值:plfk2020042013
3939
* </pre>
4040
*/
41-
@SerializedName(value = "out_batch_no")
41+
@SerializedName(value = "out_bill_no", alternate = {"out_batch_no"})
4242
private String outBatchNo;
4343

4444
/**
@@ -68,7 +68,7 @@ public String toString() {
6868
* 示例值:ACCEPTED
6969
* </pre>
7070
*/
71-
@SerializedName(value = "signature_status")
71+
@SerializedName(value = "state", alternate = {"signature_status"})
7272
private String signatureStatus;
7373

7474
/**

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/marketing/transfer/ReceiptBillRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ public class ReceiptBillRequest implements Serializable {
3030
* 示例值:plfk2020042013
3131
* </pre>
3232
*/
33-
@SerializedName(value = "out_batch_no")
33+
@SerializedName(value = "out_bill_no", alternate = {"out_batch_no"})
3434
private String outBatchNo;
3535
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/merchanttransfer/ElectronicBillApplyRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ public class ElectronicBillApplyRequest implements Serializable {
3333
* 示例值:plfk2020042013
3434
* </pre>
3535
*/
36-
@SerializedName("out_batch_no")
36+
@SerializedName(value = "out_bill_no", alternate = {"out_batch_no"})
3737
private String outBatchNo;
3838
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/merchanttransfer/ElectronicBillResult.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class ElectronicBillResult implements Serializable {
3333
* 示例值:plfk2020042013
3434
* </pre>
3535
*/
36-
@SerializedName("out_batch_no")
36+
@SerializedName(value = "out_bill_no", alternate = {"out_batch_no"})
3737
private String outBatchNo;
3838

3939
/**
@@ -63,7 +63,7 @@ public class ElectronicBillResult implements Serializable {
6363
* 示例值:ACCEPTED
6464
* </pre>
6565
*/
66-
@SerializedName("signature_status")
66+
@SerializedName(value = "state", alternate = {"signature_status"})
6767
private String signatureStatus;
6868

6969
/**

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/MerchantTransferService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ public interface MerchantTransferService {
9191
* 转账电子回单申请受理API
9292
* <p>
9393
* 适用对象:直连商户
94-
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_7.shtml
95-
* 请求URL:https://api.mch.weixin.qq.com/v3/transfer/bill-receipt
94+
* 文档详见: https://pay.weixin.qq.com/doc/v3/merchant/4012716452
95+
* 请求URL:https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/elecsign/out-bill-no
9696
* 请求方式:POST
9797
* 接口限频: 单个商户 20QPS,如果超过频率限制,会报错FREQUENCY_LIMITED,请降低频率请求。
9898
*
@@ -106,8 +106,8 @@ public interface MerchantTransferService {
106106
* 查询转账电子回单API
107107
* <p>
108108
* 适用对象:直连商户
109-
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_8.shtml
110-
* 请求URL:https://api.mch.weixin.qq.com/v3/transfer/bill-receipt/{out_batch_no}
109+
* 文档详见: https://pay.weixin.qq.com/doc/v3/merchant/4012716436
110+
* 请求URL:https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/elecsign/out-bill-no/{out_bill_no}
111111
* 请求方式:GET
112112
*
113113
* @param outBatchNo the out batch no

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PartnerTransferService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ public interface PartnerTransferService {
9999
* 转账电子回单申请受理API
100100
* 接口说明
101101
* 适用对象:直连商户 服务商
102-
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer/chapter4_1.shtml
103-
* 请求URL:https://api.mch.weixin.qq.com/v3/transfer/bill-receipt
102+
* 文档详见: https://pay.weixin.qq.com/doc/v3/merchant/4012716452
103+
* 请求URL:https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/elecsign/out-bill-no
104104
* 请求方式:POST
105105
*
106106
* @param request 商家批次单号
@@ -114,8 +114,8 @@ public interface PartnerTransferService {
114114
* 查询转账电子回单API
115115
* 接口说明
116116
* 适用对象:直连商户 服务商
117-
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer/chapter4_2.shtml
118-
* 请求URL:https://api.mch.weixin.qq.com/v3/transfer/bill-receipt/{out_batch_no}
117+
* 文档详见: https://pay.weixin.qq.com/doc/v3/merchant/4012716436
118+
* 请求URL:https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/elecsign/out-bill-no/{out_bill_no}
119119
* 请求方式:GET
120120
*
121121
* @param outBatchNo 商家批次单号

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/MerchantTransferServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ public DetailsQueryResult queryMerchantDetails(MerchantDetailsQueryRequest reque
9292

9393
@Override
9494
public ElectronicBillResult applyElectronicBill(ElectronicBillApplyRequest request) throws WxPayException {
95-
String url = String.format("%s/v3/transfer/bill-receipt", this.wxPayService.getPayBaseUrl());
95+
String url = String.format("%s/v3/fund-app/mch-transfer/elecsign/out-bill-no", this.wxPayService.getPayBaseUrl());
9696
String response = wxPayService.postV3(url, GSON.toJson(request));
9797
return GSON.fromJson(response, ElectronicBillResult.class);
9898
}
9999

100100
@Override
101101
public ElectronicBillResult queryElectronicBill(String outBatchNo) throws WxPayException {
102-
String url = String.format("%s/v3/transfer/bill-receipt/%s", this.wxPayService.getPayBaseUrl(), outBatchNo);
102+
String url = String.format("%s/v3/fund-app/mch-transfer/elecsign/out-bill-no/%s", this.wxPayService.getPayBaseUrl(), outBatchNo);
103103
String response = wxPayService.getV3(url);
104104
return GSON.fromJson(response, ElectronicBillResult.class);
105105
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PartnerTransferServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public BatchDetailsResult queryBatchDetailByMch(String outBatchNo, String outDet
196196
*/
197197
@Override
198198
public BillReceiptResult receiptBill(ReceiptBillRequest request) throws WxPayException {
199-
String url = String.format("%s/v3/transfer/bill-receipt", this.payService.getPayBaseUrl());
199+
String url = String.format("%s/v3/fund-app/mch-transfer/elecsign/out-bill-no", this.payService.getPayBaseUrl());
200200
String response = this.payService.postV3(url, GSON.toJson(request));
201201
return GSON.fromJson(response, BillReceiptResult.class);
202202
}
@@ -216,7 +216,7 @@ public BillReceiptResult receiptBill(ReceiptBillRequest request) throws WxPayExc
216216
*/
217217
@Override
218218
public BillReceiptResult queryBillReceipt(String outBatchNo) throws WxPayException {
219-
String url = String.format("%s/v3/transfer/bill-receipt/%s", this.payService.getPayBaseUrl(), outBatchNo);
219+
String url = String.format("%s/v3/fund-app/mch-transfer/elecsign/out-bill-no/%s", this.payService.getPayBaseUrl(), outBatchNo);
220220
String response = this.payService.getV3(url);
221221
return GSON.fromJson(response, BillReceiptResult.class);
222222
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package com.github.binarywang.wxpay.service.impl;
2+
3+
import com.github.binarywang.wxpay.bean.marketing.transfer.BillReceiptResult;
4+
import com.github.binarywang.wxpay.bean.marketing.transfer.ReceiptBillRequest;
5+
import com.github.binarywang.wxpay.bean.merchanttransfer.ElectronicBillApplyRequest;
6+
import com.github.binarywang.wxpay.bean.merchanttransfer.ElectronicBillResult;
7+
import com.github.binarywang.wxpay.exception.WxPayException;
8+
import com.github.binarywang.wxpay.service.WxPayService;
9+
import com.google.gson.Gson;
10+
import org.testng.Assert;
11+
import org.testng.annotations.Test;
12+
13+
import java.lang.reflect.InvocationHandler;
14+
import java.lang.reflect.Method;
15+
import java.lang.reflect.Proxy;
16+
17+
@Test
18+
public class TransferReceiptApiCompatibilityTest {
19+
20+
private static final String BASE_URL = "https://api.mch.weixin.qq.com";
21+
22+
public void shouldUseNewMerchantTransferElecsignApiPath() throws WxPayException {
23+
RequestCaptureHandler handler = new RequestCaptureHandler();
24+
WxPayService wxPayService = handler.createWxPayService();
25+
MerchantTransferServiceImpl merchantTransferService = new MerchantTransferServiceImpl(wxPayService);
26+
27+
merchantTransferService.applyElectronicBill(new ElectronicBillApplyRequest().setOutBatchNo("plfk2020042013"));
28+
Assert.assertEquals(handler.lastPostUrl, BASE_URL + "/v3/fund-app/mch-transfer/elecsign/out-bill-no");
29+
Assert.assertTrue(handler.lastPostBody.contains("\"out_bill_no\""));
30+
Assert.assertFalse(handler.lastPostBody.contains("\"out_batch_no\""));
31+
32+
merchantTransferService.queryElectronicBill("plfk2020042013");
33+
Assert.assertEquals(handler.lastGetUrl, BASE_URL + "/v3/fund-app/mch-transfer/elecsign/out-bill-no/plfk2020042013");
34+
}
35+
36+
public void shouldUseNewPartnerTransferElecsignApiPath() throws WxPayException {
37+
RequestCaptureHandler handler = new RequestCaptureHandler();
38+
WxPayService wxPayService = handler.createWxPayService();
39+
PartnerTransferServiceImpl partnerTransferService = new PartnerTransferServiceImpl(wxPayService);
40+
41+
ReceiptBillRequest request = new ReceiptBillRequest();
42+
request.setOutBatchNo("plfk2020042013");
43+
partnerTransferService.receiptBill(request);
44+
Assert.assertEquals(handler.lastPostUrl, BASE_URL + "/v3/fund-app/mch-transfer/elecsign/out-bill-no");
45+
Assert.assertTrue(handler.lastPostBody.contains("\"out_bill_no\""));
46+
Assert.assertFalse(handler.lastPostBody.contains("\"out_batch_no\""));
47+
48+
partnerTransferService.queryBillReceipt("plfk2020042013");
49+
Assert.assertEquals(handler.lastGetUrl, BASE_URL + "/v3/fund-app/mch-transfer/elecsign/out-bill-no/plfk2020042013");
50+
}
51+
52+
public void shouldDeserializeNewResponseFieldNames() {
53+
Gson gson = new Gson();
54+
BillReceiptResult billReceiptResult =
55+
gson.fromJson("{\"out_bill_no\":\"plfk2020042013\",\"state\":\"FINISHED\"}", BillReceiptResult.class);
56+
Assert.assertEquals(billReceiptResult.getOutBatchNo(), "plfk2020042013");
57+
Assert.assertEquals(billReceiptResult.getSignatureStatus(), "FINISHED");
58+
59+
ElectronicBillResult electronicBillResult =
60+
gson.fromJson("{\"out_bill_no\":\"plfk2020042013\",\"state\":\"FINISHED\"}", ElectronicBillResult.class);
61+
Assert.assertEquals(electronicBillResult.getOutBatchNo(), "plfk2020042013");
62+
Assert.assertEquals(electronicBillResult.getSignatureStatus(), "FINISHED");
63+
}
64+
65+
private static class RequestCaptureHandler implements InvocationHandler {
66+
private String lastPostUrl;
67+
private String lastPostBody;
68+
private String lastGetUrl;
69+
70+
private WxPayService createWxPayService() {
71+
return (WxPayService) Proxy.newProxyInstance(
72+
WxPayService.class.getClassLoader(),
73+
new Class<?>[]{WxPayService.class},
74+
this
75+
);
76+
}
77+
78+
@Override
79+
public Object invoke(Object proxy, Method method, Object[] args) {
80+
if ("getPayBaseUrl".equals(method.getName())) {
81+
return BASE_URL;
82+
}
83+
if ("postV3".equals(method.getName())) {
84+
this.lastPostUrl = (String) args[0];
85+
this.lastPostBody = (String) args[1];
86+
return "{}";
87+
}
88+
if ("getV3".equals(method.getName())) {
89+
this.lastGetUrl = (String) args[0];
90+
return "{}";
91+
}
92+
if ("toString".equals(method.getName())) {
93+
return "MockWxPayService";
94+
}
95+
Class<?> returnType = method.getReturnType();
96+
if (boolean.class.equals(returnType)) {
97+
return false;
98+
}
99+
if (int.class.equals(returnType)) {
100+
return 0;
101+
}
102+
if (long.class.equals(returnType)) {
103+
return 0L;
104+
}
105+
if (double.class.equals(returnType)) {
106+
return 0D;
107+
}
108+
if (float.class.equals(returnType)) {
109+
return 0F;
110+
}
111+
if (short.class.equals(returnType)) {
112+
return (short) 0;
113+
}
114+
if (byte.class.equals(returnType)) {
115+
return (byte) 0;
116+
}
117+
if (char.class.equals(returnType)) {
118+
return (char) 0;
119+
}
120+
return null;
121+
}
122+
}
123+
}

0 commit comments

Comments
 (0)