1:在maven工程中加入pom依赖
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-pay</artifactId>
<version>2.6.0</version>
</dependency>
2:创建.properties的商户信息
appid="公众号的Id"
mchId="支付的商户号"
mchKey="商户密钥"
subAppId="子商户的公众号Id"
subMchId="子商户号"
keyPath="apiclient_cert.p12的绝对路径、 包含了私钥信息的证书文件"
3:构建微信支付的服务类
WxPayConfig payConfig = new WxPayConfig();
public WxPayConfig config() {
WxPayConfig payConfig = new WxPayConfig();
payConfig.setAppId(this.properties.getAppId());
payConfig.setMchId(this.properties.getMchId());
payConfig.setMchKey(this.properties.getMchKey());
payConfig.setSubAppId(this.properties.getSubAppId());
payConfig.setSubMchId(this.properties.getSubMchId());
payConfig.setKeyPath(this.properties.getKeyPath());
return payConfig;
}
public WxPayService wxPayService(WxPayConfig payConfig) {
WxPayService wxPayService = new WxPayServiceImpl();
wxPayService.setConfig(payConfig);
return wxPayService;
}