zhibing.pu
2024-07-25 b92c83c58222a82184b525178405dcc8ea8c21fd
UserZYTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PayMoneyUtil.java
@@ -775,24 +775,25 @@
        }
        return null;
    }
    /**
     * 查询微信支付订单
     * @return
     * @throws Exception
     */
    public ResultUtil queryWXOrder() throws Exception{
    public ResultUtil<Map<String, Object>> queryWXOrder(String transaction_id, String out_trade_no, String tradeType) throws Exception{
        String url = "https://api.mch.weixin.qq.com/pay/orderquery";
        String nonce_str = UUIDUtil.getRandomCode(16);
        Map<String, Object> map = new HashMap<>();
        map.put("appid", appid);
        map.put("appid", "APP".equals(tradeType) ? appid : appletsAppid);
        map.put("mch_id", mchId);
        map.put("transaction_id", nonce_str);//微信订单号
        map.put("transaction_id", transaction_id);//微信订单号
        map.put("out_trade_no", out_trade_no);//商户订单号
        map.put("nonce_str", nonce_str);//随机字符串
        String s = this.weixinSignature(map);
        map.put("sign", s);
        //设置请求头
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_XML);
@@ -806,9 +807,10 @@
            xmlString.append("<" + keys[l] + ">" + map.get(keys[l]) + "</" + keys[l] + ">");
        }
        xmlString.append("</xml>");
        Map<String, String> map1 = null;
        String body1 = httpClientUtil.pushHttpRequsetXml(url, xmlString.toString(), new HashMap<>()).getData();
        HttpResult httpResult = httpClientUtil.pushHttpRequsetXml(url, xmlString.toString(), new HashMap<>());
        String body1 = httpResult.getData();
        //将结果xml解析成map
        body1 = body1.replaceAll("<!\\[CDATA\\[","");
        body1 = body1.replaceAll("]]>", "");
@@ -824,21 +826,20 @@
            String result_code = map1.get("result_code");
            if("SUCCESS".equals(result_code)){
                String type = map1.get("trade_type");
                switch (type){
                    case "JSAPI":
                        break;
                    case "NATIVE":
                        String code_url = map1.get("code_url");
                        return ResultUtil.success(code_url);
                    case "APP":
                        String trade_state = map1.get("trade_state");
                        String time_end = map1.get("time_end");
                        Map<String, Object> map2 = new HashMap<>();
                        map2.put("trade_state", trade_state);//订单状态SUCCESS—支付成功,REFUND—转入退款,NOTPAY—未支付,CLOSED—已关闭,REVOKED—已撤销(刷卡支付),USERPAYING--用户支付中,PAYERROR--支付失败(其他原因,如银行返回失败)
                        map2.put("time_end", time_end);//订单支付时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。
                        return ResultUtil.success(map2);
                }
                return null;
                Map<String, Object> map2 = new HashMap<>();
                String trade_state = map1.get("trade_state");
                String time_end = map1.get("time_end");
                String transactionId = map1.get("transaction_id");
                map2.put("result_code", result_code);
                map2.put("trade_state", trade_state);//订单状态SUCCESS—支付成功,REFUND—转入退款,NOTPAY—未支付,CLOSED—已关闭,REVOKED—已撤销(刷卡支付),USERPAYING--用户支付中,PAYERROR--支付失败(其他原因,如银行返回失败)
                map2.put("time_end", time_end);//订单支付时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。
                map2.put("transaction_id", transactionId);
                return ResultUtil.success(map2);
            }
            if("FAIL".equals(result_code)){//订单不存在
                Map<String, Object> map2 = new HashMap<>();
                map2.put("result_code", result_code);
                return ResultUtil.success(map2);
            }else{
                System.err.println(map1.get("err_code_des"));
                return ResultUtil.error(map1.get("err_code_des"));