Package import:
< dependency >
< groupId >me.hao0</ groupId >
< artifactId >wepay-core</ artifactId >
< version >1.3.2</ version >
</ dependency >
Dependent packages, pay attention to whether you need to exclude when introducing the project:
< dependency >
< groupId >me.hao0</ groupId >
< artifactId >common</ artifactId >
< version >1.1.2</ version >
</ dependency >
Basic usage:
Wepay wepay = WepayBuilder
. newBuilder ( appId , appKey , mchId )
. config1 (...) // 其他可选配置
...
. build ();
wepay . module (). api ();
Implemented components:
pay()
;refund()
;order()
;notify()
;bill()
.API documentation here.
About testing :
The test cases include some basic tests that require some configuration:
// 在test/reources目录中配置dev.properties
// 包括appId(APP ID), appKey(支付密钥), mchId(商户号)
Properties props = new Properties ();
InputStream in = Object . class . getResourceAsStream ( "/dev.properties" );
props . load ( in );
in . close ();
// 配置证书,退款需要证书,不配置可测试除退款的接口
Path path = Paths . get ( "/path/to/your_cert.p12" );
byte [] data = Files . readAllBytes ( path );
wepay = WepayBuilder . newBuilder (
props . getProperty ( "appId" ),
props . getProperty ( "appKey" ),
props . getProperty ( "mchId" ))
. certPasswd ( props . getProperty ( "mchId" ))
. certs ( data )
. build ();
The wepay-demo project is a runnable web project, which is convenient for testing. You can test it according to the following steps. Copy app-example.properties
in wepay-demo to app.properties
and configure it accordingly:
# 微信app id
appId =
# 微信支付key
appKey =
# 商户号
mchId =
# 支付通知url
payNotifyUrl = $ { your_domain } / notifies / paid
Note : ** payNotifyUrl
** should be configured as an address that the WeChat server can call from the external network. For local testing, it is recommended to use the ngrok tool for local and external network mapping.
Go to the wepay-demo root directory and run the following command:
mvn clean jetty:run -Dmaven.test.skip -Djetty.port={自定义端口号}
Dynamic QR code payment is accessible ( after the request is normal, the QR code image generated by Liantu will appear. After the payment is successful by scanning with WeChat, the corresponding notification Notifies
will be received in the background ):
http://localhost:{port}/pays/qrpay ? orderNumber={自定义订单号}
Refund is accessible ( after successful submission, a message will be notified on WeChat ):
http://localhost:{port}/refunds/apply ? orderNumber={商户订单号} ` ` `
Related documents:
Historical version:
1.0.0:
1.1.0:
1.1.1:
1.1.2:
1.2.2:
1.2.3:
1.2.4:
1.2.5:
1.3.0:
1.3.1:
goods_tag
field name.1.3.2:
clientIp
field to clientIp
.Related components:
Alipay:
WeChat: