开通微信支付
密钥和数字证书
把下载的 apiclient cert.p12 数字证书文件,放入后端Java项目的 resources 目录中。
在Java项目的 application.yml 文件中,填写微信支付接口的相关配置信息。
1 2 3 4 5 6 7 8 9 10 11
| wechat: app-id: APPID app-secret: 密钥 pay: 微信支付3.0接口密钥 v3: his-vue: app-id: APPID app-v3-secret: 微信支付3.0接口密钥 mch-id: 微信商户平台ID domain: URL回调地址(暂时不用配置) cert-path: apiclient_cert.p12
|
使用第三方依赖库
使用开源免费的 payment-spring-boot 扩展库(https://gitee.com/felord/payment-spring-boot),该库完全兼容SpringBoot项目,而且对微信支付3.0的RESTful接口封装的非常好,调用起来非常简单。
我们需要在Java项目的 pom.xml 文件中引入该依赖库,我们项目已经默认引用了该依赖库。刚才我们在 application.yml 文件中配置的支付信息,就是给 payment-spring-boot 框架使用的。
1 2 3 4 5
| <dependency> <groupId>cn.felord</groupId> <artifactId>payment-spring-boot-starter</artifactId> <version>1.0.14.RELEASE</version> </dependency>
|
com.jiang.his.api.config 包中,创建 PayConfig.java 类,开启支付功能
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| package com.jiang.his.api.config;
import cn.felord.payment.autoconfigure.EnableMobilePay; import org.springframework.context.annotation.Configuration;
@Configuration @EnableMobilePay public class PayConfig { }
|