无关风月
12 小时以前 5dc40fcd64b0513150f1d8335ab849e6d8cdc28e
cloud-server-account/src/main/java/com/dsh/account/util/PayMoneyUtil.java
@@ -26,6 +26,10 @@
//import com.github.binarywang.wxpay.service.ProfitSharingV3Service;
//import com.github.binarywang.wxpay.service.WxPayService;
import com.dsh.account.util.wx.PartnerAppPrepay;
import com.dsh.account.util.wx.WXPayUtility;
import com.dsh.account.util.wx.WeChatV3SignUtil;
import com.dsh.account.util.wx.WxV3PayConfig;
import org.apache.commons.collections.map.HashedMap;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
@@ -181,7 +185,8 @@
    /**
     * 支付宝支付
     */
    public ResultUtil  alipay(String smid,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 ();
//        //设置网关地址
@@ -258,47 +263,7 @@
        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 {
@@ -547,17 +512,10 @@
        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);
@@ -649,6 +607,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);
    }
    @Resource