🆕 #3217 增加 solon-plugins 适配
This commit is contained in:
@@ -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