admin
2019-11-05 bc3a51600e5b950b8042e13c2fc5e4aa943ffc29
utils/src/main/java/org/yeshi/utils/wx/WXPayUtil.java
@@ -1,6 +1,7 @@
package org.yeshi.utils.wx;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
@@ -200,7 +201,11 @@
      String entity = WXUtil.loadWXMessage(map);
      String result = HttpUtil.post("https://api.mch.weixin.qq.com/pay/unifiedorder", entity);
      System.out.println("统一下单结果:" + result);
      try {
         System.out.println("统一下单结果:" + new String( result.getBytes("GBK"),"UTF-8"));
      } catch (UnsupportedEncodingException e) {
         e.printStackTrace();
      }
      Map<String, String> resultMap = WXUtil.parseXML(result);
      return resultMap;
@@ -274,4 +279,32 @@
      }
   }
   /**
    *
    * @param refundOrderNo -退款单号
    * @param app
    * @return
    * @throws WXOrderException
    */
   public static boolean isRefundSuccess(String refundOrderNo, WXAPPInfo app)  throws WXOrderException {
      Map<String, String> map = new HashMap<String, String>();
      map.put("appid", app.getAppId());
      map.put("mch_id", app.getMchId());
      map.put("nonce_str", StringUtil.getRandomCode(32));
      map.put("out_refund_no", refundOrderNo);
      map.put("sign", WXUtil.getSignMD5(map, app.getMchKey()));
      String result = HttpUtil.post("https://api.mch.weixin.qq.com/pay/refundquery", WXUtil.loadWXMessage(map));
      System.out.println("订单查询结果:" + result);
      Map<String, String> resultMap = WXUtil.parseXML(result);
      if ("SUCCESS".equalsIgnoreCase(resultMap.get("return_code"))
            && "SUCCESS".equalsIgnoreCase(resultMap.get("result_code"))) {
         if ("SUCCESS".equalsIgnoreCase(resultMap.get("refund_status_0")))// 退款成功
            return true;
         else
            return false;
      } else {
         throw new WXOrderException(100, "微信支付接口出错:" + result);
      }
   }
}