微信支付修改

This commit is contained in:
gong
2026-01-09 17:33:32 +08:00
parent 9b74b38799
commit dfd2c74c33
2 changed files with 9 additions and 7 deletions

View File

@@ -34,11 +34,11 @@ public class PayManager {
// .setNotifyUrl("https://www.baidu.com"));
jsapiPay(new PayParamsDto()
.setPlatform(PayCst.Platform.WECHAT)
.setAppId("2021004145625815")
.setAppId("wxd88fffa983758a30")
.setOpenId("123123123")
.setOrderNo("1111231231213")
.setTitle("1213")
.setMerchantId("123312321")
.setMerchantId("1665469114")
.setBody("1213")
.setAmount(1000L)
.setPayParams("{\"app_auth_token\": \"ssss\"}")

View File

@@ -7,6 +7,9 @@ import com.czg.exception.CzgException;
import com.czg.third.wechat.dto.config.WechatPayConfigDto;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.cipher.Signer;
import com.wechat.pay.java.core.http.HttpClient;
import com.wechat.pay.java.core.http.HttpMethod;
import com.wechat.pay.java.core.util.NonceUtil;
import lombok.extern.slf4j.Slf4j;
import java.net.URLEncoder;
@@ -50,23 +53,22 @@ public class WechatReqUtils {
String authorization = String.format("WECHATPAY2-SHA256-RSA2048 mchid=\"%s\",nonce_str=\"%s\",signature=\"%s\",timestamp=\"%d\",serial_no=\"%s\"",
configDto.getMerchantId(), nonce, signature, timestamp, configDto.getSerialNumber());
HttpRequest request = switch (method) {
case "POST" -> HttpUtil.createPost(configDto.getDomain() + url)
.header("Authorization", authorization)
.header("Wechatpay-Serial", configDto.getPublicKeyId())
.header("Wechatpay-Serial", configDto.getSerialNumber())
.charset(StandardCharsets.UTF_8)
.contentType("application/json")
.body(body );
case "GET" -> HttpUtil.createGet(configDto.getDomain() + url)
.header("Authorization", authorization)
.header("Wechatpay-Serial", configDto.getPublicKeyId())
.header("Wechatpay-Serial", configDto.getSerialNumber())
.charset(StandardCharsets.UTF_8)
.contentType("application/json");
default -> throw new CzgException("不支持的请求方法");
};
log.info("微信支付请求url = {} \nauthorization: {}", url, authorization);
log.info("微信支付请求url = {} \nauthorization: {}", request.getUrl(), authorization);
HttpResponse response = request.execute();
String s = response.body();
log.info("微信支付请求url = {}\n\tmethod: {}\n\tbody: {}\n\tresp: {}", url, method, body, s);
@@ -104,7 +106,7 @@ public class WechatReqUtils {
* 获取随机串
*/
private static String getNonceStr() {
return UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
return NonceUtil.createNonce(32);
}
/**