无关风月
20 小时以前 5dc40fcd64b0513150f1d8335ab849e6d8cdc28e
cloud-server-competition/src/main/java/com/dsh/competition/util/PayMoneyUtil.java
@@ -11,6 +11,10 @@
import com.alipay.api.request.*;
import com.alipay.api.response.*;
import com.dsh.competition.util.httpClinet.HttpClientUtil;
import com.dsh.competition.util.wx.PartnerAppPrepay;
import com.dsh.competition.util.wx.WXPayUtility;
import com.dsh.competition.util.wx.WeChatV3SignUtil;
import com.dsh.competition.util.wx.WxV3PayConfig;
import org.apache.commons.collections.map.HashedMap;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.dom4j.Document;
@@ -150,9 +154,7 @@
        SubMerchant subMerchant = new SubMerchant();
        subMerchant.setMerchantId(smid);
        model.setSubMerchant(subMerchant);
        ExtendParams extendParams = new ExtendParams();
        extendParams.setRoyaltyFreeze("true");// 冻结资金 用于后续分账处理
        model.setExtendParams(extendParams);
        request.setBizModel(model);
        request.setNotifyUrl(callbackPath + notifyUrl);
@@ -409,17 +411,11 @@
        map.put("appid", appid);
        map.put("mch_id", mchId);
        map.put("nonce_str", nonce_str);
        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);
@@ -510,6 +506,62 @@
            return ResultUtil.error(map1.get("return_msg"), new JSONObject());
        }
    }
    public ResultUtil weixinpayV3(String subMchid,String description, String outTradeNo, String notifyUrl, String totalFee) throws Exception {
        int i = new BigDecimal(totalFee).multiply(new BigDecimal("100")).intValue();
        // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340
        PartnerAppPrepay client = new PartnerAppPrepay(
//                "1681873607",                  // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考https://pay.weixin.qq.com/doc/v3/partner/4013080340
//                "55714944F7A7E52526F708280B176DCC838F371A",       // 商户API证书序列号,如何获取请参考https://pay.weixin.qq.com/doc/v3/partner/4013058924
//                "E:\\wanpai\\1681873607_20250424_cert\\apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径
//                "PUB_KEY_ID_0116818736072025042400351694002605",          // 微信支付公钥ID,如何获取请参考https://pay.weixin.qq.com/doc/v3/partner/4013038589
//                "E:\\wanpai\\pub_key.pem"     // 微信支付公钥文件路径,本地文件路径
                "1681873607",                  // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考https://pay.weixin.qq.com/doc/v3/partner/4013080340
                "55714944F7A7E52526F708280B176DCC838F371A",       // 商户API证书序列号,如何获取请参考https://pay.weixin.qq.com/doc/v3/partner/4013058924
                "/usr/playpai/server/wxV3/1681873607_20250424_cert/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径
                "PUB_KEY_ID_0116818736072025042400351694002605",          // 微信支付公钥ID,如何获取请参考https://pay.weixin.qq.com/doc/v3/partner/4013038589
                "/usr/playpai/server/wxV3/pub_key.pem"     // 微信支付公钥文件路径,本地文件路径
        );
        PartnerAppPrepay.PartnerAPIv3CommonPrepayRequest request = new PartnerAppPrepay.PartnerAPIv3CommonPrepayRequest();
        request.spAppid = appid;// appid
        request.spMchid = WxV3PayConfig.Mch_ID;// 服务商商户号
        request.subMchid = subMchid;// 子商户号
        request.description = description;// 描述
        request.outTradeNo = outTradeNo;// 订单号
        request.notifyUrl =callbackPath+ notifyUrl;// 回调地址
        request.amount = new PartnerAppPrepay.CommonAmountInfo();
        request.amount.total = (long) i;// 金额 单位分
        request.amount.currency = "CNY";
        String prepayId ="";
        Map<String, Object> map3 = new HashMap<>();
        try {
            PartnerAppPrepay.PartnerAPIv3AppPrepayResponse response = client.run(request);
            // TODO: 请求成功,继续业务逻辑
            System.err.println("微信申请成功,预支付ID: " + response.prepayId);
            prepayId = response.prepayId;
        } catch (WXPayUtility.ApiException e) {
            // TODO: 请求失败,根据状态码执行不同的逻辑
            e.printStackTrace();
        }
        map3.put("appid", appid);
        map3.put("timestamp", String.valueOf(System.currentTimeMillis() / 1000));
        String nonce_str = UUIDUtil.getRandomCode(16);
        map3.put("noncestr", nonce_str);
        map3.put("prepayid", prepayId);
        // 构造待签名字符串
        String message = WeChatV3SignUtil.buildSignMessage(map3);
        // 私钥路径(pem 文件)
        String privateKeyPath = "/usr/playpai/server/wxV3/1681873607_20250424_cert/apiclient_key.pem";
//      String privateKeyPath = "E:\\wanpai\\1681873607_20250424_cert\\apiclient_key.pem";
        // 生成签名
        String sign = WeChatV3SignUtil.signWithPrivateKey(message, privateKeyPath);
        map3.put("sign", sign);
        map3.put("package", "Sign=WXPay");
        map3.put("partnerid", WxV3PayConfig.Mch_ID);// 服务商商户号
        System.err.println(map3);
        return ResultUtil.success(map3);
    }
    /**
     * 发起分账