提交 7735f055 作者: xiaowang

报错修复

上级 063f8661
......@@ -5,7 +5,6 @@ import com.mmc.payment.constant.WechatConstant;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.core.notification.NotificationConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
......@@ -20,7 +19,6 @@ public class WxConfigUtils {
@Resource
UserSystemConstant userSystemConstant;
@Bean
public Config createConfig() {
// 使用自动更新平台证书的RSA配置
// 一个商户号只能初始化一个配置,否则会因为重复的下载任务报错
......@@ -35,7 +33,6 @@ public class WxConfigUtils {
return config;
}
@Bean
public NotificationConfig createNotificationConfig() {
// 使用自动更新平台证书的RSA配置
// 一个商户号只能初始化一个配置,否则会因为重复的下载任务报错
......
package com.mmc.payment;
import com.mmc.payment.constant.UserSystemConstant;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.service.payments.nativepay.NativePayService;
import com.wechat.pay.java.service.payments.nativepay.model.Amount;
import com.wechat.pay.java.service.payments.nativepay.model.PrepayRequest;
import com.wechat.pay.java.service.payments.nativepay.model.PrepayResponse;
import org.junit.Test;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* @author: zj
* @Date: 2023/7/19 14:52
*/
@Component
public class QuickStart {
@Resource
private UserSystemConstant userSystemConstant;
/**
* 商户API私钥路径
*/
public static String privateKeyPath = "src/main/resources/apiclient_key.pem";
@Test
public void test() {
// 使用自动更新平台证书的RSA配置
// 一个商户号只能初始化一个配置,否则会因为重复的下载任务报错
Config config =
new RSAAutoCertificateConfig.Builder()
.merchantId(userSystemConstant.getMchid())
.privateKeyFromPath(privateKeyPath)
.merchantSerialNumber(userSystemConstant.getMchNumber())
.apiV3Key(userSystemConstant.getApiv3Key())
.build();
// 构建service
NativePayService service = new NativePayService.Builder().config(config).build();
// request.setXxx(val)设置所需参数,具体参数可见Request定义
PrepayRequest request = new PrepayRequest();
Amount amount = new Amount();
amount.setTotal(100);
request.setAmount(amount);
request.setAppid("wx18b7883acd204278");
request.setMchid("1648653533");
request.setDescription("测试商品标题");
request.setNotifyUrl("https://notify_url");
request.setOutTradeNo(System.currentTimeMillis()+"");
// 调用下单方法,得到应答
PrepayResponse response = service.prepay(request);
// 使用微信扫描 code_url 对应的二维码,即可体验Native支付
System.out.println(response.getCodeUrl());
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论