From d1eb76ad5d3095c6495bdc831adb2d2a546b97cb Mon Sep 17 00:00:00 2001 From: E1ED922C1E9526DD63272D7EC5C6CB77 <E1ED922C1E9526DD63272D7EC5C6CB77@i-search.com.cn> Date: 星期二, 29 十二月 2020 14:21:12 +0800 Subject: [PATCH] Merge branch 'master' of https://gitee.com/huoxiong/hx_common --- src/main/java/com/hx/mp/util/WXPayUtil.java | 60 ++++++++++++++++++++++++++++++++++++++---------------------- 1 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/hx/mp/util/WXPayUtil.java b/src/main/java/com/hx/mp/util/WXPayUtil.java index 8a3eb50..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; @@ -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銆乺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