From 3fde78070037d46fb2af7240de41b47a8c3fab4a Mon Sep 17 00:00:00 2001
From: ChenJiaHe <763432473@qq.com>
Date: 星期五, 16 十月 2020 11:53:43 +0800
Subject: [PATCH] 共用新增改查,action直接引用CommonService,service直接引用CommonDao

---
 src/main/java/com/hx/mp/util/WXPayUtil.java |   56 ++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 36 insertions(+), 20 deletions(-)

diff --git a/src/main/java/com/hx/mp/util/WXPayUtil.java b/src/main/java/com/hx/mp/util/WXPayUtil.java
index 79aea02..3006e70 100644
--- a/src/main/java/com/hx/mp/util/WXPayUtil.java
+++ b/src/main/java/com/hx/mp/util/WXPayUtil.java
@@ -2,7 +2,9 @@
 
 import com.hx.exception.ServiceException;
 import com.hx.util.SimpleTool;
+import com.hx.util.StringUtils;
 import net.sf.json.JSONObject;
+import org.apache.commons.io.IOUtils;
 import org.apache.http.HttpEntity;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpPost;
@@ -321,37 +323,47 @@
              try {
                  StringEntity se = new StringEntity(xml);
                  httppost.setEntity(se);  
-                 System.out.println("executing request" + httppost.getRequestLine());  
+
                  CloseableHttpResponse responseEntry = httpclient.execute(httppost);
                  try {  
                      HttpEntity entity = responseEntry.getEntity();
-                     System.out.println(responseEntry.getStatusLine());  
                      if (entity != null) {
+
                          SAXReader saxReader = new SAXReader();
                          Document document = saxReader.read(entity.getContent());
                          Element rootElt = document.getRootElement();
-                         String resultCode = rootElt.elementText("result_code");  
-                         JSONObject result = new JSONObject();  
+                         String returnCode = rootElt.elementText("return_code");
+                         JSONObject result = new JSONObject();
 
-                         if(resultCode.equals("SUCCESS")){  
-                             result.put("weixinPayUrl", rootElt.elementText("code_url"));
-                             result.put("prepayId", rootElt.elementText("prepay_id"));  
-                             result.put("msg","success");  
-                             
-                         	String refund_id = rootElt.elementText("refund_id");//寰俊閫�娆惧崟鍙�
-             				String r_out_refund_no=rootElt.elementText("out_refund_no");
-                         	String errMsg = "鍟嗘埛鍙�"+r_out_refund_no+"鐨勯��娆炬祦姘村彿鏄細"+refund_id;
-                         	result.put("status", "SUCCESS");
-                         	result.put("errMsg", errMsg);
-                         	result.put("refund_id", refund_id);
+                         if(returnCode.equals("SUCCESS")){
+                             String resultCode = rootElt.elementText("result_code");
+                             if(resultCode.equals("SUCCESS")) {
+                                 result.put("weixinPayUrl", rootElt.elementText("code_url"));
+                                 result.put("prepayId", rootElt.elementText("prepay_id"));
+                                 result.put("msg", "success");
+
+                                 String refund_id = rootElt.elementText("refund_id");//寰俊閫�娆惧崟鍙�
+                                 String r_out_refund_no = rootElt.elementText("out_refund_no");
+                                 String errMsg = "鍟嗘埛鍙�" + r_out_refund_no + "鐨勯��娆炬祦姘村彿鏄細" + refund_id;
+                                 result.put("status", "SUCCESS");
+                                 result.put("errMsg", errMsg);
+                                 result.put("refund_id", refund_id);
+                             }else{
+                                 String errMsg = "[ERROR]result_code:" + rootElt.elementText("result_code")+
+                                         " err_code:" + rootElt.elementText("err_code");
+
+                                 //閿欒鏃讹紝杩斿洖缁撴灉鏈鍚嶏紝璁板綍retcode銆乺etmsg鐪嬪け璐ヨ鎯呫��
+                                 result.put("errMsg", errMsg);
+                                 result.put("status","false");
+                                 result.put("msg",rootElt.elementText("err_code_des"));
+                             }
                          }else{  
-                         	String errMsg = "[ERROR]result_code:" + rootElt.elementText("result_code")+
-         							" err_code:" + rootElt.elementText("err_code");
+                         	String errMsg = "[ERROR]return_code:" + rootElt.elementText("return_code");
          					
          					//閿欒鏃讹紝杩斿洖缁撴灉鏈鍚嶏紝璁板綍retcode銆乺etmsg鐪嬪け璐ヨ鎯呫��
                          	result.put("errMsg", errMsg);
                          	result.put("status","false");
-                         	result.put("msg",rootElt.elementText("err_code_des"));
+                         	result.put("msg",rootElt.elementText("return_msg"));
                          }  
                          return result;  
                      }  
@@ -395,8 +407,12 @@
             parameters.put("appid",appId);
             parameters.put("mch_id",partner);
             parameters.put("nonce_str", nonceStr);
-            parameters.put("out_trade_no", out_trade_no);
-            parameters.put("transaction_id", transaction_id);
+            if(!StringUtils.isEmpty(out_trade_no)) {
+                parameters.put("out_trade_no", out_trade_no);
+            }
+            if(!StringUtils.isEmpty(transaction_id)) {
+                parameters.put("transaction_id", transaction_id);
+            }
             parameters.put("out_refund_no", out_refund_no);
             parameters.put("fee_type", "CNY");
             parameters.put("total_fee", total_fee);//鎬婚噾棰�

--
Gitblit v1.8.0