Adapay根据@ConditionalOnProperty("adapay")自动完成配置和初始化
This commit is contained in:
parent
70a3245630
commit
c509323b3f
|
|
@ -1,8 +1,12 @@
|
||||||
package com.ghy.common.adapay;
|
package com.ghy.common.adapay;
|
||||||
|
|
||||||
|
import com.huifu.adapay.Adapay;
|
||||||
|
import com.huifu.adapay.model.MerConfig;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapay 自动装载
|
* Adapay 自动装载
|
||||||
|
|
@ -10,11 +14,24 @@ import org.springframework.context.annotation.Configuration;
|
||||||
* @author HH 2022/3/25
|
* @author HH 2022/3/25
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@ConditionalOnProperty("adapay")
|
||||||
@EnableConfigurationProperties(AdapayProperties.class)
|
@EnableConfigurationProperties(AdapayProperties.class)
|
||||||
public class AdapayAutoConfiguration {
|
public class AdapayAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public AdapayService adapayService(AdapayProperties adapayProperties) {
|
public AdapayService adapayService(AdapayProperties adapayProperties) throws Exception {
|
||||||
|
|
||||||
|
Assert.hasText(adapayProperties.getAppId(), "Adapay.appId is blank!");
|
||||||
|
Assert.hasText(adapayProperties.getApiKey(), "Adapay.apiKey is blank!");
|
||||||
|
Assert.hasText(adapayProperties.getMockApiKey(), "Adapay.mockApiKey is blank!");
|
||||||
|
Assert.hasText(adapayProperties.getRsaPrivateKey(), "Adapay.rsaPrivateKey is blank!");
|
||||||
|
|
||||||
|
MerConfig merConfig = new MerConfig();
|
||||||
|
merConfig.setApiKey(adapayProperties.getApiKey());
|
||||||
|
merConfig.setApiMockKey(adapayProperties.getMockApiKey());
|
||||||
|
merConfig.setRSAPrivateKey(adapayProperties.getRsaPrivateKey());
|
||||||
|
Adapay.initWithMerConfig(merConfig);
|
||||||
|
|
||||||
AdapayService adapayService = new AdapayService();
|
AdapayService adapayService = new AdapayService();
|
||||||
adapayService.setAdapayProperties(adapayProperties);
|
adapayService.setAdapayProperties(adapayProperties);
|
||||||
return adapayService;
|
return adapayService;
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,8 @@
|
||||||
package com.ghy.common.adapay;
|
package com.ghy.common.adapay;
|
||||||
|
|
||||||
import com.huifu.adapay.Adapay;
|
|
||||||
import com.huifu.adapay.model.MerConfig;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapay 配置类
|
* Adapay 配置类
|
||||||
|
|
@ -16,7 +12,7 @@ import org.springframework.util.Assert;
|
||||||
@Data
|
@Data
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ConfigurationProperties("adapay")
|
@ConfigurationProperties("adapay")
|
||||||
public class AdapayProperties implements InitializingBean {
|
public class AdapayProperties {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否打印调用日志,默认不打印
|
* 是否打印调用日志,默认不打印
|
||||||
|
|
@ -41,18 +37,4 @@ public class AdapayProperties implements InitializingBean {
|
||||||
private String mockApiKey;
|
private String mockApiKey;
|
||||||
private String rsaPrivateKey;
|
private String rsaPrivateKey;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterPropertiesSet() throws Exception {
|
|
||||||
log.info("Adapay.debug={}, Adapay.prodMode={}", debug, prodMode);
|
|
||||||
Assert.hasText(appId, "Adapay.appId is blank!");
|
|
||||||
Assert.hasText(apiKey, "Adapay.apiKey is blank!");
|
|
||||||
Assert.hasText(mockApiKey, "Adapay.mockApiKey is blank!");
|
|
||||||
Assert.hasText(rsaPrivateKey, "Adapay.rsaPrivateKey is blank!");
|
|
||||||
|
|
||||||
MerConfig merConfig = new MerConfig();
|
|
||||||
merConfig.setApiKey(apiKey);
|
|
||||||
merConfig.setApiMockKey(mockApiKey);
|
|
||||||
merConfig.setRSAPrivateKey(rsaPrivateKey);
|
|
||||||
Adapay.initWithMerConfig(merConfig);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -76,7 +76,7 @@ public class AdapayService {
|
||||||
* @param paymentId [必填项]支付确认对象的id
|
* @param paymentId [必填项]支付确认对象的id
|
||||||
* @param refundOrderNo [必填项]订单号
|
* @param refundOrderNo [必填项]订单号
|
||||||
* @param refundAmt [必填项]退款金额,若退款金额小于原交易金额,则认为是部分退款,必须大于0,保留两位小数点,如0.10、100.05等
|
* @param refundAmt [必填项]退款金额,若退款金额小于原交易金额,则认为是部分退款,必须大于0,保留两位小数点,如0.10、100.05等
|
||||||
* @return 同步返回一个 退款对象
|
* @return 同步返回一个 退款对象 https://docs.adapay.tech/api/trade.html#create-refund-params
|
||||||
*/
|
*/
|
||||||
public Map<String, Object> refund(RefundCallback callback, String paymentId, String refundOrderNo, String refundAmt) throws BaseAdaPayException {
|
public Map<String, Object> refund(RefundCallback callback, String paymentId, String refundOrderNo, String refundAmt) throws BaseAdaPayException {
|
||||||
Map<String, Object> refundParams = new HashMap<>(4);
|
Map<String, Object> refundParams = new HashMap<>(4);
|
||||||
|
|
@ -98,6 +98,7 @@ public class AdapayService {
|
||||||
* @param paymentId [必填项]由 Adapay 生成的支付对象 id
|
* @param paymentId [必填项]由 Adapay 生成的支付对象 id
|
||||||
* @param reason 关单描述
|
* @param reason 关单描述
|
||||||
* @param expend 扩展域
|
* @param expend 扩展域
|
||||||
|
* @return 关单的结果将通过一个 JSON 同步返回 https://docs.adapay.tech/api/trade.html#close-payment-response
|
||||||
*/
|
*/
|
||||||
public Map<String, Object> close(String paymentId, String reason, String expend) throws BaseAdaPayException {
|
public Map<String, Object> close(String paymentId, String reason, String expend) throws BaseAdaPayException {
|
||||||
Map<String, Object> paymentParams = new HashMap<>(4);
|
Map<String, Object> paymentParams = new HashMap<>(4);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import lombok.EqualsAndHashCode;
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class WxLiteExpend extends Expend{
|
public class WxLiteExpend extends Expend {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [必填]微信用户关注商家公众号的 openid
|
* [必填]微信用户关注商家公众号的 openid
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Auto Configure
|
||||||
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||||
|
com.ghy.common.adapay.AdapayAutoConfiguration
|
||||||
Loading…
Reference in New Issue