wechat-spring-boot-starter-pay

WeChat pay spring boot starter

License

License

Categories

Categories

Spring Boot Container Microservices
GroupId

GroupId

cn.javaer.wechat
ArtifactId

ArtifactId

wechat-spring-boot-starter-pay
Last Version

Last Version

1.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

wechat-spring-boot-starter-pay
WeChat pay spring boot starter
Project URL

Project URL

https://github.com/cn-src/wechat-pay
Source Code Management

Source Code Management

https://github.com/cn-src/wechat-pay.git

Download wechat-spring-boot-starter-pay

How to add to project

<!-- https://jarcasting.com/artifacts/cn.javaer.wechat/wechat-spring-boot-starter-pay/ -->
<dependency>
    <groupId>cn.javaer.wechat</groupId>
    <artifactId>wechat-spring-boot-starter-pay</artifactId>
    <version>1.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/cn.javaer.wechat/wechat-spring-boot-starter-pay/
implementation 'cn.javaer.wechat:wechat-spring-boot-starter-pay:1.1.0'
// https://jarcasting.com/artifacts/cn.javaer.wechat/wechat-spring-boot-starter-pay/
implementation ("cn.javaer.wechat:wechat-spring-boot-starter-pay:1.1.0")
'cn.javaer.wechat:wechat-spring-boot-starter-pay:jar:1.1.0'
<dependency org="cn.javaer.wechat" name="wechat-spring-boot-starter-pay" rev="1.1.0">
  <artifact name="wechat-spring-boot-starter-pay" type="jar" />
</dependency>
@Grapes(
@Grab(group='cn.javaer.wechat', module='wechat-spring-boot-starter-pay', version='1.1.0')
)
libraryDependencies += "cn.javaer.wechat" % "wechat-spring-boot-starter-pay" % "1.1.0"
[cn.javaer.wechat/wechat-spring-boot-starter-pay "1.1.0"]

Dependencies

compile (3)

Group / Artifact Type Version
cn.javaer.wechat : wechat-pay jar 1.1.0
org.springframework.boot : spring-boot-starter-web jar
org.springframework.boot : spring-boot-configuration-processor Optional jar

provided (1)

Group / Artifact Type Version
org.projectlombok : lombok Optional jar

test (1)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-test jar

Project Modules

There are no modules declared in this project.

License Maven Central Build Status

wechat-pay

微信支付-简单易用

使用说明

  1. 参数名已尽可能保持与官方文档一致,因此可直接参照官方文档说明使用
  2. 提供了最小化参数集的接口,无需关心过多的参数
  3. 兼容微信支付API变动带来的未知响应字段以及枚举值
  4. 使用 spring 事件机制封装了微信支付通知,以简化使用方式
  5. wiremock 是一个 web mock server, 感兴趣的可以去官网了解 http://wiremock.org/, 配置中可配置微信 API 的 basePath, 所以你可以使用 wiremock 构建一个完全的仿真环境

使用前提

  1. 申请微信公众号以及微信商户号
  2. 获取到 公众号 ID(appid), 商户号(mchId)
  3. 登录商户号设置:【账户中心】-【API安全】, 设置 API 秘钥(mchKey),下载 API 证书(退款需要)
  4. 登录商户号设置:【产品中心】-【开发配置】, 配置支付目录
  5. 登录商户号设置:【交易中心】-【退款配置】, 配置通知 url(推荐样例: http://your_host/public/wechat/pay/refund_notify)
  6. 如果你处于开发测试阶段,可能需要一个内网穿透工具以及ICP备案域名,推荐使用: https://natapp.cn/
  7. samples 目录下有相关使用样例,类似 System.getenv("wechat.pay.appId") 的参数获取是为了从 jvm 系统变量中获取私密配置信息,你可以根据相关的开发工具等从外部配置好即可无需修改样例代码运行样例了,对于使用 IDEA 开发工具的推荐插件 https://github.com/Ashald/EnvFile 从外部配置私密信息

maven 坐标

<dependency>
    <groupId>cn.javaer.wechat</groupId>
    <artifactId>wechat-pay</artifactId>
    <version>LATEST</version>
</dependency>

<dependency>
    <groupId>cn.javaer.wechat</groupId>
    <artifactId>wechat-spring-boot-starter-pay</artifactId>
    <version>LATEST</version>
</dependency>

常规使用

  1. 启动接收结果通知的 web 服务, 测试下可运行 run-wiremock.sh 启动模拟服务器,用于接收结果通知以及响应.
  2. 使用样例
WeChatPayConfigurator configurator = new WeChatPayConfigurator();
configurator.setAppId("");
configurator.setMchId("");
configurator.setMchKey("");
configurator.setPaymentNotifyUrl("http://your_host/public/wechat/pay/payment_notify");
configurator.setCertificatePath("");

WeChatPayService weChatPayService = new WeChatPayService(configurator);
// weChatPayService 调用相关方法

spring & spring boot 集成

  • 【spring集成】配置 WeChatPayController, WeChatPayServiceFactoryBean, 可参照 wechat-spring-boot-starter-pay 中的自动配置.
  • 【spring boot 集成】配置
wechat.pay.appId=
wechat.pay.mchId=
wechat.pay.mchKey=
wechat.pay.paymentNotifyUrl=http://your_host/public/wechat/pay/payment_notify
wechat.pay.certificatePath=
  • 使用样例
// 调用接口
@Autowired
private WeChatPayService weChatPayService
// 接收结果通知
@Component
public class SamplePayEvent {

    /**
     * 付款结果通知.
     *
     * @param event PaymentNotifyEvent
     */
    @EventListener
    public void paymentNotifyEvent(final PaymentNotifyEvent event) {
        System.out.println(event);
    }

    /**
     * 退款结果通知.
     *
     * @param event RefundNotifyEvent
     */
    @EventListener
    public void refundNotifyEvent(final RefundNotifyEvent event) {
        System.out.println(event);
    }
}

Versions

Version
1.1.0
1.0.0
1.0.0-rc1