E1ED922C1E9526DD63272D7EC5C6CB77
2020-10-10 58a62d1c1bb97080e855f404e5529dd96766640b
修改退款
1个文件已修改
56 ■■■■■ 已修改文件
src/main/java/com/hx/mp/util/WXPayUtil.java 56 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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、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);//总金额