mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-25 18:29:17 +08:00
🆕 #3217 增加 solon-plugins 适配
This commit is contained in:
43
solon-plugins/wx-java-pay-solon-plugin/README.md
Normal file
43
solon-plugins/wx-java-pay-solon-plugin/README.md
Normal file
@@ -0,0 +1,43 @@
|
||||
# 使用说明
|
||||
1. 在自己的Solon项目里,引入maven依赖
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>wx-java-pay-solon-plugin</artifactId>
|
||||
<version>${version}</version>
|
||||
</dependency>
|
||||
```
|
||||
2. 添加配置(app.yml)
|
||||
###### 1)V2版本
|
||||
```yml
|
||||
wx:
|
||||
pay:
|
||||
appId:
|
||||
mchId:
|
||||
mchKey:
|
||||
keyPath:
|
||||
```
|
||||
###### 2)V3版本
|
||||
```yml
|
||||
wx:
|
||||
pay:
|
||||
appId: xxxxxxxxxxx
|
||||
mchId: 15xxxxxxxxx #商户id
|
||||
apiV3Key: Dc1DBwSc094jACxxxxxxxxxxxxxxx #V3密钥
|
||||
certSerialNo: 62C6CEAA360BCxxxxxxxxxxxxxxx
|
||||
privateKeyPath: classpath:cert/apiclient_key.pem #apiclient_key.pem证书文件的绝对路径或者以classpath:开头的类路径
|
||||
privateCertPath: classpath:cert/apiclient_cert.pem #apiclient_cert.pem证书文件的绝对路径或者以classpath:开头的类路径
|
||||
```
|
||||
###### 3)V3服务商版本
|
||||
```yml
|
||||
wx:
|
||||
pay: #微信服务商支付
|
||||
configs:
|
||||
- appId: wxe97b2x9c2b3d #spAppId
|
||||
mchId: 16486610 #服务商商户
|
||||
subAppId: wx118cexxe3c07679 #子appId
|
||||
subMchId: 16496705 #子商户
|
||||
apiV3Key: Dc1DBwSc094jAKDGR5aqqb7PTHr #apiV3密钥
|
||||
privateKeyPath: classpath:cert/apiclient_key.pem #服务商证书文件,apiclient_key.pem证书文件的绝对路径或者以classpath:开头的类路径(可以配置绝对路径)
|
||||
privateCertPath: classpath:cert/apiclient_cert.pem #apiclient_cert.pem证书文件的绝对路径或者以classpath:开头的类路径
|
||||
```
|
||||
24
solon-plugins/wx-java-pay-solon-plugin/pom.xml
Normal file
24
solon-plugins/wx-java-pay-solon-plugin/pom.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>wx-java-solon-plugins</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>4.6.4.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>wx-java-pay-solon-plugin</artifactId>
|
||||
<name>WxJava - Solon Plugin for WxPay</name>
|
||||
<description>微信支付开发的 Solon Plugin</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>weixin-java-pay</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.binarywang.solon.wxjava.pay.config;
|
||||
|
||||
import com.binarywang.solon.wxjava.pay.properties.WxPayProperties;
|
||||
import com.github.binarywang.wxpay.config.WxPayConfig;
|
||||
import com.github.binarywang.wxpay.service.WxPayService;
|
||||
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.noear.solon.annotation.Bean;
|
||||
import org.noear.solon.annotation.Condition;
|
||||
import org.noear.solon.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信支付自动配置
|
||||
* Created by BinaryWang on 2019/4/17.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
@Configuration
|
||||
@Condition(
|
||||
onProperty = "${wx.pay.enabled:true} = true",
|
||||
onClass=WxPayService.class
|
||||
)
|
||||
public class WxPayAutoConfiguration {
|
||||
private WxPayProperties properties;
|
||||
|
||||
public WxPayAutoConfiguration(WxPayProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造微信支付服务对象.
|
||||
*
|
||||
* @return 微信支付service
|
||||
*/
|
||||
@Bean
|
||||
@Condition(onMissingBean=WxPayService.class)
|
||||
public WxPayService wxPayService() {
|
||||
final WxPayServiceImpl wxPayService = new WxPayServiceImpl();
|
||||
WxPayConfig payConfig = new WxPayConfig();
|
||||
payConfig.setAppId(StringUtils.trimToNull(this.properties.getAppId()));
|
||||
payConfig.setMchId(StringUtils.trimToNull(this.properties.getMchId()));
|
||||
payConfig.setMchKey(StringUtils.trimToNull(this.properties.getMchKey()));
|
||||
payConfig.setSubAppId(StringUtils.trimToNull(this.properties.getSubAppId()));
|
||||
payConfig.setSubMchId(StringUtils.trimToNull(this.properties.getSubMchId()));
|
||||
payConfig.setKeyPath(StringUtils.trimToNull(this.properties.getKeyPath()));
|
||||
payConfig.setUseSandboxEnv(this.properties.isUseSandboxEnv());
|
||||
//以下是apiv3以及支付分相关
|
||||
payConfig.setServiceId(StringUtils.trimToNull(this.properties.getServiceId()));
|
||||
payConfig.setPayScoreNotifyUrl(StringUtils.trimToNull(this.properties.getPayScoreNotifyUrl()));
|
||||
payConfig.setPrivateKeyPath(StringUtils.trimToNull(this.properties.getPrivateKeyPath()));
|
||||
payConfig.setPrivateCertPath(StringUtils.trimToNull(this.properties.getPrivateCertPath()));
|
||||
payConfig.setCertSerialNo(StringUtils.trimToNull(this.properties.getCertSerialNo()));
|
||||
payConfig.setApiV3Key(StringUtils.trimToNull(this.properties.getApiv3Key()));
|
||||
|
||||
wxPayService.setConfig(payConfig);
|
||||
return wxPayService;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.binarywang.solon.wxjava.pay.integration;
|
||||
|
||||
import com.binarywang.solon.wxjava.pay.config.WxPayAutoConfiguration;
|
||||
import com.binarywang.solon.wxjava.pay.properties.WxPayProperties;
|
||||
import org.noear.solon.core.AppContext;
|
||||
import org.noear.solon.core.Plugin;
|
||||
|
||||
/**
|
||||
* @author noear 2024/9/2 created
|
||||
*/
|
||||
public class WxPayPluginImpl implements Plugin {
|
||||
@Override
|
||||
public void start(AppContext context) throws Throwable {
|
||||
context.beanMake(WxPayProperties.class);
|
||||
|
||||
context.beanMake(WxPayAutoConfiguration.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.binarywang.solon.wxjava.pay.properties;
|
||||
|
||||
import lombok.Data;
|
||||
import org.noear.solon.annotation.Configuration;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信支付属性配置类
|
||||
* Created by Binary Wang on 2019/4/17.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
@Data
|
||||
@Configuration
|
||||
@Inject("${wx.pay}")
|
||||
public class WxPayProperties {
|
||||
/**
|
||||
* 设置微信公众号或者小程序等的appid.
|
||||
*/
|
||||
private String appId;
|
||||
|
||||
/**
|
||||
* 微信支付商户号.
|
||||
*/
|
||||
private String mchId;
|
||||
|
||||
/**
|
||||
* 微信支付商户密钥.
|
||||
*/
|
||||
private String mchKey;
|
||||
|
||||
/**
|
||||
* 服务商模式下的子商户公众账号ID,普通模式请不要配置,请在配置文件中将对应项删除.
|
||||
*/
|
||||
private String subAppId;
|
||||
|
||||
/**
|
||||
* 服务商模式下的子商户号,普通模式请不要配置,最好是请在配置文件中将对应项删除.
|
||||
*/
|
||||
private String subMchId;
|
||||
|
||||
/**
|
||||
* apiclient_cert.p12文件的绝对路径,或者如果放在项目中,请以classpath:开头指定.
|
||||
*/
|
||||
private String keyPath;
|
||||
|
||||
/**
|
||||
* 微信支付分serviceId
|
||||
*/
|
||||
private String serviceId;
|
||||
|
||||
/**
|
||||
* 证书序列号
|
||||
*/
|
||||
private String certSerialNo;
|
||||
|
||||
/**
|
||||
* apiV3秘钥
|
||||
*/
|
||||
private String apiv3Key;
|
||||
|
||||
/**
|
||||
* 微信支付分回调地址
|
||||
*/
|
||||
private String payScoreNotifyUrl;
|
||||
|
||||
/**
|
||||
* apiv3 商户apiclient_key.pem
|
||||
*/
|
||||
private String privateKeyPath;
|
||||
|
||||
/**
|
||||
* apiv3 商户apiclient_cert.pem
|
||||
*/
|
||||
private String privateCertPath;
|
||||
|
||||
/**
|
||||
* 微信支付是否使用仿真测试环境.
|
||||
* 默认不使用
|
||||
*/
|
||||
private boolean useSandboxEnv;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
solon.plugin=com.binarywang.solon.wxjava.pay.integration.WxPayPluginImpl
|
||||
solon.plugin.priority=10
|
||||
Reference in New Issue
Block a user