Skip to content

Commit 11e81d8

Browse files
committed
🎨 优化代码
1 parent 5c7b6d2 commit 11e81d8

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ public interface PayScoreService {
4444
* @param queryId the query id
4545
* @return the wx pay score result
4646
* @throws WxPayException the wx pay exception
47-
* @throws URISyntaxException the uri syntax exception
4847
*/
49-
WxPayScoreResult queryServiceOrder(String outOrderNo, String queryId) throws WxPayException, URISyntaxException;
48+
WxPayScoreResult queryServiceOrder(String outOrderNo, String queryId) throws WxPayException;
5049

5150
/**
5251
* <pre>

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

+17-5
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,17 @@ public WxPayScoreResult createServiceOrder(WxPayScoreRequest request) throws WxP
6060
}
6161

6262
@Override
63-
public WxPayScoreResult queryServiceOrder(String outOrderNo, String queryId) throws WxPayException, URISyntaxException {
63+
public WxPayScoreResult queryServiceOrder(String outOrderNo, String queryId) throws WxPayException {
6464
WxPayConfig config = this.payService.getConfig();
6565
String url = this.payService.getPayBaseUrl() + "/v3/payscore/serviceorder";
66-
URIBuilder uriBuilder = new URIBuilder(url);
66+
67+
URIBuilder uriBuilder;
68+
try {
69+
uriBuilder = new URIBuilder(url);
70+
} catch (URISyntaxException e) {
71+
throw new WxPayException("未知异常!", e);
72+
}
73+
6774
if (StringUtils.isAllEmpty(outOrderNo, queryId) || !StringUtils.isAnyEmpty(outOrderNo, queryId)) {
6875
throw new WxPayException("out_order_no,query_id不允许都填写或都不填写");
6976
}
@@ -75,8 +82,13 @@ public WxPayScoreResult queryServiceOrder(String outOrderNo, String queryId) thr
7582
}
7683
uriBuilder.setParameter("service_id", config.getServiceId());
7784
uriBuilder.setParameter("appid", config.getAppId());
78-
String result = payService.getV3(uriBuilder.build());
79-
return GSON.fromJson(result, WxPayScoreResult.class);
85+
try {
86+
String result = payService.getV3(uriBuilder.build());
87+
return GSON.fromJson(result, WxPayScoreResult.class);
88+
} catch (URISyntaxException e) {
89+
throw new WxPayException("未知异常!", e);
90+
}
91+
8092
}
8193

8294
@Override
@@ -139,7 +151,7 @@ public WxPayScoreResult syncServiceOrder(WxPayScoreRequest request) throws WxPay
139151
}
140152

141153
@Override
142-
public PayScoreNotifyData parseNotifyData(String data){
154+
public PayScoreNotifyData parseNotifyData(String data) {
143155
return GSON.fromJson(data, PayScoreNotifyData.class);
144156

145157
}

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

+10-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import org.testng.annotations.Guice;
99
import org.testng.annotations.Test;
1010

11+
import java.net.URISyntaxException;
12+
1113
/**
1214
* 测试代码,待补充完善.
1315
*
@@ -62,22 +64,22 @@ public void testCreateServiceOrder() throws WxPayException {
6264
}
6365

6466
@Test
65-
public void testQueryServiceOrder() {
67+
public void testQueryServiceOrder() throws URISyntaxException, WxPayException {
6668
//两个参数选填一个
67-
this.payService.getPayScoreService().queryServiceOrder("11","");
69+
this.payService.getPayScoreService().queryServiceOrder("11", "");
6870
}
6971

7072
@Test
71-
public void testCancelServiceOrder() {
72-
this.payService.getPayScoreService().cancelServiceOrder("11","测试取消");
73+
public void testCancelServiceOrder() throws WxPayException {
74+
this.payService.getPayScoreService().cancelServiceOrder("11", "测试取消");
7375
}
7476

7577
@Test
7678
public void testModifyServiceOrder() {
7779
}
7880

7981
@Test
80-
public void testCompleteServiceOrder() throws WxPayException{
82+
public void testCompleteServiceOrder() throws WxPayException {
8183
/* {
8284
"appid":"",
8385
"service_id":"",
@@ -96,9 +98,10 @@ public void testCompleteServiceOrder() throws WxPayException{
9698
],
9799
"total_amount":100
98100
}
99-
}*/
101+
*/
100102
this.payService.getPayScoreService().completeServiceOrder(WxPayScoreRequest.builder().build());
101-
103+
}
104+
102105
@Test
103106
public void testPayServiceOrder() {
104107
}

0 commit comments

Comments
 (0)