Skip to content

Commit 50e50c1

Browse files
authored
🎨 微信支付分支付回调接口优化以及补充测试代码
1 parent 4929e4e commit 50e50c1

File tree

3 files changed

+81
-4
lines changed

3 files changed

+81
-4
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,19 @@ public interface PayScoreService {
125125
* @return the wx pay score result
126126
* @throws WxPayException the wx pay exception
127127
*/
128-
WxPayScoreResult parseNotifyData(PayScoreNotifyData data) throws WxPayException;
128+
PayScoreNotifyData parseNotifyData(String data);
129+
130+
131+
/**
132+
* <pre>
133+
* 支付分回调NotifyData解密resource
134+
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/payscore/chapter5_2.shtml
135+
* </pre>
136+
*
137+
* @param data the data
138+
* @return the wx pay score result
139+
* @throws WxPayException the wx pay exception
140+
*/
141+
WxPayScoreResult decryptNotifyDataResource(PayScoreNotifyData data) throws WxPayException;
129142

130143
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,13 @@ public WxPayScoreResult syncServiceOrder(WxPayScoreRequest request) throws WxPay
139139
}
140140

141141
@Override
142-
public WxPayScoreResult parseNotifyData(PayScoreNotifyData data) throws WxPayException {
142+
public PayScoreNotifyData parseNotifyData(String data){
143+
return GSON.fromJson(data, PayScoreNotifyData.class);
144+
145+
}
146+
147+
@Override
148+
public WxPayScoreResult decryptNotifyDataResource(PayScoreNotifyData data) throws WxPayException {
143149
PayScoreNotifyData.Resource resource = data.getResource();
144150
String cipherText = resource.getCipherText();
145151
String associatedData = resource.getAssociatedData();

weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/PayScoreServiceImplTest.java

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,83 @@ public class PayScoreServiceImplTest {
2121
private WxPayService payService;
2222

2323
@Test
24+
2425
public void testCreateServiceOrder() throws WxPayException {
26+
//测试数据
27+
/* {
28+
"out_order_no":"QLS202005201058000201",
29+
"appid":"",
30+
"service_id":"",
31+
"service_introduction":"租借服务",
32+
"time_range":{
33+
"start_time":"OnAccept",
34+
"end_time":"20200520225840"
35+
},
36+
"location":{
37+
"start_location":"山",
38+
"end_location":"山"
39+
},
40+
"risk_fund":{
41+
"name":"DEPOSIT",
42+
"amount":200,
43+
"description":"丢失偿还费用2元/台"
44+
},
45+
"attach":"",
46+
"notify_url":"/pay/notify/payScore",
47+
"openid":"",
48+
"need_user_confirm":true,
49+
"profit_sharing":false,
50+
"post_payments":[
51+
{
52+
"name":"租借服务",
53+
"amount":100,
54+
"description":"服务费:1元/台",
55+
"count":1
56+
}
57+
],
58+
"total_amount":0
59+
}*/
60+
2561
this.payService.getPayScoreService().createServiceOrder(WxPayScoreRequest.builder().build());
2662
}
2763

2864
@Test
2965
public void testQueryServiceOrder() {
66+
//两个参数选填一个
67+
this.payService.getPayScoreService().queryServiceOrder("11","");
3068
}
3169

3270
@Test
3371
public void testCancelServiceOrder() {
72+
this.payService.getPayScoreService().cancelServiceOrder("11","测试取消");
3473
}
3574

3675
@Test
3776
public void testModifyServiceOrder() {
3877
}
3978

4079
@Test
41-
public void testCompleteServiceOrder() {
42-
}
80+
public void testCompleteServiceOrder() throws WxPayException{
81+
/* {
82+
"appid":"",
83+
"service_id":"",
84+
"time_range":{
85+
"end_time":"20200520111702"
86+
},
87+
"need_user_confirm":false,
88+
"profit_sharing":false,
89+
"post_payments":[
90+
{
91+
"name":"租借服务",
92+
"amount":100,
93+
"description":"服务费:1.0000元/台",
94+
"count":1
95+
}
96+
],
97+
"total_amount":100
98+
}
99+
}*/
100+
this.payService.getPayScoreService().completeServiceOrder(WxPayScoreRequest.builder().build());
43101

44102
@Test
45103
public void testPayServiceOrder() {

0 commit comments

Comments
 (0)