微信支付修改
This commit is contained in:
@@ -34,11 +34,11 @@ public class PayManager {
|
|||||||
// .setNotifyUrl("https://www.baidu.com"));
|
// .setNotifyUrl("https://www.baidu.com"));
|
||||||
jsapiPay(new PayParamsDto()
|
jsapiPay(new PayParamsDto()
|
||||||
.setPlatform(PayCst.Platform.WECHAT)
|
.setPlatform(PayCst.Platform.WECHAT)
|
||||||
.setAppId("2021004145625815")
|
.setAppId("wxd88fffa983758a30")
|
||||||
.setOpenId("123123123")
|
.setOpenId("123123123")
|
||||||
.setOrderNo("1111231231213")
|
.setOrderNo("1111231231213")
|
||||||
.setTitle("1213")
|
.setTitle("1213")
|
||||||
.setMerchantId("123312321")
|
.setMerchantId("1665469114")
|
||||||
.setBody("1213")
|
.setBody("1213")
|
||||||
.setAmount(1000L)
|
.setAmount(1000L)
|
||||||
.setPayParams("{\"app_auth_token\": \"ssss\"}")
|
.setPayParams("{\"app_auth_token\": \"ssss\"}")
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ import com.czg.exception.CzgException;
|
|||||||
import com.czg.third.wechat.dto.config.WechatPayConfigDto;
|
import com.czg.third.wechat.dto.config.WechatPayConfigDto;
|
||||||
import com.wechat.pay.java.core.Config;
|
import com.wechat.pay.java.core.Config;
|
||||||
import com.wechat.pay.java.core.cipher.Signer;
|
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 lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.net.URLEncoder;
|
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\"",
|
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());
|
configDto.getMerchantId(), nonce, signature, timestamp, configDto.getSerialNumber());
|
||||||
|
|
||||||
|
|
||||||
HttpRequest request = switch (method) {
|
HttpRequest request = switch (method) {
|
||||||
case "POST" -> HttpUtil.createPost(configDto.getDomain() + url)
|
case "POST" -> HttpUtil.createPost(configDto.getDomain() + url)
|
||||||
.header("Authorization", authorization)
|
.header("Authorization", authorization)
|
||||||
.header("Wechatpay-Serial", configDto.getPublicKeyId())
|
.header("Wechatpay-Serial", configDto.getSerialNumber())
|
||||||
.charset(StandardCharsets.UTF_8)
|
.charset(StandardCharsets.UTF_8)
|
||||||
.contentType("application/json")
|
.contentType("application/json")
|
||||||
.body(body );
|
.body(body );
|
||||||
|
|
||||||
case "GET" -> HttpUtil.createGet(configDto.getDomain() + url)
|
case "GET" -> HttpUtil.createGet(configDto.getDomain() + url)
|
||||||
.header("Authorization", authorization)
|
.header("Authorization", authorization)
|
||||||
.header("Wechatpay-Serial", configDto.getPublicKeyId())
|
.header("Wechatpay-Serial", configDto.getSerialNumber())
|
||||||
.charset(StandardCharsets.UTF_8)
|
.charset(StandardCharsets.UTF_8)
|
||||||
.contentType("application/json");
|
.contentType("application/json");
|
||||||
default -> throw new CzgException("不支持的请求方法");
|
default -> throw new CzgException("不支持的请求方法");
|
||||||
};
|
};
|
||||||
log.info("微信支付请求:url = {} \nauthorization: {}", url, authorization);
|
log.info("微信支付请求:url = {} \nauthorization: {}", request.getUrl(), authorization);
|
||||||
HttpResponse response = request.execute();
|
HttpResponse response = request.execute();
|
||||||
String s = response.body();
|
String s = response.body();
|
||||||
log.info("微信支付请求:url = {}\n\tmethod: {}\n\tbody: {}\n\tresp: {}", url, method, body, s);
|
log.info("微信支付请求:url = {}\n\tmethod: {}\n\tbody: {}\n\tresp: {}", url, method, body, s);
|
||||||
@@ -104,7 +106,7 @@ public class WechatReqUtils {
|
|||||||
* 获取随机串
|
* 获取随机串
|
||||||
*/
|
*/
|
||||||
private static String getNonceStr() {
|
private static String getNonceStr() {
|
||||||
return UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
|
return NonceUtil.createNonce(32);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user