From 11e81d83186a2f1439483d643de061bb9246ae8e Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 21 May 2020 21:23:53 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wxpay/service/PayScoreService.java | 3 +-- .../service/impl/PayScoreServiceImpl.java | 22 ++++++++++++++----- .../service/impl/PayScoreServiceImplTest.java | 17 ++++++++------ 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PayScoreService.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PayScoreService.java index 079f1e7ca..e9b71d2cc 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PayScoreService.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/PayScoreService.java @@ -44,9 +44,8 @@ public interface PayScoreService { * @param queryId the query id * @return the wx pay score result * @throws WxPayException the wx pay exception - * @throws URISyntaxException the uri syntax exception */ - WxPayScoreResult queryServiceOrder(String outOrderNo, String queryId) throws WxPayException, URISyntaxException; + WxPayScoreResult queryServiceOrder(String outOrderNo, String queryId) throws WxPayException; /** *
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PayScoreServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PayScoreServiceImpl.java
index 299e8f87d..f99d5c91b 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PayScoreServiceImpl.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PayScoreServiceImpl.java
@@ -60,10 +60,17 @@ public class PayScoreServiceImpl implements PayScoreService {
   }
 
   @Override
-  public WxPayScoreResult queryServiceOrder(String outOrderNo, String queryId) throws WxPayException, URISyntaxException {
+  public WxPayScoreResult queryServiceOrder(String outOrderNo, String queryId) throws WxPayException {
     WxPayConfig config = this.payService.getConfig();
     String url = this.payService.getPayBaseUrl() + "/v3/payscore/serviceorder";
-    URIBuilder uriBuilder = new URIBuilder(url);
+
+    URIBuilder uriBuilder;
+    try {
+      uriBuilder = new URIBuilder(url);
+    } catch (URISyntaxException e) {
+      throw new WxPayException("未知异常!", e);
+    }
+
     if (StringUtils.isAllEmpty(outOrderNo, queryId) || !StringUtils.isAnyEmpty(outOrderNo, queryId)) {
       throw new WxPayException("out_order_no,query_id不允许都填写或都不填写");
     }
@@ -75,8 +82,13 @@ public class PayScoreServiceImpl implements PayScoreService {
     }
     uriBuilder.setParameter("service_id", config.getServiceId());
     uriBuilder.setParameter("appid", config.getAppId());
-    String result = payService.getV3(uriBuilder.build());
-    return GSON.fromJson(result, WxPayScoreResult.class);
+    try {
+      String result = payService.getV3(uriBuilder.build());
+      return GSON.fromJson(result, WxPayScoreResult.class);
+    } catch (URISyntaxException e) {
+      throw new WxPayException("未知异常!", e);
+    }
+
   }
 
   @Override
@@ -139,7 +151,7 @@ public class PayScoreServiceImpl implements PayScoreService {
   }
 
   @Override
-  public PayScoreNotifyData parseNotifyData(String data){
+  public PayScoreNotifyData parseNotifyData(String data) {
     return GSON.fromJson(data, PayScoreNotifyData.class);
 
   }
diff --git a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/PayScoreServiceImplTest.java b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/PayScoreServiceImplTest.java
index fd805b6fc..67483268c 100644
--- a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/PayScoreServiceImplTest.java
+++ b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/PayScoreServiceImplTest.java
@@ -8,6 +8,8 @@ import com.google.inject.Inject;
 import org.testng.annotations.Guice;
 import org.testng.annotations.Test;
 
+import java.net.URISyntaxException;
+
 /**
  * 测试代码,待补充完善.
  *
@@ -62,14 +64,14 @@ public class PayScoreServiceImplTest {
   }
 
   @Test
-  public void testQueryServiceOrder() {
+  public void testQueryServiceOrder() throws URISyntaxException, WxPayException {
     //两个参数选填一个
-    this.payService.getPayScoreService().queryServiceOrder("11","");
+    this.payService.getPayScoreService().queryServiceOrder("11", "");
   }
 
   @Test
-  public void testCancelServiceOrder() {
-    this.payService.getPayScoreService().cancelServiceOrder("11","测试取消");
+  public void testCancelServiceOrder() throws WxPayException {
+    this.payService.getPayScoreService().cancelServiceOrder("11", "测试取消");
   }
 
   @Test
@@ -77,7 +79,7 @@ public class PayScoreServiceImplTest {
   }
 
   @Test
-  public void testCompleteServiceOrder()  throws WxPayException{
+  public void testCompleteServiceOrder() throws WxPayException {
 /*    {
       "appid":"",
       "service_id":"",
@@ -96,9 +98,10 @@ public class PayScoreServiceImplTest {
     ],
       "total_amount":100
     }
-  }*/
+*/
     this.payService.getPayScoreService().completeServiceOrder(WxPayScoreRequest.builder().build());
-
+  }
+  
   @Test
   public void testPayServiceOrder() {
   }