E1ED922C1E9526DD63272D7EC5C6CB77
2021-01-20 a1dba41efa841aef8fb9f2bf2a179095ef77a9cd
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;
@@ -317,41 +319,51 @@
            CloseableHttpClient httpclient = HttpClients.custom()
                     .setSSLSocketFactory(sslsf).build();  
             HttpPost httppost = new HttpPost(REFUND_URL);
             String xml = wxPayRefundData(appId,partner,key,out_trade_no, transaction_id, total_fee, out_refund_no, refund_fee);
             try {
             String xml = wxPayRefundData(appId, partner, key, out_trade_no, transaction_id, out_refund_no, total_fee, refund_fee);
             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、retmsg看失败详情。
                                 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、retmsg看失败详情。
                            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);//总金额