无关风月
2025-05-08 9486766c806fe1d9e082b2fd02ea1cc558f1b443
cloud-server-account/src/main/java/com/dsh/account/util/PayMoneyUtil.java
@@ -1,30 +1,46 @@
package com.dsh.account.util;
import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.CertAlipayRequest;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradeAppPayModel;
import com.alipay.api.domain.AlipayTradeQueryModel;
import com.alipay.api.domain.*;
import com.alipay.api.request.*;
import com.alipay.api.response.*;
import com.dsh.account.dto.Receivers;
import com.dsh.account.entity.OperatorUser;
import com.dsh.account.feignclient.competition.DeductionCompetitionsClient;
import com.dsh.account.feignclient.competition.model.PaymentCompetition;
import com.dsh.account.feignclient.course.CoursePackageClient;
import com.dsh.account.feignclient.course.model.TCoursePackagePayment;
import com.dsh.account.feignclient.other.SiteClient;
import com.dsh.account.feignclient.other.model.SiteBooking;
import com.dsh.account.mapper.RechargeRecordsMapper;
import com.dsh.account.util.httpClinet.HttpClientUtil;
//import com.github.binarywang.wxpay.bean.profitsharingV3.ProfitSharingReceiver;
//import com.github.binarywang.wxpay.bean.profitsharingV3.ProfitSharingRequest;
//import com.github.binarywang.wxpay.service.ProfitSharingV3Service;
//import com.github.binarywang.wxpay.service.WxPayService;
import org.apache.commons.collections.map.HashedMap;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.annotation.Resource;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
@@ -37,6 +53,8 @@
import java.security.NoSuchProviderException;
import java.security.Security;
import java.util.*;
import static com.dsh.account.util.akeylogin.Md5Util.byteArrayToHexString;
/**
 * 第三方支付工具类
@@ -51,15 +69,17 @@
    private String alipay_public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmu8n/4yTHWbn7VOrNc9OsLtDL1bEQ8gC1dHkj8Wy5z0mkaOsjJRIG/28ze12M0V8jdCKuuDr5Z1OPKiqf+XO3ypguEh+mYUVMBM/cZodDFQfTY1TKLWjvQCuaqlA+QUTCK6f7T7stsgyQ1o9Jj0rXZDz6PM4QHSTzjrLIBaeqM5WIBvH+fy/X+QG5Utd+/UT0kc0JyvuKhZ65yVUd/C9VcwJJAPliRsAQNrqYterwAJ9zvw9tF11wj9W0XgJ8Ccu4x3gR1vrlLRJJo/OA97RmxPQ+5hSacWQZCUd1dwiBq+YCrKVHGTj14izRHXrLc0yBlRXo7tBOIqcy3IsvKVthQIDAQAB";//支付宝支付公钥
    private String appid = "";//微信appid
    private String smid = "2088330203191220";//平台支付宝商户号...
    private String appletsAppid = "";//微信小程序appid
    private String appid = "wx41d32f362ba0f911";//微信appid
    private String mchId = "";//微信商户号
    private String appSecret = "cf0ebf950f5926a69041a0e2bbe20f3e";
    private String key = "";//微信商户号
    private String mchId = "1501481761";//微信商户号
    private String callbackPath = "";//支付回调网关地址
    private String key = "6f5e0c2dcabfa9c27b5da5836a362fef";//微信商户号
    private String callbackPath = "https://online.daowepark.com:443/account";//支付回调网关地址
    private String app_cert_path = "C:/cert/alipay/user/app_cert_path.crt";//应用公钥证书路径
@@ -67,14 +87,101 @@
    private String alipay_root_cert_path = "C:/cert/alipay/user/alipay_root_cert_path.crt";//支付宝CA根证书文件路径
    private String certPath = "C:\\cert\\1523106371_20211206_cert\\apiclient_cert.p12";//微信证书
    private String certPath = "/usr/playpai/cert/weixin/apiclient_cert.p12";//微信证书
//    public static void main(String[] args) {
//        Map<String, Object> body = new HashMap<>();
//        body.put("type", "MERCHANT_ID");
//        body.put("account", "1231232121");
//        body.put("amount", "asda");
//        body.put("description", "订单分账");
//        JSONObject jsonObject = new JSONObject(body);
//        JSONArray objects = new JSONArray();
//        objects.add(jsonObject);
//        System.err.println(objects);
//        System.err.println(objects.toJSONString());
//    }
    /**
     * 发起分账
     * @param order 微信订单号
     * @return
     */
    public ResultUtil fenzhang(String order,BigDecimal amount,String merchantNumber,String description) throws Exception {
        Map<String, Object> map = new HashMap<>();
        map.put("mch_id", mchId);
        map.put("appid", appid);
        String nonce_str = UUIDUtil.getRandomCode(16);
        String out_order_no = UUIDUtil.getRandomCode(16);
        map.put("out_order_no", out_order_no);
        map.put("nonce_str", nonce_str);
        map.put("transaction_id", order);
        // 将这个字符串使用json格式拼接起来
        Map<String, Object> body = new HashMap<>();
        body.put("type", "MERCHANT_ID");
        body.put("account", merchantNumber);
        int i = amount.multiply(new BigDecimal("100")).intValue();
        body.put("amount", i);
        body.put("description", description);
        JSONObject jsonObject = new JSONObject(body);
        JSONArray objects = new JSONArray();
        objects.add(jsonObject);
        map.put("receivers",objects.toJSONString());
        String s = this.weixinSignature1(map);
        map.put("sign", s);
        String url = "https://api.mch.weixin.qq.com/secapi/pay/profitsharing";
        //设置请求头
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_XML);
        StringBuffer xmlString = new StringBuffer();
        Set<String> strings = map.keySet();
        String[] keys = {};
        keys = strings.toArray(keys);
        Arrays.sort(keys);
        xmlString.append("<xml>");
        for (int l = 0; l < keys.length; l++) {
            xmlString.append("<" + keys[l] + ">" + map.get(keys[l]) + "</" + keys[l] + ">");
        }
        xmlString.append("</xml>");
        Map<String, String> map1 = null;
        String body1 = null;
        try {
            body1 = HttpClientUtil.pushHttpsRequsetXml1(url, xmlString.toString(), new HashMap<>(), mchId, certPath, "PKCS12");
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.err.println("分账请求"+body1);
        //将结果xml解析成map
        body1 = body1.replaceAll("<!\\[CDATA\\[", "");
        body1 = body1.replaceAll("]]>", "");
        try {
            map1 = this.xmlToMap(body1, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        String return_code = map1.get("return_code");
        if ("SUCCESS".equals(return_code)) {
            String result_code = map1.get("result_code");
            if ("SUCCESS".equals(result_code)) {
                return ResultUtil.success();
            } else {
//                System.err.println(map1.get("err_code_des"));
                return ResultUtil.error(map1.get("err_code_des"));
            }
        } else {
//            System.err.println(map1.get("return_msg") + appid + "----" + mchId);
            return ResultUtil.error(map1.get("return_msg"), new JSONObject());
        }
    }
    /**
     * 支付宝支付
     */
    public ResultUtil alipay(String body, String subject, String passbackParams, String outTradeNo, String amount, String notifyUrl){
    public ResultUtil  alipay(String smid,String body, String subject, String passbackParams, String outTradeNo, String amount, String notifyUrl) {
//        //构造client
//        CertAlipayRequest certAlipayRequest = new CertAlipayRequest ();
//        //设置网关地址
@@ -126,7 +233,6 @@
//            e.printStackTrace();
//        }
        //实例化客户端
        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", aliAppid, appPrivateKey, "json", "UTF-8", alipay_public_key, "RSA2");
        //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
@@ -140,6 +246,59 @@
        model.setTotalAmount(amount);//付款金额
        model.setProductCode("QUICK_MSECURITY_PAY");
        model.setPassbackParams(passbackParams);//自定义参数
        SettleInfo settleInfo = new SettleInfo();
        settleInfo.setSettlePeriodTime("3d");
        SettleDetailInfo settleDetailInfo = new SettleDetailInfo();
        settleDetailInfo.setTransInType("defaultSettle");
        settleDetailInfo.setAmount(amount);
        List<SettleDetailInfo> settleDetailInfos = new ArrayList<>();
        settleDetailInfos.add(settleDetailInfo);
        settleInfo.setSettleDetailInfos(settleDetailInfos);
        model.setSettleInfo(settleInfo);
        SubMerchant subMerchant = new SubMerchant();
        subMerchant.setMerchantId(smid);
        model.setSubMerchant(subMerchant);
        ExtendParams extendParams = new ExtendParams();
        extendParams.setRoyaltyFreeze("true");// 冻结资金 用于后续分账处理
        model.setExtendParams(extendParams);
        //分账
//        Integer    coursePackagePayments = coursePackageClient.queryByCode(outTradeNo);
//        Integer paymentCompetitions = competitionsClient.queryByCode(outTradeNo);
//        Integer siteBookings = siteClient.queryByCode(outTradeNo);
//        List<Integer> stores = new ArrayList<>();
//        stores.add(coursePackagePayments);
//        stores.add(paymentCompetitions);
//        stores.add(siteBookings);
//
//        OperatorUser operatorUser = siteClient.queryOperator(stores);
//
//        String alipayProportion = operatorUser.getAlipayProportion();
//        String alipayNum = operatorUser.getAlipayNum();
//
//        ExtendParams extendParams = new ExtendParams();
////        extendParams.setSysServiceProviderId("YOUR_SERVICE_PROVIDER_ID");
//        model.setExtendParams(extendParams);
//
//        RoyaltyInfo royaltyInfo = new RoyaltyInfo();
////        royaltyInfo.setRoyaltyType("transfer");
//
//
//        RoyaltyDetailInfos royaltyDetailInfo1 = new RoyaltyDetailInfos();
//        royaltyDetailInfo1.setTransOutType("userId");
//        royaltyDetailInfo1.setTransOut(aliAppid);
//        royaltyDetailInfo1.setTransInType("loginName");
//        royaltyDetailInfo1.setTransIn("18398968484");
//
//        royaltyDetailInfo1.setDesc("分账描述1");
//        royaltyDetailInfo1.setAmountPercentage(alipayProportion);
//        List<RoyaltyDetailInfos> royaltyDetailInfos = new ArrayList<>();
//
//
//
//        royaltyInfo.setRoyaltyDetailInfos(royaltyDetailInfos);
//        model.setRoyaltyInfo(royaltyInfo);
//        System.err.println("=================="+royaltyInfo);
        //
        request.setBizModel(model);
        request.setNotifyUrl(callbackPath + notifyUrl);
        try {
@@ -147,6 +306,7 @@
            AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
            Map<String, String> map = new HashMap<>();
            map.put("orderString", response.getBody());
            map.put("returnId", passbackParams);
            System.out.println(map);//就是orderString 可以直接给客户端请求,无需再做处理。
            return ResultUtil.success(map);
        } catch (AlipayApiException e) {
@@ -158,6 +318,7 @@
    /**
     * 支付宝扫码支付下单
     *
     * @param body
     * @param subject
     * @param outTradeNo
@@ -165,7 +326,7 @@
     * @param notifyUrl
     * @return
     */
    public ResultUtil aliScanCodePay(String body, String subject, String outTradeNo, String amount, String notifyUrl){
    public ResultUtil aliScanCodePay(String body, String subject, String outTradeNo, String amount, String notifyUrl) {
        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", aliAppid, appPrivateKey, "json", "UTF-8", alipay_public_key, "RSA2"); //获得初始化的AlipayClient
        AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest();//创建API对应的request类
        request.setBizContent("{" +
@@ -187,17 +348,98 @@
        System.err.print(alipay_trade_precreate_response.getString("qr_code"));
        return ResultUtil.success(alipay_trade_precreate_response.getString("qr_code"));
    }
    // 直付通模式 alipay.trade.settle.confirm(统一收单确认结算接口)
    public ResultUtil confirm(String smid1,String code, String outTradeNo, String amount) {
        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",
                aliAppid,
                appPrivateKey,
                "json",
                "GBK",
                alipay_public_key,
                "RSA2");
        AlipayTradeSettleConfirmRequest request = new AlipayTradeSettleConfirmRequest();
        request.setBizContent("{" +
                "  \"out_request_no\":\""+code+"\"," +
                "  \"trade_no\":\""+outTradeNo+"\"," +
                "  \"settle_info\":{" +
                "    \"settle_detail_infos\":[" +
                "      {" +
                "        \"trans_in_type\":\"defaultSettle\"," +
                "        \"settle_entity_id\":\""+smid1+"\"," +
                "        \"settle_entity_type\":\"SecondMerchant\"," +
                "        \"amount\":"+amount+"," +
                "      }" +
                "    ]" +
                "  }," +
                "  \"extend_params\":{" +
                "    \"royalty_freeze\":\"false\"" +
                "  }" +
                "}");
        AlipayTradeSettleConfirmResponse response = null;
        try {
            response = alipayClient.execute(request);
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
        if(response.isSuccess()){
            System.out.println("调用成功");
            return ResultUtil.success();
        } else {
            System.out.println("调用失败");
            return ResultUtil.error("出现问题啦");
        }
    }
    // 资金冻结 做分账处理
    public ResultUtil confirm1(String smid,String code, String outTradeNo, String amount) {
        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",
                aliAppid,
                appPrivateKey,
                "json",
                "GBK",
                alipay_public_key,
                "RSA2");
        AlipayTradeSettleConfirmRequest request = new AlipayTradeSettleConfirmRequest();
        request.setBizContent("{" +
                "  \"out_request_no\":\""+code+"\"," +
                "  \"trade_no\":\""+outTradeNo+"\"," +
                "  \"settle_info\":{" +
                "    \"settle_detail_infos\":[" +
                "      {" +
                "        \"trans_in_type\":\"defaultSettle\"," +
                "        \"settle_entity_id\":\""+smid+"\"," +
                "        \"settle_entity_type\":\"SecondMerchant\"," +
                "        \"amount\":"+amount+"," +
                "      }" +
                "    ]" +
                "  }," +
                "  \"extend_params\":{" +
                "    \"royalty_freeze\":\"true\"" +
                "  }" +
                "}");
        AlipayTradeSettleConfirmResponse response = null;
        try {
            response = alipayClient.execute(request);
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
        if(response.isSuccess()){
            System.out.println("调用成功");
            return ResultUtil.success();
        } else {
            System.out.println("调用失败");
            return ResultUtil.error("出现问题啦");
        }
    }
    /**
     * 支付成功后的回调处理逻辑
     *
     * @param request
     */
    public Map<String, String> alipayCallback(HttpServletRequest request){
    public Map<String, String> alipayCallback(HttpServletRequest request) {
        //获取支付宝POST过来反馈信息
        Map<String,String> params = new HashMap<String,String>();
        Map<String, String> params = new HashMap<String, String>();
        Map requestParams = request.getParameterMap();
        for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) {
        for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext(); ) {
            String name = (String) iter.next();
            String[] values = (String[]) requestParams.get(name);
            String valueStr = "";
@@ -237,54 +479,62 @@
        Map<String, String> map = new HashMap<>();
        String out_trade_no = params.get("out_trade_no");
        String subject = params.get("subject");
        String total_amount = params.get("total_amount");
        String trade_no = params.get("trade_no");
        String passback_params = params.get("passback_params");
        map.put("out_trade_no", out_trade_no);//商家订单号
        map.put("subject", subject);
        map.put("total_amount", total_amount);
        map.put("trade_no", trade_no);//支付宝交易号
        map.put("passback_params", passback_params);//回传参数
        return map;
        System.err.println("返回码"+params);
        if (params.get("trade_status").equals("TRADE_SUCCESS")){
            String out_trade_no = params.get("out_trade_no");
            String subject = params.get("subject");
            String total_amount = params.get("total_amount");
            String trade_no = params.get("trade_no");
            String passback_params = params.get("passback_params");
            map.put("out_trade_no", out_trade_no);//商家订单号
            map.put("subject", subject);
            map.put("total_amount", total_amount);
            map.put("trade_no", trade_no);//支付宝交易号
            map.put("passback_params", passback_params);//回传参数
            System.err.println("回调map");
            return map;
        }else{
            return null;
        }
    }
    /**
     * 支付宝查询订单支付状态
     *
     * @param out_trade_no
     * @return
     * @throws Exception
     */
    public ResultUtil queryALIOrder(String out_trade_no) throws Exception{
        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",aliAppid, appPrivateKey,"json","UTF-8",alipay_public_key,"RSA2");
    public AlipayTradeQueryResponse queryALIOrder(String out_trade_no) throws Exception {
        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", aliAppid, appPrivateKey, "json", "UTF-8", alipay_public_key, "RSA2");
        AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
        request.setBizContent("{" +
                "  \"out_trade_no\":\"" + out_trade_no + "\"" +
                "}");
        AlipayTradeQueryResponse response = alipayClient.execute(request);
        if(response.isSuccess()){
            String tradeStatus = response.getTradeStatus();//交易状态:WAIT_BUYER_PAY(交易创建,等待买家付款)、TRADE_CLOSED(未付款交易超时关闭,或支付完成后全额退款)、TRADE_SUCCESS(交易支付成功)、TRADE_FINISHED(交易结束,不可退款)
            return ResultUtil.success(tradeStatus);
        } else {
            return ResultUtil.error(response.getMsg());
        }
        return response;
//        if(response.isSuccess()){
//            String tradeStatus = response.getTradeStatus();//交易状态:WAIT_BUYER_PAY(交易创建,等待买家付款)、TRADE_CLOSED(未付款交易超时关闭,或支付完成后全额退款)、TRADE_SUCCESS(交易支付成功)、TRADE_FINISHED(交易结束,不可退款)
//            return ResultUtil.success(response);
//        } else {
//            return ResultUtil.error(response.getMsg());
//        }
    }
    /**
     * 微信统一下单
     * @param body          商品描述
     * @param attach        附加数据
     * @param out_trade_no  商户订单号
     * @param total_fee     标价金额
     * @param notify_url    通知地址
     * @param tradeType     交易类型
     *
     * @param body         商品描述
     * @param attach       附加数据
     * @param out_trade_no 商户订单号
     * @param total_fee    标价金额
     * @param notify_url   通知地址
     * @param tradeType    交易类型
     * @return
     */
    public ResultUtil weixinpay(String body, String attach, String out_trade_no, String total_fee, String notify_url, String tradeType, String openId) throws Exception{
    public ResultUtil weixinpay(String body, String attach, String out_trade_no, String total_fee, String notify_url, String tradeType, String openId) throws Exception {
        int i = new BigDecimal(total_fee).multiply(new BigDecimal("100")).intValue();
        String hostAddress = null;
        try {
@@ -294,17 +544,27 @@
        }
        String nonce_str = UUIDUtil.getRandomCode(16);
        Map<String, Object> map = new HashMap<>();
        map.put("appid", "APP".equals(tradeType) ? appid : appletsAppid);
        map.put("appid", appid);
        map.put("mch_id", mchId);
        map.put("nonce_str", nonce_str);
        map.put("body", body);
        String temp = "";
        if (body.split("-").length>1){
             temp = body.split("-")[1];
            map.put("body", body.split("-")[0]);
        }else{
            map.put("body", body);
        }
        if (StringUtils.hasLength(temp) && temp.equals("1")){
            // 添加分账标识
            map.put("profit_sharing", "Y");
        }
        map.put("attach", attach);//存储订单id
        map.put("out_trade_no", out_trade_no);//存储的订单code
        map.put("total_fee", i);
        map.put("spbill_create_ip", hostAddress);
        map.put("notify_url", callbackPath + notify_url);
        map.put("trade_type", tradeType);
        if("JSAPI".equals(tradeType)){
        if ("JSAPI".equals(tradeType)) {
            map.put("openid", openId);
        }
        String s = this.weixinSignature(map);
@@ -320,7 +580,7 @@
        keys = strings.toArray(keys);
        Arrays.sort(keys);
        xmlString.append("<xml>");
        for(int l = 0; l < keys.length; l++){
        for (int l = 0; l < keys.length; l++) {
            xmlString.append("<" + keys[l] + ">" + map.get(keys[l]) + "</" + keys[l] + ">");
        }
        xmlString.append("</xml>");
@@ -328,7 +588,7 @@
        Map<String, String> map1 = null;
        String body1 = HttpClientUtil.pushHttpRequsetXml(url, xmlString.toString(), new HashMap<>()).getData();
        //将结果xml解析成map
        body1 = body1.replaceAll("<!\\[CDATA\\[","");
        body1 = body1.replaceAll("<!\\[CDATA\\[", "");
        body1 = body1.replaceAll("]]>", "");
        try {
            map1 = this.xmlToMap(body1, "UTF-8");
@@ -338,12 +598,14 @@
            e.printStackTrace();
        }
        String return_code = map1.get("return_code");
        if("SUCCESS".equals(return_code)){
        if ("SUCCESS".equals(return_code)) {
            String result_code = map1.get("result_code");
            if("SUCCESS".equals(result_code)){
            if ("SUCCESS".equals(result_code)) {
                String type = map1.get("trade_type");
                String prepay_id = map1.get("prepay_id");
                switch (type){
                switch (type) {
                    case "JSAPI":
                        //重新进行签名后返回给前端
                        Map<String, Object> map2 = new HashMap<>();
@@ -378,34 +640,36 @@
                        return ResultUtil.success(map3);
                }
                return null;
            }else{
            } else {
                System.err.println(map1.get("err_code_des"));
                return ResultUtil.error(map1.get("err_code_des"));
            }
        }else{
        } else {
            System.err.println(map1.get("return_msg") + appid + "----" + mchId);
            return ResultUtil.error(map1.get("return_msg"), new JSONObject());
        }
    }
    @Resource
    private RechargeRecordsMapper rereMapper;
    /**
     * 微信支付成功后的回调处理
     *
     * @param request
     */
    public Map<String, String> weixinpayCallback(HttpServletRequest request){
    public Map<String, String> weixinpayCallback(HttpServletRequest request) {
        try {
            String param = this.getParam(request);
            param = param.replaceAll("<!\\[CDATA\\[","");
            param = param.replaceAll("<!\\[CDATA\\[", "");
            param = param.replaceAll("]]>", "");
            Map<String, String> map = this.xmlToMap(param, "UTF-8");
            String return_code = map.get("return_code");
            if("SUCCESS".equals(return_code)){
            if ("SUCCESS".equals(return_code)) {
                String result_code = map.get("result_code");
                if("SUCCESS".equals(result_code)){
                if ("SUCCESS".equals(result_code)) {
                    Map<String, String> map1 = new HashedMap();
                    map1.put("nonce_str", map.get("nonce_str"));
                    map1.put("out_trade_no", map.get("out_trade_no"));//存储的订单code
@@ -414,33 +678,146 @@
                    map1.put("transaction_id", map.get("transaction_id"));//微信支付订单号
                    String result = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
                    map1.put("result", result);
                    return map1;
                }else{
                } else {
                    System.err.println(map.get("err_code_des"));
                }
            }else{
            } else {
                System.err.println(map.get("return_msg"));
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return null;
    }
    @Resource
    private CoursePackageClient coursePackageClient;
    @Resource
    private DeductionCompetitionsClient competitionsClient;
    @Resource
    private SiteClient siteClient;
//    @Autowired
//    private WxPayService wxPayService;
    //分账
//    public ResultUtil order(String code) throws Exception {
//
//
//
//                  Integer    coursePackagePayments = coursePackageClient.queryByCode(code);
//                  Integer paymentCompetitions = competitionsClient.queryByCode(code);
//                  Integer siteBookings = siteClient.queryByCode(code);
//        List<Integer> stores = new ArrayList<>();
//                stores.add(coursePackagePayments);
//                stores.add(paymentCompetitions);
//                stores.add(siteBookings);
//
//                OperatorUser operatorUser = siteClient.queryOperator(stores);
//
//
////        WxPayService myWxPayService = wxPayService.switchoverTo("mch_id");
////
////        ProfitSharingV3Service profitSharingV3Service = myWxPayService.getProfitSharingV3Service();
//
//        String nonceStr = RandomUtil.randomString(32);
//        String appId = "您的appid";
//
//
//        //添加分账方
//
////        ProfitSharingReceiver profitSharingReceiver = new ProfitSharingReceiver();
////        profitSharingReceiver.setAccount("appid对应的openId");
////        profitSharingReceiver.setAmount(1l);
////        profitSharingReceiver.setAppid(appId);
////        profitSharingReceiver.setType("PERSONAL_OPENID");
////        profitSharingReceiver.setRelationType("PARTNER");
////        profitSharingV3Service.addProfitSharingReceiver(profitSharingReceiver);
//
//        //分账
//        ProfitSharingRequest profitSharingRequest = new ProfitSharingRequest();
//        profitSharingRequest.setAppid(appId);
//        profitSharingRequest.setTransactionId("微信支付订单号");
//        profitSharingRequest.setOutOrderNo("业务系统唯一编号");
//        //分账完成后,剩余金额自动解冻并返回给商户账号,默认false
//        profitSharingRequest.setUnfreezeUnsplit(true);
//        //待分账金额1元
//        Long money = 1L;
//        List<ProfitSharingReceiver> profitSharingReceivers = new ArrayList<>();
//        ProfitSharingReceiver profitSharingReceiver = new ProfitSharingReceiver();
//        profitSharingReceiver.setAccount("appid对应的openId,分账用户1");
//
//
//        //分账百分之5
//        profitSharingReceiver.setAmount(money * 100 / 5);
//        profitSharingReceiver.setAppid(appId);
//        profitSharingReceiver.setType("PERSONAL_OPENID");
//        profitSharingReceiver.setRelationType("PARTNER");
//        profitSharingReceiver.setDescription("test01");
//        profitSharingReceivers.add(profitSharingReceiver);
//
//        ProfitSharingReceiver receiver = new ProfitSharingReceiver();
//        receiver.setAccount("appid对应的openId,分账用户2");
//        //百分之10
//        receiver.setAmount(money * 100 / 10);
//        receiver.setAppid(appId);
//        receiver.setType("PERSONAL_OPENID");
//        receiver.setRelationType("PARTNER");
//        receiver.setDescription("test02");
//        profitSharingReceivers.add(receiver);
//
//
//        profitSharingRequest.setReceivers(profitSharingReceivers);
//
//        profitSharingV3Service.profitSharing(profitSharingRequest);
//
//
//
//
////                    Map<String,String> headers = new HashMap<>();
////                    headers.put("Authorization",map.get("sign"));
////                    headers.put("Accept","application/json");
////                    headers.put("Wechatpay-Serial",certPath);
////
////                    List<Receivers> receivers = new ArrayList<>();
////
////                    Map<String,Object> body = new HashMap<>();
////                    body.put("appid",appid);
////                    body.put("transaction_id",map.get("transaction_id"));
////                    body.put("out_order_no",map.get("out_trade_no"));
////                    body.put("receivers",receivers);
////                    body.put("unfreeze_unsplit",true);
//
//                    //支付分账
////                    String url ="https://api.mch.weixin.qq.com/v3/profitsharing/orders";
////                    CloseableHttpResponse closeableHttpResponse = HttpClientUtil.setPostHttpRequset(url, body, headers, "application/json");
////
//
//            return  null;
//
//
//
//
//    }
    /**
     * 微信扫码收款
     * @param body              商品描述
     * @param attach            附加数据
     * @param nonce_str         随机字符串
     * @param out_trade_no      商户订单号
     * @param total_fee         订单金额
     * @param auth_code         授权码   扫码支付授权码,设备读取用户微信中的条码或者二维码信息(注:用户付款码条形码规则:18位纯数字,以10、11、12、13、14、15开头)
     *
     * @param body         商品描述
     * @param attach       附加数据
     * @param nonce_str    随机字符串
     * @param out_trade_no 商户订单号
     * @param total_fee    订单金额
     * @param auth_code    授权码   扫码支付授权码,设备读取用户微信中的条码或者二维码信息(注:用户付款码条形码规则:18位纯数字,以10、11、12、13、14、15开头)
     * @return
     */
    public ResultUtil wxScanQRCodePay(String body, String attach, String nonce_str, String out_trade_no, String total_fee, String auth_code){
    public ResultUtil wxScanQRCodePay(String body, String attach, String nonce_str, String out_trade_no, String total_fee, String auth_code) {
        int i = new BigDecimal(total_fee).multiply(new BigDecimal("100")).intValue();
        String hostAddress = null;
        try {
@@ -478,7 +855,7 @@
        keys = strings.toArray(keys);
        Arrays.sort(keys);
        xmlString.append("<xml>");
        for(int l = 0; l < keys.length; l++){
        for (int l = 0; l < keys.length; l++) {
            xmlString.append("<" + keys[l] + ">" + map.get(keys[l]) + "</" + keys[l] + ">");
        }
        xmlString.append("</xml>");
@@ -491,7 +868,7 @@
            e.printStackTrace();
        }
        //将结果xml解析成map
        body1 = body1.replaceAll("<!\\[CDATA\\[","");
        body1 = body1.replaceAll("<!\\[CDATA\\[", "");
        body1 = body1.replaceAll("]]>", "");
        try {
            map1 = this.xmlToMap(body1, "UTF-8");
@@ -501,11 +878,11 @@
            e.printStackTrace();
        }
        String return_code = map1.get("return_code");
        if("SUCCESS".equals(return_code)){
        if ("SUCCESS".equals(return_code)) {
            String result_code = map1.get("result_code");
            if("SUCCESS".equals(result_code)){
            if ("SUCCESS".equals(result_code)) {
                String type = map1.get("trade_type");
                switch (type){
                switch (type) {
                    case "JSAPI":
                        break;
                    case "NATIVE":
@@ -529,11 +906,11 @@
                        return ResultUtil.success(map2);
                }
                return null;
            }else{
            } else {
//                System.err.println(map1.get("err_code_des"));
                return ResultUtil.error(map1.get("err_code_des"));
            }
        }else{
        } else {
//            System.err.println(map1.get("return_msg") + appid + "----" + mchId);
            return ResultUtil.error(map1.get("return_msg"), new JSONObject());
        }
@@ -542,24 +919,26 @@
    /**
     * 支付宝扫码收款
     *
     * @param data
     * @return
     */
    public Object aliScanQRCodePay(String data){
    public Object aliScanQRCodePay(String data) {
        return null;
    }
    /**
     * 微信退款申请
     * @param transaction_id    微信订单号。微信生成的订单号,在支付通知中有返回
     * @param out_refund_no     商户退款单号。商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|*@ ,同一退款单号多次请求只退一笔。
     * @param total_fee         订单金额。订单总金额,单位为分,只能为整数
     * @param refund_fee        退款金额。退款总金额,订单总金额,单位为分,只能为整数
     * @param notify_url        退款结果通知url。异步接收微信支付退款结果通知的回调地址,通知URL必须为外网可访问的url,不允许带参数 如果参数中传了notify_url,则商户平台上配置的回调地址将不会生效。
     *
     * @param transaction_id 微信订单号。微信生成的订单号,在支付通知中有返回
     * @param out_refund_no  商户退款单号。商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|*@ ,同一退款单号多次请求只退一笔。
     * @param total_fee      订单金额。订单总金额,单位为分,只能为整数
     * @param refund_fee     退款金额。退款总金额,订单总金额,单位为分,只能为整数
     * @param notify_url     退款结果通知url。异步接收微信支付退款结果通知的回调地址,通知URL必须为外网可访问的url,不允许带参数 如果参数中传了notify_url,则商户平台上配置的回调地址将不会生效。
     * @return
     */
    public Map<String, String> wxRefund(String transaction_id, String out_refund_no, String total_fee, String refund_fee, String notify_url){
    public Map<String, String> wxRefund(String transaction_id, String out_refund_no, String total_fee, String refund_fee, String notify_url) {
        int tf = new BigDecimal(total_fee).multiply(new BigDecimal("100")).intValue();
        int rf = new BigDecimal(refund_fee).multiply(new BigDecimal("100")).intValue();
        String nonce_str = UUIDUtil.getRandomCode();
@@ -585,7 +964,7 @@
        keys = strings.toArray(keys);
        Arrays.sort(keys);
        xmlString.append("<xml>");
        for(int l = 0; l < keys.length; l++){
        for (int l = 0; l < keys.length; l++) {
            xmlString.append("<" + keys[l] + ">" + map.get(keys[l]) + "</" + keys[l] + ">");
        }
        xmlString.append("</xml>");
@@ -599,7 +978,7 @@
        }
        System.err.println(body1);
        //将结果xml解析成map
        body1 = body1.replaceAll("<!\\[CDATA\\[","");
        body1 = body1.replaceAll("<!\\[CDATA\\[", "");
        body1 = body1.replaceAll("]]>", "");
        try {
            map1 = this.xmlToMap(body1, "UTF-8");
@@ -610,19 +989,19 @@
        }
        String return_code = map1.get("return_code");
        Map<String, String> map2 = new HashMap<>();
        if("SUCCESS".equals(return_code)){
        if ("SUCCESS".equals(return_code)) {
            String result_code = map1.get("result_code");
            if("SUCCESS".equals(result_code)){
            if ("SUCCESS".equals(result_code)) {
                map2.put("return_code", result_code);
                map2.put("refund_id", String.valueOf(map1.get("refund_id")));//微信退款订单号
                map2.put("refund_fee", String.valueOf(map1.get("refund_fee")));//退款金额
                return map2;
            }else{
            } else {
                map2.put("return_code", result_code);
                map2.put("return_msg", map1.get("err_code_des"));
                return map2;
            }
        }else{
        } else {
            map2.put("return_code", return_code);
            map2.put("return_msg", map1.get("return_msg"));
            return map2;
@@ -632,20 +1011,21 @@
    /**
     * 微信退款成功后的回调处理
     *
     * @param request
     * @return
     */
    public Map<String, String> wxRefundCallback(HttpServletRequest request){
    public Map<String, String> wxRefundCallback(HttpServletRequest request) {
        try {
            String param = this.getParam(request);
            param = param.replaceAll("<!\\[CDATA\\[","");
            param = param.replaceAll("<!\\[CDATA\\[", "");
            param = param.replaceAll("]]>", "");
            Map<String, String> map = this.xmlToMap(param, "UTF-8");
            String return_code = map.get("return_code");
            if("SUCCESS".equals(return_code)){
            if ("SUCCESS".equals(return_code)) {
                String req_info = map.get("req_info");//加密信息请用商户秘钥进行解密
                String s = this.wxDecrypt(req_info);
                s = s.replaceAll("<!\\[CDATA\\[","");
                s = s.replaceAll("<!\\[CDATA\\[", "");
                s = s.replaceAll("]]>", "");
                map = this.xmlToMap(s, "UTF-8");
                Map<String, String> map1 = new HashMap<>();
@@ -654,7 +1034,7 @@
                String result = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
                map1.put("result", result);
                return map1;
            }else{
            } else {
//                System.err.println(map.get("return_msg"));
            }
        } catch (IOException e) {
@@ -680,13 +1060,14 @@
    /**
     * 支付宝退款
     * @param trade_no          支付宝交易号
     * @param refund_amount     退款金额
     *
     * @param trade_no      支付宝交易号
     * @param refund_amount 退款金额
     * @return
     * @throws AlipayApiException
     */
    public Map<String, String> aliRefund(String trade_no, String refund_amount) throws AlipayApiException {
        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", aliAppid, appPrivateKey,"json","UTF-8", alipay_public_key,"RSA2");
        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", aliAppid, appPrivateKey, "json", "UTF-8", alipay_public_key, "RSA2");
        AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("trade_no", trade_no);
@@ -694,7 +1075,7 @@
        request.setBizContent(jsonObject.toJSONString());
        AlipayTradeRefundResponse response = alipayClient.execute(request);
        Map<String, String> map = new HashMap<>();
        if(response.isSuccess()){
        if (response.isSuccess()) {
            System.out.println("调用成功");
            String outTradeNo = response.getOutTradeNo();
            map.put("code", response.getCode());//10000
@@ -711,10 +1092,11 @@
    /**
     * 查询微信支付订单
     *
     * @return
     * @throws Exception
     */
    public ResultUtil<Map<String, String>> queryWXOrder(String out_trade_no, String transaction_id) throws Exception{
    public ResultUtil<Map<String, String>> queryWXOrder(String out_trade_no, String transaction_id) throws Exception {
        String url = "https://api.mch.weixin.qq.com/pay/orderquery";
        String nonce_str = UUIDUtil.getRandomCode(16);
        Map<String, Object> map = new HashMap<>();
@@ -735,7 +1117,7 @@
        keys = strings.toArray(keys);
        Arrays.sort(keys);
        xmlString.append("<xml>");
        for(int l = 0; l < keys.length; l++){
        for (int l = 0; l < keys.length; l++) {
            xmlString.append("<" + keys[l] + ">" + map.get(keys[l]) + "</" + keys[l] + ">");
        }
        xmlString.append("</xml>");
@@ -743,7 +1125,7 @@
        Map<String, String> map1 = null;
        String body1 = HttpClientUtil.pushHttpRequsetXml(url, xmlString.toString(), new HashMap<>()).getData();
        //将结果xml解析成map
        body1 = body1.replaceAll("<!\\[CDATA\\[","");
        body1 = body1.replaceAll("<!\\[CDATA\\[", "");
        body1 = body1.replaceAll("]]>", "");
        try {
            map1 = this.xmlToMap(body1, "UTF-8");
@@ -753,35 +1135,35 @@
            e.printStackTrace();
        }
        String return_code = map1.get("return_code");
        if("SUCCESS".equals(return_code)){
        if ("SUCCESS".equals(return_code)) {
            String result_code = map1.get("result_code");
            if("SUCCESS".equals(result_code)){
            if ("SUCCESS".equals(result_code)) {
                Map<String, String> map2 = new HashMap<>();
                map2.put("trade_type", map1.get("trade_type"));
                map2.put("trade_state", map1.get("trade_state"));//订单状态SUCCESS—支付成功,REFUND—转入退款,NOTPAY—未支付,CLOSED—已关闭,REVOKED—已撤销(刷卡支付),USERPAYING--用户支付中,PAYERROR--支付失败(其他原因,如银行返回失败)
                map2.put("transaction_id", map1.get("transaction_id"));
                return ResultUtil.success(map2);
            }else{
            } else {
                System.err.println(map1.get("err_code_des"));
                return ResultUtil.error(map1.get("err_code_des"));
            }
        }else{
        } else {
            System.err.println(map1.get("return_msg") + appid + "----" + mchId);
            return ResultUtil.error(map1.get("return_msg"));
        }
    }
    /**
     * 微信转账功能(企业付款到零钱)
     * @param openid                商户appid下,某用户的openid
     * @param desc                  企业付款备注,必填。
     * @param total_fee             企业付款金额
     * @param partner_trade_no      商户订单号,需保持唯一性
     *
     * @param openid           商户appid下,某用户的openid
     * @param desc             企业付款备注,必填。
     * @param total_fee        企业付款金额
     * @param partner_trade_no 商户订单号,需保持唯一性
     * @return
     */
    public Map<String, String> wxTransfers(String openid, String desc, String total_fee, String partner_trade_no) throws Exception{
    public Map<String, String> wxTransfers(String openid, String desc, String total_fee, String partner_trade_no) throws Exception {
        int amount = new BigDecimal(total_fee).multiply(new BigDecimal("100")).intValue();
        String nonce_str = UUIDUtil.getRandomCode();
        Map<String, Object> map = new HashMap<>();
@@ -806,7 +1188,7 @@
        keys = strings.toArray(keys);
        Arrays.sort(keys);
        xmlString.append("<xml>");
        for(int l = 0; l < keys.length; l++){
        for (int l = 0; l < keys.length; l++) {
            xmlString.append("<" + keys[l] + ">" + map.get(keys[l]) + "</" + keys[l] + ">");
        }
        xmlString.append("</xml>");
@@ -814,7 +1196,7 @@
        Map<String, String> map1 = null;
        String body1 = HttpClientUtil.pushHttpsRequsetXml(url, xmlString.toString(), new HashMap<>(), mchId, certPath, "PKCS12");
        //将结果xml解析成map
        body1 = body1.replaceAll("<!\\[CDATA\\[","");
        body1 = body1.replaceAll("<!\\[CDATA\\[", "");
        body1 = body1.replaceAll("]]>", "");
        try {
            map1 = this.xmlToMap(body1, "UTF-8");
@@ -825,20 +1207,20 @@
        }
        String return_code = map1.get("return_code");
        Map<String, String> map2 = new HashMap<>();
        if("SUCCESS".equals(return_code)){
        if ("SUCCESS".equals(return_code)) {
            String result_code = map1.get("result_code");
            if("SUCCESS".equals(result_code)){
            if ("SUCCESS".equals(result_code)) {
                map2.put("return_code", result_code);
                map2.put("payment_no", String.valueOf(map1.get("payment_no")));//付款订单号
                map2.put("payment_time", String.valueOf(map1.get("payment_time")));//付款时间
                return map2;
            }else{
            } else {
                map2.put("return_code", result_code);
                map2.put("err_code", map1.get("err_code"));
                map2.put("err_code_des", map1.get("err_code_des"));
                return map2;
            }
        }else{
        } else {
            map2.put("return_code", return_code);
            map2.put("return_msg", map1.get("return_msg"));
            return map2;
@@ -848,16 +1230,17 @@
    /**
     * 微信转账功能(企业付款到银行卡)
     * @param desc              备注信息
     * @param total_fee         转账金额
     * @param partner_trade_no  订单号
     * @param enc_bank_no       银行卡号
     * @param enc_true_name     收款方用户名
     * @param bankName          银行名称
     *
     * @param desc             备注信息
     * @param total_fee        转账金额
     * @param partner_trade_no 订单号
     * @param enc_bank_no      银行卡号
     * @param enc_true_name    收款方用户名
     * @param bankName         银行名称
     * @return
     * @throws Exception
     */
    public Map<String, String> wxPayBank(String desc, String total_fee, String partner_trade_no, String enc_bank_no, String enc_true_name, String bankName) throws Exception{
    public Map<String, String> wxPayBank(String desc, String total_fee, String partner_trade_no, String enc_bank_no, String enc_true_name, String bankName) throws Exception {
        int amount = new BigDecimal(total_fee).multiply(new BigDecimal("100")).intValue();
        String nonce_str = UUIDUtil.getRandomCode();
        Map<String, Object> map = new HashMap<>();
@@ -882,7 +1265,7 @@
        keys = strings.toArray(keys);
        Arrays.sort(keys);
        xmlString.append("<xml>");
        for(int l = 0; l < keys.length; l++){
        for (int l = 0; l < keys.length; l++) {
            xmlString.append("<" + keys[l] + ">" + map.get(keys[l]) + "</" + keys[l] + ">");
        }
        xmlString.append("</xml>");
@@ -890,7 +1273,7 @@
        Map<String, String> map1 = null;
        String body1 = HttpClientUtil.pushHttpsRequsetXml(url, xmlString.toString(), new HashMap<>(), mchId, certPath, "PKCS12");
        //将结果xml解析成map
        body1 = body1.replaceAll("<!\\[CDATA\\[","");
        body1 = body1.replaceAll("<!\\[CDATA\\[", "");
        body1 = body1.replaceAll("]]>", "");
        try {
            map1 = this.xmlToMap(body1, "UTF-8");
@@ -901,20 +1284,20 @@
        }
        String return_code = map1.get("return_code");
        Map<String, String> map2 = new HashMap<>();
        if("SUCCESS".equals(return_code)){
        if ("SUCCESS".equals(return_code)) {
            String result_code = map1.get("result_code");
            if("SUCCESS".equals(result_code)){
            if ("SUCCESS".equals(result_code)) {
                map2.put("return_code", result_code);
                map2.put("payment_no", String.valueOf(map1.get("payment_no")));//付款订单号
                map2.put("cmms_amt", String.valueOf(map1.get("cmms_amt")));//手续费金额 RMB:分
                return map2;
            }else{
            } else {
                map2.put("return_code", result_code);
                map2.put("err_code", map1.get("err_code"));
                map2.put("err_code_des", map1.get("err_code_des"));
                return map2;
            }
        }else{
        } else {
            map2.put("return_code", return_code);
            map2.put("return_msg", map1.get("return_msg"));
            return map2;
@@ -923,15 +1306,16 @@
    /**
     * 微信转账到银行卡不编号
     *
     * @param bankName
     * @return
     */
    public String findBankCode(String bankName){
    public String findBankCode(String bankName) {
        String json = "{\"工商银行 \":1002,\"农业银行\":1005,\"建设银行\":1003,\"中国银行\":1026,\"交通银行 \":1020,\"招商银行 \":1001,\"邮储银行\":1066,\"民生银行 \":1006,\"平安银行 \":1010,\"中信银行\":1021,\"浦发银行 \":1004,\"兴业银行 \":1009,\"光大银行 \":1022,\"广发银行\":1027,\"华夏银行\":1025,\"宁波银行\":1056,\"北京银行\":4836,\"上海银行\":1024,\"南京银行\":1054,\"长子县融汇村镇银行\":4755,\"长沙银行\":4216,\"浙江泰隆商业银行\":4051,\"中原银行 \":4753,\"企业银行(中国)\":4761,\"顺德农商银行 \":4036,\"衡水银行\":4752,\"长治银行\":4756,\"大同银行\":4767,\"河南省农村信用社\":4115,\"宁夏黄河农村商业银行\":4150,\"山西省农村信用社\":4156,\"安徽省农村信用社\":4166,\"甘肃省农村信用社\":4157,\"天津农村商业银行\":4153,\"广西壮族自治区农村信用社\":4113,\"陕西省农村信用社\":4108,\"深圳农村商业银行\":4076,\"宁波鄞州农村商业银行\":4052,\"浙江省农村信用社联合社\":4764,\"江苏省农村信用社联合社\":4217,\"江苏紫金农村商业银行股份有限公司 \":4072,\"北京中关村银行股份有限公司 \":4769,\"星展银行( 中国) 有限公司 \":4778,\"枣庄银行股份有限公司 \":4766,\"海口联合农村商业银行股份有限公司 \":4758,\"南洋商业银行( 中国) 有限公司 \":4763}";
        JSONObject jsonObject = JSON.parseObject(json);
        Set<String> strings = jsonObject.keySet();
        for(String key : strings){
            if(key.indexOf(bankName) >= 0){
        for (String key : strings) {
            if (key.indexOf(bankName) >= 0) {
                return jsonObject.getString(key);
            }
        }
@@ -939,19 +1323,19 @@
    }
    /**
     * 支付宝转账
     * @param out_biz_no        商家侧唯一订单号,由商家自定义。对于不同转账请求,商家需保证该订单号在自身系统唯一。
     * @param trans_amount      订单总金额,单位为元,精确到小数点后两位
     * @param order_title       转账业务的标题,用于在支付宝用户的账单里显示
     * @param identity          参与方的唯一标识(收款方支付宝账号)
     * @param name              参与方真实姓名,如果非空,将校验收款支付宝账号姓名一致性。
     * @param remark            业务备注
     *
     * @param out_biz_no   商家侧唯一订单号,由商家自定义。对于不同转账请求,商家需保证该订单号在自身系统唯一。
     * @param trans_amount 订单总金额,单位为元,精确到小数点后两位
     * @param order_title  转账业务的标题,用于在支付宝用户的账单里显示
     * @param identity     参与方的唯一标识(收款方支付宝账号)
     * @param name         参与方真实姓名,如果非空,将校验收款支付宝账号姓名一致性。
     * @param remark       业务备注
     * @return
     * @throws Exception
     */
    public Map<String, Object> aliTransfer(String out_biz_no, Double trans_amount, String order_title, String identity, String name, String remark) throws Exception{
    public Map<String, Object> aliTransfer(String out_biz_no, Double trans_amount, String order_title, String identity, String name, String remark) throws Exception {
        CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
        certAlipayRequest.setServerUrl("https://openapi.alipay.com/gateway.do");  //gateway:支付宝网关(固定)https://openapi.alipay.com/gateway.do
        certAlipayRequest.setAppId(aliAppid);  //APPID 即创建应用后生成,详情见创建应用并获取 APPID
@@ -979,13 +1363,13 @@
                "}");
        AlipayFundTransUniTransferResponse response = alipayClient.certificateExecute(request);
        Map<String, Object> map = new HashMap<>();
        if(response.isSuccess()){
        if (response.isSuccess()) {
            String status = response.getStatus();
            if(status.equals("SUCCESS")){//成功
            if (status.equals("SUCCESS")) {//成功
                map.put("code", response.getCode());
                map.put("order_id", response.getOrderId());//支付宝订单号
                map.put("pay_fund_order_id", response.getPayFundOrderId());//支付宝流水号
            }else{
            } else {
                map.put("code", response.getCode());
                map.put("sub_msg", response.getSubMsg());
            }
@@ -999,6 +1383,7 @@
    /**
     * 获取请求内容
     *
     * @param request
     * @return
     * @throws IOException
@@ -1021,10 +1406,11 @@
    /**
     * 微信下单的签名算法
     *
     * @param map
     * @return
     */
    private String weixinSignature(Map<String, Object> map){
    private String weixinSignature(Map<String, Object> map) {
        try {
            Set<Map.Entry<String, Object>> entries = map.entrySet();
            List<Map.Entry<String, Object>> infoIds = new ArrayList<Map.Entry<String, Object>>(entries);
@@ -1057,10 +1443,11 @@
    /**
     * 微信下单的签名算法
     *
     * @param map
     * @return
     */
    private String weixinSignature(Map<String, Object> map, String key_){
    private String weixinSignature(Map<String, Object> map, String key_) {
        try {
            Set<Map.Entry<String, Object>> entries = map.entrySet();
            List<Map.Entry<String, Object>> infoIds = new ArrayList<Map.Entry<String, Object>>(entries);
@@ -1089,10 +1476,58 @@
        }
        return null;
    }
    private String weixinSignature1(Map<String, Object> map) {
        try {
            Set<Map.Entry<String, Object>> entries = map.entrySet();
            List<Map.Entry<String, Object>> infoIds = new ArrayList<Map.Entry<String, Object>>(entries);
            // 对所有传入参数按照字段名的 ASCII 码从小到大排序(字典序)
            Collections.sort(infoIds, new Comparator<Map.Entry<String, Object>>() {
                public int compare(Map.Entry<String, Object> o1, Map.Entry<String, Object> o2) {
                    return (o1.getKey()).toString().compareTo(o2.getKey());
                }
            });
            // 构造签名键值对的格式
            StringBuilder sb = new StringBuilder();
            for (Map.Entry<String, Object> item : infoIds) {
                if (item.getKey() != null || item.getKey() != "") {
                    String key = item.getKey();
                    Object val = item.getValue();
                    if (!(val == "" || val == null)) {
                        sb.append(key + "=" + val + "&");
                    }
                }
            }
            sb.append("key=" + key);
            String sign = sha256_HMAC(sb.toString(), key).toUpperCase();
            return sign;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
     * sha256_HMAC加密
     * @param message 消息
     * @param secret  秘钥
     * @return 加密后字符串
     */
    public  String sha256_HMAC(String message, String secret) {
        String hash = "";
        try {
            Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
            SecretKeySpec secret_key = new SecretKeySpec(secret.getBytes(), "HmacSHA256");
            sha256_HMAC.init(secret_key);
            byte[] bytes = sha256_HMAC.doFinal(message.getBytes());
            hash = byteArrayToHexString(bytes);
        } catch (Exception e) {
            System.out.println("Error HmacSHA256 ===========" + e.getMessage());
        }
        return hash;
    }
    /**
     * 微信退款成功后的解密
     *
     * @param req_info
     * @return
     */
@@ -1100,7 +1535,7 @@
            InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
        byte[] decode = Base64.getDecoder().decode(req_info);
        String sign = MD5AndKL.MD5Encode(key, "UTF-8").toLowerCase();
        if (Security.getProvider("BC") == null){
        if (Security.getProvider("BC") == null) {
            Security.addProvider(new BouncyCastleProvider());
        }
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding", "BC");
@@ -1110,22 +1545,23 @@
    }
    public static void main(String[] ages){
        PayMoneyUtil payMoneyUtil = new PayMoneyUtil();
        ResultUtil ce = payMoneyUtil.alipay("测试", "测试", "", "121456457", "10", "http://123.com");
        System.err.println(ce);
        ResultUtil resultUtil = null;
        try {
            resultUtil = payMoneyUtil.queryALIOrder("121456457");
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.err.println(resultUtil);
    }
//    public static void main(String[] ages){
//        PayMoneyUtil payMoneyUtil = new PayMoneyUtil();
//        ResultUtil ce = payMoneyUtil.alipay("测试", "测试", "", "121456457", "10", "http://123.com");
//        System.err.println(ce);
//        ResultUtil resultUtil = null;
//        try {
//            resultUtil = payMoneyUtil.queryALIOrder("121456457");
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        System.err.println(resultUtil);
//    }
    /**
     * xml转map
     *
     * @param xml
     * @param charset
     * @return
@@ -1143,7 +1579,7 @@
        return respMap;
    }
    public static Map<String, String> xmlToMap(Element tmpElement, Map<String, String> respMap){
    public static Map<String, String> xmlToMap(Element tmpElement, Map<String, String> respMap) {
        if (tmpElement.isTextOnly()) {
            respMap.put(tmpElement.getName(), tmpElement.getText());
            return respMap;