From f1a3683bc6516b25580437b1a106a0fbecdb84b6 Mon Sep 17 00:00:00 2001 From: "felord.cn" Date: Thu, 7 Jan 2021 21:07:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BE=AE=E4=BF=A1=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E8=83=BD=E5=A4=9F=E6=AD=A3=E7=A1=AE=E6=A0=B9=E6=8D=AE=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E6=9D=A1=E4=BB=B6=E5=8A=A8=E6=80=81=E5=90=AF=E7=94=A8?= =?UTF-8?q?=E4=BA=86=EF=BC=8C=E4=BF=AE=E5=A4=8D=E4=BA=86=E4=B8=8D=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=BE=AE=E4=BF=A1=E6=94=AF=E4=BB=98=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=90=AF=E7=94=A8=E6=94=AF=E4=BB=98=E5=AE=9D?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82=20=20=20=20=201.=20?= =?UTF-8?q?=E5=BD=93=E9=85=8D=E7=BD=AE=E4=B8=AD=E5=AD=98=E5=9C=A8`wechat.p?= =?UTF-8?q?ay.v3`=E9=85=8D=E7=BD=AE=E6=97=B6=EF=BC=8C=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=90=AF=E7=94=A8=EF=BC=9B=E5=90=A6=E5=88=99?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=94=AF=E4=BB=98=E4=B8=8D=E5=90=AF=E7=94=A8?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E4=BC=9A=E5=BD=B1=E5=93=8D=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E5=AE=9D=E7=9A=84=E8=BF=90=E8=A1=8C=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/changelog.md | 10 +++ docs/stackoverflow.md | 2 +- payment-spring-boot-autoconfigure/pom.xml | 4 +- .../wechat/WechatPayConfiguration.java | 2 + .../wechat/WechatPayConfiguredCondition.java | 64 +++++++++++++++++++ payment-spring-boot-starter/pom.xml | 4 +- pom.xml | 2 +- 7 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/WechatPayConfiguredCondition.java diff --git a/docs/changelog.md b/docs/changelog.md index 0524842..9332e68 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,3 +1,13 @@ +## 1.0.3.RELEASE +- 微信支付 + - feat: 完善合单支付账单 + 1. 增加合单支付-申请交易账单API。 + 2. 增加合单支付-申请资金账单API。 + - fix: #I2BCMZ 合单支付url不正确的问题。 + - fix: 微信支付能够正确根据环境条件动态启用了,修复了不配置微信支付时,无法启用支付宝的问题。 + 1. 当配置中存在`wechat.pay.v3`配置时,微信支付启用;否则微信支付不启用,不会影响支付宝的运行。 + - refactor: 先享卡优化 + ## 1.0.2.RELEASE - 微信支付 - feat: 接入微信支付分 diff --git a/docs/stackoverflow.md b/docs/stackoverflow.md index aa73e1d..8982758 100644 --- a/docs/stackoverflow.md +++ b/docs/stackoverflow.md @@ -35,7 +35,7 @@ ## 支付宝 -### 证书 +### 支付宝证书 请注意因为未来**SHA1withRSA**将被淘汰,因此采用最新的**SHA256withRSA**证书,旧的模式将不提供支持。步骤如下: diff --git a/payment-spring-boot-autoconfigure/pom.xml b/payment-spring-boot-autoconfigure/pom.xml index bae82a5..6c96d52 100644 --- a/payment-spring-boot-autoconfigure/pom.xml +++ b/payment-spring-boot-autoconfigure/pom.xml @@ -5,11 +5,11 @@ cn.felord payment-spring-boot - 1.0.2.RELEASE + 1.0.3.RELEASE payment-spring-boot-autoconfigure - 1.0.2.RELEASE + 1.0.3.RELEASE jar 4.0.0 diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/WechatPayConfiguration.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/WechatPayConfiguration.java index 68d98eb..9878264 100644 --- a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/WechatPayConfiguration.java +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/WechatPayConfiguration.java @@ -23,6 +23,7 @@ import cn.felord.payment.wechat.v3.*; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; import java.util.Map; @@ -34,6 +35,7 @@ import java.util.Map; * @since 1.0.0.RELEASE */ @Configuration +@Conditional(WechatPayConfiguredCondition.class) @EnableConfigurationProperties(WechatPayProperties.class) public class WechatPayConfiguration { /** diff --git a/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/WechatPayConfiguredCondition.java b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/WechatPayConfiguredCondition.java new file mode 100644 index 0000000..bb624a8 --- /dev/null +++ b/payment-spring-boot-autoconfigure/src/main/java/cn/felord/payment/wechat/WechatPayConfiguredCondition.java @@ -0,0 +1,64 @@ +/* + * + * Copyright 2019-2021 felord.cn + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * Website: + * https://felord.cn + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package cn.felord.payment.wechat; + +import org.springframework.boot.autoconfigure.condition.ConditionMessage; +import org.springframework.boot.autoconfigure.condition.ConditionOutcome; +import org.springframework.boot.autoconfigure.condition.SpringBootCondition; +import org.springframework.boot.context.properties.bind.Bindable; +import org.springframework.boot.context.properties.bind.Binder; +import org.springframework.context.annotation.ConditionContext; +import org.springframework.core.env.Environment; +import org.springframework.core.type.AnnotatedTypeMetadata; + +import java.util.Collections; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * The type Wechat pay configured condition. + * + * @author felord.cn + * @since 1.0.3.RELEASE + */ +public class WechatPayConfiguredCondition extends SpringBootCondition { + + /** + * The constant STRING_WECHAT_V3_MAP. + */ + private static final Bindable> STRING_WECHAT_V3_MAP = Bindable + .mapOf(String.class, WechatPayProperties.V3.class); + + @Override + public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { + ConditionMessage.Builder message = ConditionMessage.forCondition("Wechat Pay V3 Configured Condition"); + Map v3 = getV3(context.getEnvironment()); + if (!v3.isEmpty()) { + return ConditionOutcome.match(message.foundExactly("registered wechat mchIds " + v3.values().stream() + .map(WechatPayProperties.V3::getMchId).collect(Collectors.joining(", ")))); + } + return ConditionOutcome.noMatch(message.notAvailable("registered wechat pay configs")); + } + + private Map getV3(Environment environment) { + return Binder.get(environment).bind("wechat.pay.v3", STRING_WECHAT_V3_MAP) + .orElse(Collections.emptyMap()); + } + +} diff --git a/payment-spring-boot-starter/pom.xml b/payment-spring-boot-starter/pom.xml index d738dc4..116f47e 100644 --- a/payment-spring-boot-starter/pom.xml +++ b/payment-spring-boot-starter/pom.xml @@ -5,11 +5,11 @@ cn.felord payment-spring-boot - 1.0.2.RELEASE + 1.0.3.RELEASE payment-spring-boot-starter - 1.0.2.RELEASE + 1.0.3.RELEASE jar 4.0.0 diff --git a/pom.xml b/pom.xml index 2130491..31ddea9 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> cn.felord payment-spring-boot - 1.0.2.RELEASE + 1.0.3.RELEASE pom 4.0.0