Merge remote-tracking branch 'origin/test' into test

This commit is contained in:
wangw 2025-10-29 16:51:06 +08:00
commit ffde41dd97
3 changed files with 45 additions and 29 deletions

View File

@ -3,7 +3,6 @@ package com.czg.controller;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.CzgPayUtils;
import com.czg.entity.CzgBaseRespParams;
@ -13,6 +12,7 @@ import com.czg.order.entity.OrderPayment;
import com.czg.order.service.OrderInfoService;
import com.czg.order.service.OrderPaymentService;
import com.czg.order.service.ShopTableOrderStatisticService;
import com.czg.service.market.service.impl.AppWxServiceImpl;
import com.czg.service.market.service.impl.WxServiceImpl;
import com.czg.task.StatisticTask;
import com.czg.utils.AssertUtil;
@ -25,7 +25,6 @@ import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;
/**
* 回调
@ -47,7 +46,9 @@ public class NotifyController {
@Resource
private ShopTableOrderStatisticService shopTableOrderStatisticService;
@Resource
private WxServiceImpl wxService;
private AppWxServiceImpl wxService;
@Resource
private WxServiceImpl wxService2;
@Resource
private MkDistributionUserService distributionUserService;
@Resource
@ -55,9 +56,9 @@ public class NotifyController {
@GetMapping("testOpen")
public Map<String, String> test1(String code) throws Exception {
distributionUserService.distribute(54458L, "WX1980104754310836224", BigDecimal.valueOf(18), 36434L, 122L, "order");
return null;
public JSONObject test1(String code) throws Exception {
JSONObject jsonObject = wxService.transferBalance("or1l86yipGvwyfPhrKIAcQuSfAV8", "叶明飞", new BigDecimal("0.01"), "转账测试", "testTranymf0001");
return jsonObject;
}

View File

@ -30,9 +30,9 @@ public class AppWxServiceImpl extends BaseWx {
@PostConstruct
public void init() {
// 小程序id
config.appId = paramsService.getSysParamValue("shop_wx_appid");
config.appId = paramsService.getSysParamValue("wx_mini_app_id");
// 小程序secrete
config.appSecret = paramsService.getSysParamValue("shop_wx_secrete");
config.appSecret = paramsService.getSysParamValue("wx_mini_secrete");
config.certPath = "";
// 微信支付公钥
config.pubKey = paramsService.getSysParamValue("wx_pub_key");

View File

@ -12,6 +12,7 @@ import com.ijpay.core.enums.RequestMethodEnum;
import com.ijpay.core.enums.SignType;
import com.ijpay.core.kit.AesUtil;
import com.ijpay.core.kit.PayKit;
import com.ijpay.core.kit.RsaKit;
import com.ijpay.core.kit.WxPayKit;
import com.ijpay.wxpay.WxPayApi;
import com.ijpay.wxpay.enums.WxDomainEnum;
@ -22,12 +23,14 @@ import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.crypto.Cipher;
import java.io.ByteArrayInputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.security.PrivateKey;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.Base64;
import java.util.Locale;
@ -104,20 +107,7 @@ public abstract class BaseWx {
* 使用微信支付平台证书公钥加密敏感信息OAEP
*/
String encryptByPlatformCert(String content) {
try (var certStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(config.getPlatformCertPath())) {
if (certStream == null) {
throw new RuntimeException("未找到微信支付平台证书文件: " + config.getPlatformCertPath());
}
X509Certificate certificate = PayKit.getCertificate(certStream);
if (certificate == null) {
throw new RuntimeException("读取证书失败");
}
return PayKit.rsaEncryptOAEP(content, certificate);
} catch (Exception e) {
throw new RuntimeException(e);
}
return PayKit.encryptData(content, config.pubKey);
}
String getSerialNumberFromPem(String certContent) {
@ -343,19 +333,41 @@ public abstract class BaseWx {
}
return "data:image/png;base64," + Base64.getEncoder().encodeToString(bodyBytes);
}
public static X509Certificate loadCertificate(String certStr) throws Exception {
// 去掉 PEM 头尾
String pem = certStr
.replace("-----BEGIN CERTIFICATE-----", "")
.replace("-----END CERTIFICATE-----", "")
.replaceAll("\\s+", "");
byte[] der = Base64.getDecoder().decode(pem);
CertificateFactory factory = CertificateFactory.getInstance("X.509");
return (X509Certificate) factory.generateCertificate(new ByteArrayInputStream(der));
}
public String rsaEncryptOAEP(String content) {
try {
Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-1AndMGF1Padding");
cipher.init(Cipher.ENCRYPT_MODE, RsaKit.loadPublicKey(config.pubKey));
byte[] dataByte = content.getBytes(StandardCharsets.UTF_8);
byte[] cipherData = cipher.doFinal(dataByte);
return cn.hutool.core.codec.Base64.encode(cipherData);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
JSONObject transferBalance(String openId, String name, BigDecimal amount, String remarkTxt, String billNoTxt) {
public JSONObject transferBalance(String openId, String name, BigDecimal amount, String remarkTxt, String billNoTxt) {
String remark = remarkTxt == null ? "佣金" : remarkTxt;
String billNo = billNoTxt == null ? IdUtil.simpleUUID() : billNoTxt;
Map<String, Object> params = Map.of(
Map<String, Object> params = new java.util.HashMap<>(Map.of(
"appid", config.appId,
"out_bill_no", billNo,
"transfer_scene_id", "1005",
"openid", openId,
"user_name", encryptByPlatformCert(name),
"transfer_amount", amount.multiply(BigDecimal.valueOf(100)).intValue(),
"transfer_remark", remark,
"notify_url", config.transferNotifyUrl,
@ -363,7 +375,10 @@ public abstract class BaseWx {
Map.of("info_type", "岗位类型", "info_content", "加盟商"),
Map.of("info_type", "报酬说明", "info_content", "测试")
}
);
));
if (amount.compareTo(BigDecimal.valueOf(0.3)) >= 0) {
params.put("user_name", rsaEncryptOAEP(name));
}
log.info("转账到零钱参数: {}", JSONObject.toJSONString(params));
IJPayHttpResponse response = null;
try {
@ -372,9 +387,9 @@ public abstract class BaseWx {
WxDomainEnum.CHINA.toString(),
"/v3/fund-app/mch-transfer/transfer-bills",
config.mchId,
getSerialNumber(),
config.platformCertNo,
config.apiCertKey,
getSerialNumberFromPem(config.apiCert),
null,
config.privateKey,
JSONObject.toJSONString(params)
);
} catch (Exception e) {