Commit cd03ddddb31057a250e57fc996de88f00763184c
Merge remote-tracking branch 'refs/remotes/yudao/develop' into develop
Showing
46 changed files
with
908 additions
and
364 deletions
pom.xml
| @@ -31,7 +31,7 @@ | @@ -31,7 +31,7 @@ | ||
| 31 | <url>https://github.com/YunaiV/ruoyi-vue-pro</url> | 31 | <url>https://github.com/YunaiV/ruoyi-vue-pro</url> |
| 32 | 32 | ||
| 33 | <properties> | 33 | <properties> |
| 34 | - <revision>2.1.0-snapshot</revision> | 34 | + <revision>2.2.0-snapshot</revision> |
| 35 | <!-- Maven 相关 --> | 35 | <!-- Maven 相关 --> |
| 36 | <java.version>17</java.version> | 36 | <java.version>17</java.version> |
| 37 | <maven.compiler.source>${java.version}</maven.compiler.source> | 37 | <maven.compiler.source>${java.version}</maven.compiler.source> |
yudao-dependencies/pom.xml
| @@ -14,7 +14,7 @@ | @@ -14,7 +14,7 @@ | ||
| 14 | <url>https://github.com/YunaiV/ruoyi-vue-pro</url> | 14 | <url>https://github.com/YunaiV/ruoyi-vue-pro</url> |
| 15 | 15 | ||
| 16 | <properties> | 16 | <properties> |
| 17 | - <revision>2.1.0-snapshot</revision> | 17 | + <revision>2.2.0-snapshot</revision> |
| 18 | <flatten-maven-plugin.version>1.6.0</flatten-maven-plugin.version> | 18 | <flatten-maven-plugin.version>1.6.0</flatten-maven-plugin.version> |
| 19 | <!-- 统一依赖管理 --> | 19 | <!-- 统一依赖管理 --> |
| 20 | <spring.boot.version>3.3.1</spring.boot.version> | 20 | <spring.boot.version>3.3.1</spring.boot.version> |
| @@ -69,8 +69,6 @@ | @@ -69,8 +69,6 @@ | ||
| 69 | <okhttp3.version>4.11.0</okhttp3.version> | 69 | <okhttp3.version>4.11.0</okhttp3.version> |
| 70 | <commons-io.version>2.15.1</commons-io.version> | 70 | <commons-io.version>2.15.1</commons-io.version> |
| 71 | <minio.version>8.5.7</minio.version> | 71 | <minio.version>8.5.7</minio.version> |
| 72 | - <aliyun-java-sdk-core.version>4.6.4</aliyun-java-sdk-core.version> | ||
| 73 | - <aliyun-java-sdk-dysmsapi.version>2.2.1</aliyun-java-sdk-dysmsapi.version> | ||
| 74 | <tencentcloud-sdk-java.version>3.1.880</tencentcloud-sdk-java.version> | 72 | <tencentcloud-sdk-java.version>3.1.880</tencentcloud-sdk-java.version> |
| 75 | <justauth.version>2.0.5</justauth.version> | 73 | <justauth.version>2.0.5</justauth.version> |
| 76 | <jimureport.version>1.7.8</jimureport.version> | 74 | <jimureport.version>1.7.8</jimureport.version> |
| @@ -549,26 +547,6 @@ | @@ -549,26 +547,6 @@ | ||
| 549 | 547 | ||
| 550 | <!-- SMS SDK begin --> | 548 | <!-- SMS SDK begin --> |
| 551 | <dependency> | 549 | <dependency> |
| 552 | - <groupId>com.aliyun</groupId> | ||
| 553 | - <artifactId>aliyun-java-sdk-core</artifactId> | ||
| 554 | - <version>${aliyun-java-sdk-core.version}</version> | ||
| 555 | - <exclusions> | ||
| 556 | - <exclusion> | ||
| 557 | - <artifactId>opentracing-api</artifactId> | ||
| 558 | - <groupId>io.opentracing</groupId> | ||
| 559 | - </exclusion> | ||
| 560 | - <exclusion> | ||
| 561 | - <artifactId>opentracing-util</artifactId> | ||
| 562 | - <groupId>io.opentracing</groupId> | ||
| 563 | - </exclusion> | ||
| 564 | - </exclusions> | ||
| 565 | - </dependency> | ||
| 566 | - <dependency> | ||
| 567 | - <groupId>com.aliyun</groupId> | ||
| 568 | - <artifactId>aliyun-java-sdk-dysmsapi</artifactId> | ||
| 569 | - <version>${aliyun-java-sdk-dysmsapi.version}</version> | ||
| 570 | - </dependency> | ||
| 571 | - <dependency> | ||
| 572 | <groupId>com.tencentcloudapi</groupId> | 550 | <groupId>com.tencentcloudapi</groupId> |
| 573 | <artifactId>tencentcloud-sdk-java-sms</artifactId> | 551 | <artifactId>tencentcloud-sdk-java-sms</artifactId> |
| 574 | <version>${tencentcloud-sdk-java.version}</version> | 552 | <version>${tencentcloud-sdk-java.version}</version> |
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/spring/SpringExpressionUtils.java
| @@ -3,11 +3,15 @@ package cn.iocoder.yudao.framework.common.util.spring; | @@ -3,11 +3,15 @@ package cn.iocoder.yudao.framework.common.util.spring; | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.hutool.core.map.MapUtil; | 4 | import cn.hutool.core.map.MapUtil; |
| 5 | import cn.hutool.core.util.ArrayUtil; | 5 | import cn.hutool.core.util.ArrayUtil; |
| 6 | +import cn.hutool.core.util.StrUtil; | ||
| 7 | +import cn.hutool.extra.spring.SpringUtil; | ||
| 6 | import org.aspectj.lang.JoinPoint; | 8 | import org.aspectj.lang.JoinPoint; |
| 7 | import org.aspectj.lang.reflect.MethodSignature; | 9 | import org.aspectj.lang.reflect.MethodSignature; |
| 10 | +import org.springframework.context.expression.BeanFactoryResolver; | ||
| 8 | import org.springframework.core.DefaultParameterNameDiscoverer; | 11 | import org.springframework.core.DefaultParameterNameDiscoverer; |
| 9 | import org.springframework.core.ParameterNameDiscoverer; | 12 | import org.springframework.core.ParameterNameDiscoverer; |
| 10 | import org.springframework.expression.EvaluationContext; | 13 | import org.springframework.expression.EvaluationContext; |
| 14 | +import org.springframework.expression.Expression; | ||
| 11 | import org.springframework.expression.ExpressionParser; | 15 | import org.springframework.expression.ExpressionParser; |
| 12 | import org.springframework.expression.spel.standard.SpelExpressionParser; | 16 | import org.springframework.expression.spel.standard.SpelExpressionParser; |
| 13 | import org.springframework.expression.spel.support.StandardEvaluationContext; | 17 | import org.springframework.expression.spel.support.StandardEvaluationContext; |
| @@ -86,4 +90,20 @@ public class SpringExpressionUtils { | @@ -86,4 +90,20 @@ public class SpringExpressionUtils { | ||
| 86 | return result; | 90 | return result; |
| 87 | } | 91 | } |
| 88 | 92 | ||
| 93 | + /** | ||
| 94 | + * 从 Bean 工厂,解析 EL 表达式的结果 | ||
| 95 | + * | ||
| 96 | + * @param expressionString EL 表达式 | ||
| 97 | + * @return 执行界面 | ||
| 98 | + */ | ||
| 99 | + public static Object parseExpression(String expressionString) { | ||
| 100 | + if (StrUtil.isBlank(expressionString)) { | ||
| 101 | + return null; | ||
| 102 | + } | ||
| 103 | + Expression expression = EXPRESSION_PARSER.parseExpression(expressionString); | ||
| 104 | + StandardEvaluationContext context = new StandardEvaluationContext(); | ||
| 105 | + context.setBeanResolver(new BeanFactoryResolver(SpringUtil.getApplicationContext())); | ||
| 106 | + return expression.getValue(context); | ||
| 107 | + } | ||
| 108 | + | ||
| 89 | } | 109 | } |
yudao-framework/yudao-spring-boot-starter-web/pom.xml
| @@ -32,6 +32,11 @@ | @@ -32,6 +32,11 @@ | ||
| 32 | <artifactId>spring-boot-configuration-processor</artifactId> | 32 | <artifactId>spring-boot-configuration-processor</artifactId> |
| 33 | <optional>true</optional> | 33 | <optional>true</optional> |
| 34 | </dependency> | 34 | </dependency> |
| 35 | + <dependency> | ||
| 36 | + <groupId>org.aspectj</groupId> | ||
| 37 | + <artifactId>aspectjweaver</artifactId> | ||
| 38 | + <scope>provided</scope> <!-- 解决工具类 SpringExpressionUtils 加载的时候访问不到 org.aspectj.lang.JoinPoint 问题 --> | ||
| 39 | + </dependency> | ||
| 35 | 40 | ||
| 36 | <dependency> | 41 | <dependency> |
| 37 | <groupId>com.github.xiaoymin</groupId> | 42 | <groupId>com.github.xiaoymin</groupId> |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/desensitize/core/base/handler/DesensitizationHandler.java
| 1 | package cn.iocoder.yudao.framework.desensitize.core.base.handler; | 1 | package cn.iocoder.yudao.framework.desensitize.core.base.handler; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.util.ReflectUtil; | ||
| 4 | + | ||
| 3 | import java.lang.annotation.Annotation; | 5 | import java.lang.annotation.Annotation; |
| 4 | 6 | ||
| 5 | /** | 7 | /** |
| @@ -18,4 +20,21 @@ public interface DesensitizationHandler<T extends Annotation> { | @@ -18,4 +20,21 @@ public interface DesensitizationHandler<T extends Annotation> { | ||
| 18 | */ | 20 | */ |
| 19 | String desensitize(String origin, T annotation); | 21 | String desensitize(String origin, T annotation); |
| 20 | 22 | ||
| 23 | + /** | ||
| 24 | + * 是否禁用脱敏的 Spring EL 表达式 | ||
| 25 | + * | ||
| 26 | + * 如果返回 true 则跳过脱敏 | ||
| 27 | + * | ||
| 28 | + * @param annotation 注解信息 | ||
| 29 | + * @return 是否禁用脱敏的 Spring EL 表达式 | ||
| 30 | + */ | ||
| 31 | + default String getDisable(T annotation) { | ||
| 32 | + // 约定:默认就是 enable() 属性。如果不符合,子类重写 | ||
| 33 | + try { | ||
| 34 | + return (String) ReflectUtil.invoke(annotation, "disable"); | ||
| 35 | + } catch (Exception ex) { | ||
| 36 | + return ""; | ||
| 37 | + } | ||
| 38 | + } | ||
| 39 | + | ||
| 21 | } | 40 | } |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/EmailDesensitize.java
| @@ -33,4 +33,12 @@ public @interface EmailDesensitize { | @@ -33,4 +33,12 @@ public @interface EmailDesensitize { | ||
| 33 | * 比如:example@gmail.com 脱敏之后为 e****@gmail.com | 33 | * 比如:example@gmail.com 脱敏之后为 e****@gmail.com |
| 34 | */ | 34 | */ |
| 35 | String replacer() default "$1****$2"; | 35 | String replacer() default "$1****$2"; |
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 是否禁用脱敏 | ||
| 39 | + * | ||
| 40 | + * 支持 Spring EL 表达式,如果返回 true 则跳过脱敏 | ||
| 41 | + */ | ||
| 42 | + String disable() default ""; | ||
| 43 | + | ||
| 36 | } | 44 | } |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/annotation/RegexDesensitize.java
| @@ -35,4 +35,12 @@ public @interface RegexDesensitize { | @@ -35,4 +35,12 @@ public @interface RegexDesensitize { | ||
| 35 | * 脱敏后字符串 ******456789 | 35 | * 脱敏后字符串 ******456789 |
| 36 | */ | 36 | */ |
| 37 | String replacer() default "******"; | 37 | String replacer() default "******"; |
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * 是否禁用脱敏 | ||
| 41 | + * | ||
| 42 | + * 支持 Spring EL 表达式,如果返回 true 则跳过脱敏 | ||
| 43 | + */ | ||
| 44 | + String disable() default ""; | ||
| 45 | + | ||
| 38 | } | 46 | } |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/AbstractRegexDesensitizationHandler.java
| 1 | package cn.iocoder.yudao.framework.desensitize.core.regex.handler; | 1 | package cn.iocoder.yudao.framework.desensitize.core.regex.handler; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.common.util.spring.SpringExpressionUtils; | ||
| 3 | import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; | 4 | import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; |
| 4 | 5 | ||
| 5 | import java.lang.annotation.Annotation; | 6 | import java.lang.annotation.Annotation; |
| @@ -14,6 +15,13 @@ public abstract class AbstractRegexDesensitizationHandler<T extends Annotation> | @@ -14,6 +15,13 @@ public abstract class AbstractRegexDesensitizationHandler<T extends Annotation> | ||
| 14 | 15 | ||
| 15 | @Override | 16 | @Override |
| 16 | public String desensitize(String origin, T annotation) { | 17 | public String desensitize(String origin, T annotation) { |
| 18 | + // 1. 判断是否禁用脱敏 | ||
| 19 | + Object disable = SpringExpressionUtils.parseExpression(getDisable(annotation)); | ||
| 20 | + if (Boolean.TRUE.equals(disable)) { | ||
| 21 | + return origin; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + // 2. 执行脱敏 | ||
| 17 | String regex = getRegex(annotation); | 25 | String regex = getRegex(annotation); |
| 18 | String replacer = getReplacer(annotation); | 26 | String replacer = getReplacer(annotation); |
| 19 | return origin.replaceAll(regex, replacer); | 27 | return origin.replaceAll(regex, replacer); |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/desensitize/core/regex/handler/DefaultRegexDesensitizationHandler.java
| @@ -18,4 +18,10 @@ public class DefaultRegexDesensitizationHandler extends AbstractRegexDesensitiza | @@ -18,4 +18,10 @@ public class DefaultRegexDesensitizationHandler extends AbstractRegexDesensitiza | ||
| 18 | String getReplacer(RegexDesensitize annotation) { | 18 | String getReplacer(RegexDesensitize annotation) { |
| 19 | return annotation.replacer(); | 19 | return annotation.replacer(); |
| 20 | } | 20 | } |
| 21 | + | ||
| 22 | + @Override | ||
| 23 | + public String getDisable(RegexDesensitize annotation) { | ||
| 24 | + return annotation.disable(); | ||
| 25 | + } | ||
| 26 | + | ||
| 21 | } | 27 | } |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/BankCardDesensitize.java
| @@ -37,4 +37,11 @@ public @interface BankCardDesensitize { | @@ -37,4 +37,11 @@ public @interface BankCardDesensitize { | ||
| 37 | */ | 37 | */ |
| 38 | String replacer() default "*"; | 38 | String replacer() default "*"; |
| 39 | 39 | ||
| 40 | + /** | ||
| 41 | + * 是否禁用脱敏 | ||
| 42 | + * | ||
| 43 | + * 支持 Spring EL 表达式,如果返回 true 则跳过脱敏 | ||
| 44 | + */ | ||
| 45 | + String disable() default ""; | ||
| 46 | + | ||
| 40 | } | 47 | } |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/CarLicenseDesensitize.java
| @@ -37,4 +37,11 @@ public @interface CarLicenseDesensitize { | @@ -37,4 +37,11 @@ public @interface CarLicenseDesensitize { | ||
| 37 | */ | 37 | */ |
| 38 | String replacer() default "*"; | 38 | String replacer() default "*"; |
| 39 | 39 | ||
| 40 | + /** | ||
| 41 | + * 是否禁用脱敏 | ||
| 42 | + * | ||
| 43 | + * 支持 Spring EL 表达式,如果返回 true 则跳过脱敏 | ||
| 44 | + */ | ||
| 45 | + String disable() default ""; | ||
| 46 | + | ||
| 40 | } | 47 | } |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/ChineseNameDesensitize.java
| @@ -37,4 +37,11 @@ public @interface ChineseNameDesensitize { | @@ -37,4 +37,11 @@ public @interface ChineseNameDesensitize { | ||
| 37 | */ | 37 | */ |
| 38 | String replacer() default "*"; | 38 | String replacer() default "*"; |
| 39 | 39 | ||
| 40 | + /** | ||
| 41 | + * 是否禁用脱敏 | ||
| 42 | + * | ||
| 43 | + * 支持 Spring EL 表达式,如果返回 true 则跳过脱敏 | ||
| 44 | + */ | ||
| 45 | + String disable() default ""; | ||
| 46 | + | ||
| 40 | } | 47 | } |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/FixedPhoneDesensitize.java
| @@ -37,4 +37,11 @@ public @interface FixedPhoneDesensitize { | @@ -37,4 +37,11 @@ public @interface FixedPhoneDesensitize { | ||
| 37 | */ | 37 | */ |
| 38 | String replacer() default "*"; | 38 | String replacer() default "*"; |
| 39 | 39 | ||
| 40 | + /** | ||
| 41 | + * 是否禁用脱敏 | ||
| 42 | + * | ||
| 43 | + * 支持 Spring EL 表达式,如果返回 true 则跳过脱敏 | ||
| 44 | + */ | ||
| 45 | + String disable() default ""; | ||
| 46 | + | ||
| 40 | } | 47 | } |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/IdCardDesensitize.java
| @@ -37,4 +37,11 @@ public @interface IdCardDesensitize { | @@ -37,4 +37,11 @@ public @interface IdCardDesensitize { | ||
| 37 | */ | 37 | */ |
| 38 | String replacer() default "*"; | 38 | String replacer() default "*"; |
| 39 | 39 | ||
| 40 | + /** | ||
| 41 | + * 是否禁用脱敏 | ||
| 42 | + * | ||
| 43 | + * 支持 Spring EL 表达式,如果返回 true 则跳过脱敏 | ||
| 44 | + */ | ||
| 45 | + String disable() default ""; | ||
| 46 | + | ||
| 40 | } | 47 | } |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/MobileDesensitize.java
| @@ -37,4 +37,11 @@ public @interface MobileDesensitize { | @@ -37,4 +37,11 @@ public @interface MobileDesensitize { | ||
| 37 | */ | 37 | */ |
| 38 | String replacer() default "*"; | 38 | String replacer() default "*"; |
| 39 | 39 | ||
| 40 | + /** | ||
| 41 | + * 是否禁用脱敏 | ||
| 42 | + * | ||
| 43 | + * 支持 Spring EL 表达式,如果返回 true 则跳过脱敏 | ||
| 44 | + */ | ||
| 45 | + String disable() default ""; | ||
| 46 | + | ||
| 40 | } | 47 | } |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/PasswordDesensitize.java
| @@ -39,4 +39,11 @@ public @interface PasswordDesensitize { | @@ -39,4 +39,11 @@ public @interface PasswordDesensitize { | ||
| 39 | */ | 39 | */ |
| 40 | String replacer() default "*"; | 40 | String replacer() default "*"; |
| 41 | 41 | ||
| 42 | + /** | ||
| 43 | + * 是否禁用脱敏 | ||
| 44 | + * | ||
| 45 | + * 支持 Spring EL 表达式,如果返回 true 则跳过脱敏 | ||
| 46 | + */ | ||
| 47 | + String disable() default ""; | ||
| 48 | + | ||
| 42 | } | 49 | } |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/annotation/SliderDesensitize.java
| @@ -40,4 +40,12 @@ public @interface SliderDesensitize { | @@ -40,4 +40,12 @@ public @interface SliderDesensitize { | ||
| 40 | * 前缀保留长度 | 40 | * 前缀保留长度 |
| 41 | */ | 41 | */ |
| 42 | int prefixKeep() default 0; | 42 | int prefixKeep() default 0; |
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * 是否禁用脱敏 | ||
| 46 | + * | ||
| 47 | + * 支持 Spring EL 表达式,如果返回 true 则跳过脱敏 | ||
| 48 | + */ | ||
| 49 | + String disable() default ""; | ||
| 50 | + | ||
| 43 | } | 51 | } |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractSliderDesensitizationHandler.java
| 1 | package cn.iocoder.yudao.framework.desensitize.core.slider.handler; | 1 | package cn.iocoder.yudao.framework.desensitize.core.slider.handler; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.common.util.spring.SpringExpressionUtils; | ||
| 3 | import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; | 4 | import cn.iocoder.yudao.framework.desensitize.core.base.handler.DesensitizationHandler; |
| 4 | 5 | ||
| 5 | import java.lang.annotation.Annotation; | 6 | import java.lang.annotation.Annotation; |
| @@ -14,6 +15,13 @@ public abstract class AbstractSliderDesensitizationHandler<T extends Annotation> | @@ -14,6 +15,13 @@ public abstract class AbstractSliderDesensitizationHandler<T extends Annotation> | ||
| 14 | 15 | ||
| 15 | @Override | 16 | @Override |
| 16 | public String desensitize(String origin, T annotation) { | 17 | public String desensitize(String origin, T annotation) { |
| 18 | + // 1. 判断是否禁用脱敏 | ||
| 19 | + Object disable = SpringExpressionUtils.parseExpression(getDisable(annotation)); | ||
| 20 | + if (Boolean.FALSE.equals(disable)) { | ||
| 21 | + return origin; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + // 2. 执行脱敏 | ||
| 17 | int prefixKeep = getPrefixKeep(annotation); | 25 | int prefixKeep = getPrefixKeep(annotation); |
| 18 | int suffixKeep = getSuffixKeep(annotation); | 26 | int suffixKeep = getSuffixKeep(annotation); |
| 19 | String replacer = getReplacer(annotation); | 27 | String replacer = getReplacer(annotation); |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/BankCardDesensitization.java
| @@ -24,4 +24,9 @@ public class BankCardDesensitization extends AbstractSliderDesensitizationHandle | @@ -24,4 +24,9 @@ public class BankCardDesensitization extends AbstractSliderDesensitizationHandle | ||
| 24 | return annotation.replacer(); | 24 | return annotation.replacer(); |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | + @Override | ||
| 28 | + public String getDisable(BankCardDesensitize annotation) { | ||
| 29 | + return ""; | ||
| 30 | + } | ||
| 31 | + | ||
| 27 | } | 32 | } |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/CarLicenseDesensitization.java
| @@ -8,6 +8,7 @@ import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.CarLicenseD | @@ -8,6 +8,7 @@ import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.CarLicenseD | ||
| 8 | * @author gaibu | 8 | * @author gaibu |
| 9 | */ | 9 | */ |
| 10 | public class CarLicenseDesensitization extends AbstractSliderDesensitizationHandler<CarLicenseDesensitize> { | 10 | public class CarLicenseDesensitization extends AbstractSliderDesensitizationHandler<CarLicenseDesensitize> { |
| 11 | + | ||
| 11 | @Override | 12 | @Override |
| 12 | Integer getPrefixKeep(CarLicenseDesensitize annotation) { | 13 | Integer getPrefixKeep(CarLicenseDesensitize annotation) { |
| 13 | return annotation.prefixKeep(); | 14 | return annotation.prefixKeep(); |
| @@ -22,4 +23,10 @@ public class CarLicenseDesensitization extends AbstractSliderDesensitizationHand | @@ -22,4 +23,10 @@ public class CarLicenseDesensitization extends AbstractSliderDesensitizationHand | ||
| 22 | String getReplacer(CarLicenseDesensitize annotation) { | 23 | String getReplacer(CarLicenseDesensitize annotation) { |
| 23 | return annotation.replacer(); | 24 | return annotation.replacer(); |
| 24 | } | 25 | } |
| 26 | + | ||
| 27 | + @Override | ||
| 28 | + public String getDisable(CarLicenseDesensitize annotation) { | ||
| 29 | + return annotation.disable(); | ||
| 30 | + } | ||
| 31 | + | ||
| 25 | } | 32 | } |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/DefaultDesensitizationHandler.java
| @@ -8,6 +8,7 @@ import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.SliderDesen | @@ -8,6 +8,7 @@ import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.SliderDesen | ||
| 8 | * @author gaibu | 8 | * @author gaibu |
| 9 | */ | 9 | */ |
| 10 | public class DefaultDesensitizationHandler extends AbstractSliderDesensitizationHandler<SliderDesensitize> { | 10 | public class DefaultDesensitizationHandler extends AbstractSliderDesensitizationHandler<SliderDesensitize> { |
| 11 | + | ||
| 11 | @Override | 12 | @Override |
| 12 | Integer getPrefixKeep(SliderDesensitize annotation) { | 13 | Integer getPrefixKeep(SliderDesensitize annotation) { |
| 13 | return annotation.prefixKeep(); | 14 | return annotation.prefixKeep(); |
| @@ -22,4 +23,5 @@ public class DefaultDesensitizationHandler extends AbstractSliderDesensitization | @@ -22,4 +23,5 @@ public class DefaultDesensitizationHandler extends AbstractSliderDesensitization | ||
| 22 | String getReplacer(SliderDesensitize annotation) { | 23 | String getReplacer(SliderDesensitize annotation) { |
| 23 | return annotation.replacer(); | 24 | return annotation.replacer(); |
| 24 | } | 25 | } |
| 26 | + | ||
| 25 | } | 27 | } |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/FixedPhoneDesensitization.java
| @@ -8,6 +8,7 @@ import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.FixedPhoneD | @@ -8,6 +8,7 @@ import cn.iocoder.yudao.framework.desensitize.core.slider.annotation.FixedPhoneD | ||
| 8 | * @author gaibu | 8 | * @author gaibu |
| 9 | */ | 9 | */ |
| 10 | public class FixedPhoneDesensitization extends AbstractSliderDesensitizationHandler<FixedPhoneDesensitize> { | 10 | public class FixedPhoneDesensitization extends AbstractSliderDesensitizationHandler<FixedPhoneDesensitize> { |
| 11 | + | ||
| 11 | @Override | 12 | @Override |
| 12 | Integer getPrefixKeep(FixedPhoneDesensitize annotation) { | 13 | Integer getPrefixKeep(FixedPhoneDesensitize annotation) { |
| 13 | return annotation.prefixKeep(); | 14 | return annotation.prefixKeep(); |
| @@ -22,4 +23,5 @@ public class FixedPhoneDesensitization extends AbstractSliderDesensitizationHand | @@ -22,4 +23,5 @@ public class FixedPhoneDesensitization extends AbstractSliderDesensitizationHand | ||
| 22 | String getReplacer(FixedPhoneDesensitize annotation) { | 23 | String getReplacer(FixedPhoneDesensitize annotation) { |
| 23 | return annotation.replacer(); | 24 | return annotation.replacer(); |
| 24 | } | 25 | } |
| 26 | + | ||
| 25 | } | 27 | } |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/IdCardDesensitization.java
| @@ -22,4 +22,5 @@ public class IdCardDesensitization extends AbstractSliderDesensitizationHandler< | @@ -22,4 +22,5 @@ public class IdCardDesensitization extends AbstractSliderDesensitizationHandler< | ||
| 22 | String getReplacer(IdCardDesensitize annotation) { | 22 | String getReplacer(IdCardDesensitize annotation) { |
| 23 | return annotation.replacer(); | 23 | return annotation.replacer(); |
| 24 | } | 24 | } |
| 25 | + | ||
| 25 | } | 26 | } |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/MobileDesensitization.java
| @@ -23,4 +23,5 @@ public class MobileDesensitization extends AbstractSliderDesensitizationHandler< | @@ -23,4 +23,5 @@ public class MobileDesensitization extends AbstractSliderDesensitizationHandler< | ||
| 23 | String getReplacer(MobileDesensitize annotation) { | 23 | String getReplacer(MobileDesensitize annotation) { |
| 24 | return annotation.replacer(); | 24 | return annotation.replacer(); |
| 25 | } | 25 | } |
| 26 | + | ||
| 26 | } | 27 | } |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/PasswordDesensitization.java
| @@ -22,4 +22,5 @@ public class PasswordDesensitization extends AbstractSliderDesensitizationHandle | @@ -22,4 +22,5 @@ public class PasswordDesensitization extends AbstractSliderDesensitizationHandle | ||
| 22 | String getReplacer(PasswordDesensitize annotation) { | 22 | String getReplacer(PasswordDesensitize annotation) { |
| 23 | return annotation.replacer(); | 23 | return annotation.replacer(); |
| 24 | } | 24 | } |
| 25 | + | ||
| 25 | } | 26 | } |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/MessageTemplateConstants.java
| @@ -9,6 +9,6 @@ public interface MessageTemplateConstants { | @@ -9,6 +9,6 @@ public interface MessageTemplateConstants { | ||
| 9 | 9 | ||
| 10 | //======================= 小程序订阅消息模版 ======================= | 10 | //======================= 小程序订阅消息模版 ======================= |
| 11 | 11 | ||
| 12 | - String COMBINATION_RESULT = "拼团结果通知"; | 12 | + String COMBINATION_SUCCESS = "拼团结果通知"; |
| 13 | 13 | ||
| 14 | } | 14 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java
| @@ -44,7 +44,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. | @@ -44,7 +44,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils. | ||
| 44 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.afterNow; | 44 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.afterNow; |
| 45 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.beforeNow; | 45 | import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.beforeNow; |
| 46 | import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; | 46 | import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; |
| 47 | -import static cn.iocoder.yudao.module.promotion.enums.MessageTemplateConstants.COMBINATION_RESULT; | 47 | +import static cn.iocoder.yudao.module.promotion.enums.MessageTemplateConstants.COMBINATION_SUCCESS; |
| 48 | 48 | ||
| 49 | // TODO 芋艿:等拼团记录做完,完整 review 下 | 49 | // TODO 芋艿:等拼团记录做完,完整 review 下 |
| 50 | 50 | ||
| @@ -212,10 +212,10 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | @@ -212,10 +212,10 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | ||
| 212 | } | 212 | } |
| 213 | updateRecords.add(updateRecord); | 213 | updateRecords.add(updateRecord); |
| 214 | }); | 214 | }); |
| 215 | - Boolean result = combinationRecordMapper.updateBatch(updateRecords); | 215 | + Boolean updateSuccess = combinationRecordMapper.updateBatch(updateRecords); |
| 216 | 216 | ||
| 217 | // 3. 拼团成功发送订阅消息 | 217 | // 3. 拼团成功发送订阅消息 |
| 218 | - if (result && isFull) { | 218 | + if (updateSuccess && isFull) { |
| 219 | records.forEach(item -> { | 219 | records.forEach(item -> { |
| 220 | getSelf().sendCombinationResultMessage(item); | 220 | getSelf().sendCombinationResultMessage(item); |
| 221 | }); | 221 | }); |
| @@ -227,7 +227,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | @@ -227,7 +227,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { | ||
| 227 | // 构建并发送模版消息 | 227 | // 构建并发送模版消息 |
| 228 | socialClientApi.sendWxaSubscribeMessage(new SocialWxaSubscribeMessageSendReqDTO() | 228 | socialClientApi.sendWxaSubscribeMessage(new SocialWxaSubscribeMessageSendReqDTO() |
| 229 | .setUserId(record.getUserId()).setUserType(UserTypeEnum.MEMBER.getValue()) | 229 | .setUserId(record.getUserId()).setUserType(UserTypeEnum.MEMBER.getValue()) |
| 230 | - .setTemplateTitle(COMBINATION_RESULT) | 230 | + .setTemplateTitle(COMBINATION_SUCCESS) |
| 231 | .setPage("pages/order/detail?id=" + record.getOrderId()) // 订单详情页 | 231 | .setPage("pages/order/detail?id=" + record.getOrderId()) // 订单详情页 |
| 232 | .addMessage("thing1", "商品拼团活动") // 活动标题 | 232 | .addMessage("thing1", "商品拼团活动") // 活动标题 |
| 233 | .addMessage("thing2", "恭喜您拼团成功!我们将尽快为您发货。")); // 温馨提示 | 233 | .addMessage("thing2", "恭喜您拼团成功!我们将尽快为您发货。")); // 温馨提示 |
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/MessageTemplateConstants.java
| @@ -7,15 +7,15 @@ package cn.iocoder.yudao.module.trade.enums; | @@ -7,15 +7,15 @@ package cn.iocoder.yudao.module.trade.enums; | ||
| 7 | */ | 7 | */ |
| 8 | public interface MessageTemplateConstants { | 8 | public interface MessageTemplateConstants { |
| 9 | 9 | ||
| 10 | - //======================= 短信消息模版 ======================= | 10 | + // ======================= 短信消息模版 ======================= |
| 11 | 11 | ||
| 12 | - String ORDER_DELIVERY = "order_delivery"; // 短信模版编号 | 12 | + String SMS_ORDER_DELIVERY = "order_delivery"; // 短信模版编号 |
| 13 | 13 | ||
| 14 | - String BROKERAGE_WITHDRAW_AUDIT_APPROVE = "brokerage_withdraw_audit_approve"; // 佣金提现(审核通过) | ||
| 15 | - String BROKERAGE_WITHDRAW_AUDIT_REJECT = "brokerage_withdraw_audit_reject"; // 佣金提现(审核不通过) | 14 | + String SMS_BROKERAGE_WITHDRAW_AUDIT_APPROVE = "brokerage_withdraw_audit_approve"; // 佣金提现(审核通过) |
| 15 | + String SMS_BROKERAGE_WITHDRAW_AUDIT_REJECT = "brokerage_withdraw_audit_reject"; // 佣金提现(审核不通过) | ||
| 16 | 16 | ||
| 17 | - //======================= 小程序订阅消息模版 ======================= | 17 | + // ======================= 小程序订阅消息模版 ======================= |
| 18 | 18 | ||
| 19 | - String DELIVERY_ORDER = "订单发货通知"; | 19 | + String WXA_ORDER_DELIVERY = "订单发货通知"; |
| 20 | 20 | ||
| 21 | } | 21 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java
| @@ -77,14 +77,14 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService { | @@ -77,14 +77,14 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService { | ||
| 77 | 77 | ||
| 78 | String templateCode; | 78 | String templateCode; |
| 79 | if (BrokerageWithdrawStatusEnum.AUDIT_SUCCESS.equals(status)) { | 79 | if (BrokerageWithdrawStatusEnum.AUDIT_SUCCESS.equals(status)) { |
| 80 | - templateCode = MessageTemplateConstants.BROKERAGE_WITHDRAW_AUDIT_APPROVE; | 80 | + templateCode = MessageTemplateConstants.SMS_BROKERAGE_WITHDRAW_AUDIT_APPROVE; |
| 81 | // 3.1 通过时佣金转余额 | 81 | // 3.1 通过时佣金转余额 |
| 82 | if (BrokerageWithdrawTypeEnum.WALLET.getType().equals(withdraw.getType())) { | 82 | if (BrokerageWithdrawTypeEnum.WALLET.getType().equals(withdraw.getType())) { |
| 83 | // todo 疯狂: | 83 | // todo 疯狂: |
| 84 | } | 84 | } |
| 85 | // TODO 疯狂:调用转账接口 | 85 | // TODO 疯狂:调用转账接口 |
| 86 | } else if (BrokerageWithdrawStatusEnum.AUDIT_FAIL.equals(status)) { | 86 | } else if (BrokerageWithdrawStatusEnum.AUDIT_FAIL.equals(status)) { |
| 87 | - templateCode = MessageTemplateConstants.BROKERAGE_WITHDRAW_AUDIT_REJECT; | 87 | + templateCode = MessageTemplateConstants.SMS_BROKERAGE_WITHDRAW_AUDIT_REJECT; |
| 88 | // 3.2 驳回时需要退还用户佣金 | 88 | // 3.2 驳回时需要退还用户佣金 |
| 89 | brokerageRecordService.addBrokerage(withdraw.getUserId(), BrokerageRecordBizTypeEnum.WITHDRAW_REJECT, | 89 | brokerageRecordService.addBrokerage(withdraw.getUserId(), BrokerageRecordBizTypeEnum.WITHDRAW_REJECT, |
| 90 | String.valueOf(withdraw.getId()), withdraw.getPrice(), BrokerageRecordBizTypeEnum.WITHDRAW_REJECT.getTitle()); | 90 | String.valueOf(withdraw.getId()), withdraw.getPrice(), BrokerageRecordBizTypeEnum.WITHDRAW_REJECT.getTitle()); |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/message/TradeMessageServiceImpl.java
| @@ -37,7 +37,7 @@ public class TradeMessageServiceImpl implements TradeMessageService { | @@ -37,7 +37,7 @@ public class TradeMessageServiceImpl implements TradeMessageService { | ||
| 37 | notifyMessageSendApi.sendSingleMessageToMember( | 37 | notifyMessageSendApi.sendSingleMessageToMember( |
| 38 | new NotifySendSingleToUserReqDTO() | 38 | new NotifySendSingleToUserReqDTO() |
| 39 | .setUserId(reqBO.getUserId()) | 39 | .setUserId(reqBO.getUserId()) |
| 40 | - .setTemplateCode(MessageTemplateConstants.ORDER_DELIVERY) | 40 | + .setTemplateCode(MessageTemplateConstants.SMS_ORDER_DELIVERY) |
| 41 | .setTemplateParams(msgMap)); | 41 | .setTemplateParams(msgMap)); |
| 42 | } | 42 | } |
| 43 | 43 |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java
| @@ -7,6 +7,7 @@ import cn.hutool.core.map.MapUtil; | @@ -7,6 +7,7 @@ import cn.hutool.core.map.MapUtil; | ||
| 7 | import cn.hutool.core.util.ObjUtil; | 7 | import cn.hutool.core.util.ObjUtil; |
| 8 | import cn.hutool.core.util.ObjectUtil; | 8 | import cn.hutool.core.util.ObjectUtil; |
| 9 | import cn.hutool.core.util.RandomUtil; | 9 | import cn.hutool.core.util.RandomUtil; |
| 10 | +import cn.hutool.core.util.StrUtil; | ||
| 10 | import cn.hutool.extra.spring.SpringUtil; | 11 | import cn.hutool.extra.spring.SpringUtil; |
| 11 | import cn.iocoder.yudao.framework.common.core.KeyValue; | 12 | import cn.iocoder.yudao.framework.common.core.KeyValue; |
| 12 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | 13 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| @@ -71,7 +72,7 @@ import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.min | @@ -71,7 +72,7 @@ import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.min | ||
| 71 | import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; | 72 | import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; |
| 72 | import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getTerminal; | 73 | import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getTerminal; |
| 73 | import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; | 74 | import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; |
| 74 | -import static cn.iocoder.yudao.module.trade.enums.MessageTemplateConstants.DELIVERY_ORDER; | 75 | +import static cn.iocoder.yudao.module.trade.enums.MessageTemplateConstants.WXA_ORDER_DELIVERY; |
| 75 | 76 | ||
| 76 | /** | 77 | /** |
| 77 | * 交易订单【写】Service 实现类 | 78 | * 交易订单【写】Service 实现类 |
| @@ -384,12 +385,12 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | @@ -384,12 +385,12 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | ||
| 384 | Long orderId = order.getId(); | 385 | Long orderId = order.getId(); |
| 385 | socialClientApi.sendWxaSubscribeMessage(new SocialWxaSubscribeMessageSendReqDTO() | 386 | socialClientApi.sendWxaSubscribeMessage(new SocialWxaSubscribeMessageSendReqDTO() |
| 386 | .setUserId(order.getUserId()).setUserType(UserTypeEnum.MEMBER.getValue()) | 387 | .setUserId(order.getUserId()).setUserType(UserTypeEnum.MEMBER.getValue()) |
| 387 | - .setTemplateTitle(DELIVERY_ORDER) | 388 | + .setTemplateTitle(WXA_ORDER_DELIVERY) |
| 388 | .setPage("pages/order/detail?id=" + orderId) // 订单详情页 | 389 | .setPage("pages/order/detail?id=" + orderId) // 订单详情页 |
| 389 | .addMessage("character_string3", String.valueOf(orderId)) // 订单编号 | 390 | .addMessage("character_string3", String.valueOf(orderId)) // 订单编号 |
| 390 | .addMessage("phrase6", TradeOrderStatusEnum.DELIVERED.getName()) // 订单状态 | 391 | .addMessage("phrase6", TradeOrderStatusEnum.DELIVERED.getName()) // 订单状态 |
| 391 | .addMessage("date4", LocalDateTimeUtil.formatNormal(LocalDateTime.now()))// 发货时间 | 392 | .addMessage("date4", LocalDateTimeUtil.formatNormal(LocalDateTime.now()))// 发货时间 |
| 392 | - .addMessage("character_string5", deliveryReqVO.getLogisticsNo()) // 快递单号 | 393 | + .addMessage("character_string5", StrUtil.blankToDefault(deliveryReqVO.getLogisticsNo(), "-")) // 快递单号 |
| 393 | .addMessage("thing9", order.getReceiverDetailAddress())); // 收货地址 | 394 | .addMessage("thing9", order.getReceiverDetailAddress())); // 收货地址 |
| 394 | } | 395 | } |
| 395 | 396 |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/AppSocialUserController.java
| @@ -63,16 +63,16 @@ public class AppSocialUserController { | @@ -63,16 +63,16 @@ public class AppSocialUserController { | ||
| 63 | 63 | ||
| 64 | @PostMapping("/wxa-qrcode") | 64 | @PostMapping("/wxa-qrcode") |
| 65 | @Operation(summary = "获得微信小程序码(base64 image)") | 65 | @Operation(summary = "获得微信小程序码(base64 image)") |
| 66 | - public CommonResult<String> getWxaQrcode(@RequestBody @Valid AppSocialWxQrcodeReqVO reqVO) { | 66 | + public CommonResult<String> getWxaQrcode(@RequestBody @Valid AppSocialWxaQrcodeReqVO reqVO) { |
| 67 | byte[] wxQrcode = socialClientApi.getWxaQrcode(BeanUtils.toBean(reqVO, SocialWxQrcodeReqDTO.class)); | 67 | byte[] wxQrcode = socialClientApi.getWxaQrcode(BeanUtils.toBean(reqVO, SocialWxQrcodeReqDTO.class)); |
| 68 | return success(Base64.encode(wxQrcode)); | 68 | return success(Base64.encode(wxQrcode)); |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | @GetMapping("/get-subscribe-template-list") | 71 | @GetMapping("/get-subscribe-template-list") |
| 72 | @Operation(summary = "获得微信小程订阅模板列表") | 72 | @Operation(summary = "获得微信小程订阅模板列表") |
| 73 | - public CommonResult<List<AppSocialWxSubscribeTemplateRespVO>> getSubscribeTemplateList() { | 73 | + public CommonResult<List<AppSocialWxaSubscribeTemplateRespVO>> getSubscribeTemplateList() { |
| 74 | List<SocialWxaSubscribeTemplateRespDTO> template = socialClientApi.getWxaSubscribeTemplateList(UserTypeEnum.MEMBER.getValue()); | 74 | List<SocialWxaSubscribeTemplateRespDTO> template = socialClientApi.getWxaSubscribeTemplateList(UserTypeEnum.MEMBER.getValue()); |
| 75 | - return success(BeanUtils.toBean(template, AppSocialWxSubscribeTemplateRespVO.class)); | 75 | + return success(BeanUtils.toBean(template, AppSocialWxaSubscribeTemplateRespVO.class)); |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | } | 78 | } |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialWxQrcodeReqVO.java renamed to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialWxaQrcodeReqVO.java
| @@ -7,7 +7,7 @@ import lombok.Data; | @@ -7,7 +7,7 @@ import lombok.Data; | ||
| 7 | 7 | ||
| 8 | @Schema(description = "用户 APP - 获得获取小程序码 Request VO") | 8 | @Schema(description = "用户 APP - 获得获取小程序码 Request VO") |
| 9 | @Data | 9 | @Data |
| 10 | -public class AppSocialWxQrcodeReqVO { | 10 | +public class AppSocialWxaQrcodeReqVO { |
| 11 | 11 | ||
| 12 | /** | 12 | /** |
| 13 | * 页面路径不能携带参数(参数请放在scene字段里) | 13 | * 页面路径不能携带参数(参数请放在scene字段里) |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialWxSubscribeTemplateRespVO.java renamed to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialWxaSubscribeTemplateRespVO.java
| @@ -5,7 +5,7 @@ import lombok.Data; | @@ -5,7 +5,7 @@ import lombok.Data; | ||
| 5 | 5 | ||
| 6 | @Schema(description = "用户 APP - 获得小程序订阅模版 Response VO") | 6 | @Schema(description = "用户 APP - 获得小程序订阅模版 Response VO") |
| 7 | @Data | 7 | @Data |
| 8 | -public class AppSocialWxSubscribeTemplateRespVO { | 8 | +public class AppSocialWxaSubscribeTemplateRespVO { |
| 9 | 9 | ||
| 10 | @Schema(description = "模版编号", requiredMode = Schema.RequiredMode.REQUIRED, | 10 | @Schema(description = "模版编号", requiredMode = Schema.RequiredMode.REQUIRED, |
| 11 | example = "9Aw5ZV1j9xdWTFEkqCpZ7mIBbSC34khK55OtzUPl0rU") | 11 | example = "9Aw5ZV1j9xdWTFEkqCpZ7mIBbSC34khK55OtzUPl0rU") |
yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/MessageTemplateConstants.java
| @@ -7,8 +7,8 @@ package cn.iocoder.yudao.module.pay.enums; | @@ -7,8 +7,8 @@ package cn.iocoder.yudao.module.pay.enums; | ||
| 7 | */ | 7 | */ |
| 8 | public interface MessageTemplateConstants { | 8 | public interface MessageTemplateConstants { |
| 9 | 9 | ||
| 10 | - //======================= 小程序订阅消息 ======================= | 10 | + // ======================= 小程序订阅消息 ======================= |
| 11 | 11 | ||
| 12 | - String WALLET_RECHARGER_PAID = "充值成功通知"; | 12 | + String WXA_WALLET_RECHARGER_PAID = "充值成功通知"; |
| 13 | 13 | ||
| 14 | } | 14 | } |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java
| @@ -39,7 +39,7 @@ import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString | @@ -39,7 +39,7 @@ import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString | ||
| 39 | import static cn.iocoder.yudao.framework.common.util.number.MoneyUtils.fenToYuanStr; | 39 | import static cn.iocoder.yudao.framework.common.util.number.MoneyUtils.fenToYuanStr; |
| 40 | import static cn.iocoder.yudao.module.pay.convert.wallet.PayWalletRechargeConvert.INSTANCE; | 40 | import static cn.iocoder.yudao.module.pay.convert.wallet.PayWalletRechargeConvert.INSTANCE; |
| 41 | import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*; | 41 | import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*; |
| 42 | -import static cn.iocoder.yudao.module.pay.enums.MessageTemplateConstants.WALLET_RECHARGER_PAID; | 42 | +import static cn.iocoder.yudao.module.pay.enums.MessageTemplateConstants.WXA_WALLET_RECHARGER_PAID; |
| 43 | import static cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum.*; | 43 | import static cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum.*; |
| 44 | 44 | ||
| 45 | /** | 45 | /** |
| @@ -147,7 +147,7 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService { | @@ -147,7 +147,7 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService { | ||
| 147 | // 2. 构建并发送模版消息 | 147 | // 2. 构建并发送模版消息 |
| 148 | socialClientApi.sendWxaSubscribeMessage(new SocialWxaSubscribeMessageSendReqDTO() | 148 | socialClientApi.sendWxaSubscribeMessage(new SocialWxaSubscribeMessageSendReqDTO() |
| 149 | .setUserId(wallet.getUserId()).setUserType(wallet.getUserType()) | 149 | .setUserId(wallet.getUserId()).setUserType(wallet.getUserType()) |
| 150 | - .setTemplateTitle(WALLET_RECHARGER_PAID) | 150 | + .setTemplateTitle(WXA_WALLET_RECHARGER_PAID) |
| 151 | .setPage("pages/user/wallet/money") // 钱包详情界面 | 151 | .setPage("pages/user/wallet/money") // 钱包详情界面 |
| 152 | .addMessage("character_string1", String.valueOf(payOrderId)) // 支付单编号 | 152 | .addMessage("character_string1", String.valueOf(payOrderId)) // 支付单编号 |
| 153 | .addMessage("amount2", fenToYuanStr(walletRecharge.getTotalPrice())) // 充值金额 | 153 | .addMessage("amount2", fenToYuanStr(walletRecharge.getTotalPrice())) // 充值金额 |
yudao-module-system/yudao-module-system-biz/pom.xml
| @@ -111,19 +111,6 @@ | @@ -111,19 +111,6 @@ | ||
| 111 | </dependency> | 111 | </dependency> |
| 112 | 112 | ||
| 113 | <dependency> | 113 | <dependency> |
| 114 | - <groupId>com.aliyun</groupId> | ||
| 115 | - <artifactId>aliyun-java-sdk-core</artifactId> <!-- 短信(阿里云) --> | ||
| 116 | - </dependency> | ||
| 117 | - <dependency> | ||
| 118 | - <groupId>com.aliyun</groupId> | ||
| 119 | - <artifactId>aliyun-java-sdk-dysmsapi</artifactId> <!-- 短信(阿里云) --> | ||
| 120 | - </dependency> | ||
| 121 | - <dependency> | ||
| 122 | - <groupId>com.tencentcloudapi</groupId> | ||
| 123 | - <artifactId>tencentcloud-sdk-java-sms</artifactId> <!-- 短信(腾讯云) --> | ||
| 124 | - </dependency> | ||
| 125 | - | ||
| 126 | - <dependency> | ||
| 127 | <groupId>com.xingyuv</groupId> | 114 | <groupId>com.xingyuv</groupId> |
| 128 | <artifactId>spring-boot-starter-captcha-plus</artifactId> <!-- 验证码,一般用于登录使用 --> | 115 | <artifactId>spring-boot-starter-captcha-plus</artifactId> <!-- 验证码,一般用于登录使用 --> |
| 129 | </dependency> | 116 | </dependency> |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialClientApiImpl.java
| @@ -8,6 +8,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | @@ -8,6 +8,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 8 | import cn.iocoder.yudao.module.system.api.social.dto.*; | 8 | import cn.iocoder.yudao.module.system.api.social.dto.*; |
| 9 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; | 9 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; |
| 10 | import cn.iocoder.yudao.module.system.service.social.SocialClientService; | 10 | import cn.iocoder.yudao.module.system.service.social.SocialClientService; |
| 11 | +import cn.iocoder.yudao.module.system.service.social.SocialUserService; | ||
| 11 | import jakarta.annotation.Resource; | 12 | import jakarta.annotation.Resource; |
| 12 | import lombok.extern.slf4j.Slf4j; | 13 | import lombok.extern.slf4j.Slf4j; |
| 13 | import me.chanjar.weixin.common.bean.WxJsapiSignature; | 14 | import me.chanjar.weixin.common.bean.WxJsapiSignature; |
| @@ -33,7 +34,7 @@ public class SocialClientApiImpl implements SocialClientApi { | @@ -33,7 +34,7 @@ public class SocialClientApiImpl implements SocialClientApi { | ||
| 33 | @Resource | 34 | @Resource |
| 34 | private SocialClientService socialClientService; | 35 | private SocialClientService socialClientService; |
| 35 | @Resource | 36 | @Resource |
| 36 | - public SocialUserApi socialUserApi; | 37 | + private SocialUserService socialUserService; |
| 37 | 38 | ||
| 38 | @Override | 39 | @Override |
| 39 | public String getAuthorizeUrl(Integer socialType, Integer userType, String redirectUri) { | 40 | public String getAuthorizeUrl(Integer socialType, Integer userType, String redirectUri) { |
| @@ -68,29 +69,29 @@ public class SocialClientApiImpl implements SocialClientApi { | @@ -68,29 +69,29 @@ public class SocialClientApiImpl implements SocialClientApi { | ||
| 68 | @Override | 69 | @Override |
| 69 | public void sendWxaSubscribeMessage(SocialWxaSubscribeMessageSendReqDTO reqDTO) { | 70 | public void sendWxaSubscribeMessage(SocialWxaSubscribeMessageSendReqDTO reqDTO) { |
| 70 | // 1.1 获得订阅模版列表 | 71 | // 1.1 获得订阅模版列表 |
| 71 | - List<SocialWxaSubscribeTemplateRespDTO> templateList = getWxaSubscribeTemplateList(reqDTO.getUserType()); | 72 | + List<TemplateInfo> templateList = socialClientService.getSubscribeTemplateList(reqDTO.getUserType()); |
| 72 | if (CollUtil.isEmpty(templateList)) { | 73 | if (CollUtil.isEmpty(templateList)) { |
| 73 | log.warn("[sendSubscribeMessage][reqDTO({}) 发送订阅消息失败,原因:没有找到订阅模板]", reqDTO); | 74 | log.warn("[sendSubscribeMessage][reqDTO({}) 发送订阅消息失败,原因:没有找到订阅模板]", reqDTO); |
| 74 | return; | 75 | return; |
| 75 | } | 76 | } |
| 76 | // 1.2 获得需要使用的模版 | 77 | // 1.2 获得需要使用的模版 |
| 77 | - SocialWxaSubscribeTemplateRespDTO template = findOne(templateList, item -> | 78 | + TemplateInfo template = findOne(templateList, item -> |
| 78 | ObjUtil.equal(item.getTitle(), reqDTO.getTemplateTitle())); | 79 | ObjUtil.equal(item.getTitle(), reqDTO.getTemplateTitle())); |
| 79 | if (template == null) { | 80 | if (template == null) { |
| 80 | - log.warn("[sendSubscribeMessage][reqDTO({}) 发送订阅消息失败,原因:没有找到订阅模板]", reqDTO); | 81 | + log.warn("[sendWxaSubscribeMessage][reqDTO({}) 发送订阅消息失败,原因:没有找到订阅模板]", reqDTO); |
| 81 | return; | 82 | return; |
| 82 | } | 83 | } |
| 83 | 84 | ||
| 84 | // 2. 获得社交用户 | 85 | // 2. 获得社交用户 |
| 85 | - SocialUserRespDTO socialUser = socialUserApi.getSocialUserByUserId(reqDTO.getUserType(), reqDTO.getUserId(), | 86 | + SocialUserRespDTO socialUser = socialUserService.getSocialUserByUserId(reqDTO.getUserType(), reqDTO.getUserId(), |
| 86 | SocialTypeEnum.WECHAT_MINI_APP.getType()); | 87 | SocialTypeEnum.WECHAT_MINI_APP.getType()); |
| 87 | if (StrUtil.isBlankIfStr(socialUser.getOpenid())) { | 88 | if (StrUtil.isBlankIfStr(socialUser.getOpenid())) { |
| 88 | - log.warn("[sendSubscribeMessage][reqDTO({}) 发送订阅消息失败,原因:会员 openid 缺失]", reqDTO); | 89 | + log.warn("[sendWxaSubscribeMessage][reqDTO({}) 发送订阅消息失败,原因:会员 openid 缺失]", reqDTO); |
| 89 | return; | 90 | return; |
| 90 | } | 91 | } |
| 91 | 92 | ||
| 92 | // 3. 发送订阅消息 | 93 | // 3. 发送订阅消息 |
| 93 | - socialClientService.sendSubscribeMessage(reqDTO, template.getId(), socialUser.getOpenid()); | 94 | + socialClientService.sendSubscribeMessage(reqDTO, template.getPriTmplId(), socialUser.getOpenid()); |
| 94 | } | 95 | } |
| 95 | 96 | ||
| 96 | } | 97 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/sms/core/client/SmsClient.java
| @@ -46,6 +46,8 @@ public interface SmsClient { | @@ -46,6 +46,8 @@ public interface SmsClient { | ||
| 46 | /** | 46 | /** |
| 47 | * 查询指定的短信模板 | 47 | * 查询指定的短信模板 |
| 48 | * | 48 | * |
| 49 | + * 如果查询失败,则返回 null 空 | ||
| 50 | + * | ||
| 49 | * @param apiTemplateId 短信 API 的模板编号 | 51 | * @param apiTemplateId 短信 API 的模板编号 |
| 50 | * @return 短信模板 | 52 | * @return 短信模板 |
| 51 | */ | 53 | */ |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/sms/core/client/impl/AliyunSmsClient.java
| 1 | package cn.iocoder.yudao.module.system.framework.sms.core.client.impl; | 1 | package cn.iocoder.yudao.module.system.framework.sms.core.client.impl; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.date.format.FastDateFormat; | ||
| 3 | import cn.hutool.core.lang.Assert; | 4 | import cn.hutool.core.lang.Assert; |
| 5 | +import cn.hutool.core.util.IdUtil; | ||
| 6 | +import cn.hutool.core.util.ObjectUtil; | ||
| 7 | +import cn.hutool.core.util.URLUtil; | ||
| 8 | +import cn.hutool.crypto.SecureUtil; | ||
| 9 | +import cn.hutool.crypto.digest.DigestUtil; | ||
| 10 | +import cn.hutool.http.HttpRequest; | ||
| 11 | +import cn.hutool.http.HttpResponse; | ||
| 12 | +import cn.hutool.json.JSONArray; | ||
| 13 | +import cn.hutool.json.JSONObject; | ||
| 14 | +import cn.hutool.json.JSONUtil; | ||
| 4 | import cn.iocoder.yudao.framework.common.core.KeyValue; | 15 | import cn.iocoder.yudao.framework.common.core.KeyValue; |
| 5 | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | 16 | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; |
| 6 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | 17 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| @@ -9,27 +20,13 @@ import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsSendRespD | @@ -9,27 +20,13 @@ import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsSendRespD | ||
| 9 | import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsTemplateRespDTO; | 20 | import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsTemplateRespDTO; |
| 10 | import cn.iocoder.yudao.module.system.framework.sms.core.enums.SmsTemplateAuditStatusEnum; | 21 | import cn.iocoder.yudao.module.system.framework.sms.core.enums.SmsTemplateAuditStatusEnum; |
| 11 | import cn.iocoder.yudao.module.system.framework.sms.core.property.SmsChannelProperties; | 22 | import cn.iocoder.yudao.module.system.framework.sms.core.property.SmsChannelProperties; |
| 12 | -import com.aliyuncs.DefaultAcsClient; | ||
| 13 | -import com.aliyuncs.IAcsClient; | ||
| 14 | -import com.aliyuncs.dysmsapi.model.v20170525.QuerySmsTemplateRequest; | ||
| 15 | -import com.aliyuncs.dysmsapi.model.v20170525.QuerySmsTemplateResponse; | ||
| 16 | -import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest; | ||
| 17 | -import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; | ||
| 18 | -import com.aliyuncs.profile.DefaultProfile; | ||
| 19 | -import com.aliyuncs.profile.IClientProfile; | ||
| 20 | -import com.fasterxml.jackson.annotation.JsonFormat; | ||
| 21 | -import com.fasterxml.jackson.annotation.JsonProperty; | ||
| 22 | import com.google.common.annotations.VisibleForTesting; | 23 | import com.google.common.annotations.VisibleForTesting; |
| 23 | -import lombok.Data; | ||
| 24 | import lombok.extern.slf4j.Slf4j; | 24 | import lombok.extern.slf4j.Slf4j; |
| 25 | 25 | ||
| 26 | -import java.time.LocalDateTime; | ||
| 27 | -import java.util.List; | ||
| 28 | -import java.util.Objects; | 26 | +import java.util.*; |
| 27 | +import java.util.stream.Collectors; | ||
| 29 | 28 | ||
| 30 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | 29 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; |
| 31 | -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | ||
| 32 | -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.TIME_ZONE_DEFAULT; | ||
| 33 | 30 | ||
| 34 | /** | 31 | /** |
| 35 | * 阿里短信客户端的实现类 | 32 | * 阿里短信客户端的实现类 |
| @@ -40,20 +37,11 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.TIME_ZONE_DE | @@ -40,20 +37,11 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.TIME_ZONE_DE | ||
| 40 | @Slf4j | 37 | @Slf4j |
| 41 | public class AliyunSmsClient extends AbstractSmsClient { | 38 | public class AliyunSmsClient extends AbstractSmsClient { |
| 42 | 39 | ||
| 43 | - /** | ||
| 44 | - * 调用成功 code | ||
| 45 | - */ | ||
| 46 | - public static final String API_CODE_SUCCESS = "OK"; | 40 | + private static final String URL = "https://dysmsapi.aliyuncs.com"; |
| 41 | + private static final String HOST = "dysmsapi.aliyuncs.com"; | ||
| 42 | + private static final String VERSION = "2017-05-25"; | ||
| 47 | 43 | ||
| 48 | - /** | ||
| 49 | - * REGION, 使用杭州 | ||
| 50 | - */ | ||
| 51 | - private static final String ENDPOINT = "cn-hangzhou"; | ||
| 52 | - | ||
| 53 | - /** | ||
| 54 | - * 阿里云客户端 | ||
| 55 | - */ | ||
| 56 | - private volatile IAcsClient client; | 44 | + private static final String RESPONSE_CODE_SUCCESS = "OK"; |
| 57 | 45 | ||
| 58 | public AliyunSmsClient(SmsChannelProperties properties) { | 46 | public AliyunSmsClient(SmsChannelProperties properties) { |
| 59 | super(properties); | 47 | super(properties); |
| @@ -63,47 +51,66 @@ public class AliyunSmsClient extends AbstractSmsClient { | @@ -63,47 +51,66 @@ public class AliyunSmsClient extends AbstractSmsClient { | ||
| 63 | 51 | ||
| 64 | @Override | 52 | @Override |
| 65 | protected void doInit() { | 53 | protected void doInit() { |
| 66 | - IClientProfile profile = DefaultProfile.getProfile(ENDPOINT, properties.getApiKey(), properties.getApiSecret()); | ||
| 67 | - client = new DefaultAcsClient(profile); | ||
| 68 | } | 54 | } |
| 69 | 55 | ||
| 70 | @Override | 56 | @Override |
| 71 | public SmsSendRespDTO sendSms(Long sendLogId, String mobile, String apiTemplateId, | 57 | public SmsSendRespDTO sendSms(Long sendLogId, String mobile, String apiTemplateId, |
| 72 | List<KeyValue<String, Object>> templateParams) throws Throwable { | 58 | List<KeyValue<String, Object>> templateParams) throws Throwable { |
| 73 | - // 构建请求 | ||
| 74 | - SendSmsRequest request = new SendSmsRequest(); | ||
| 75 | - request.setPhoneNumbers(mobile); | ||
| 76 | - request.setSignName(properties.getSignature()); | ||
| 77 | - request.setTemplateCode(apiTemplateId); | ||
| 78 | - request.setTemplateParam(JsonUtils.toJsonString(MapUtils.convertMap(templateParams))); | ||
| 79 | - request.setOutId(String.valueOf(sendLogId)); | ||
| 80 | - // 执行请求 | ||
| 81 | - SendSmsResponse response = client.getAcsResponse(request); | ||
| 82 | - return new SmsSendRespDTO().setSuccess(Objects.equals(response.getCode(), API_CODE_SUCCESS)).setSerialNo(response.getBizId()) | ||
| 83 | - .setApiRequestId(response.getRequestId()).setApiCode(response.getCode()).setApiMsg(response.getMessage()); | 59 | + // 1. 执行请求 |
| 60 | + // 参考链接 https://api.aliyun.com/document/Dysmsapi/2017-05-25/SendSms | ||
| 61 | + TreeMap<String, Object> queryParam = new TreeMap<>(); | ||
| 62 | + queryParam.put("PhoneNumbers",mobile); | ||
| 63 | + queryParam.put("SignName", properties.getSignature()); | ||
| 64 | + queryParam.put("TemplateCode", apiTemplateId); | ||
| 65 | + queryParam.put("TemplateParam", JsonUtils.toJsonString(MapUtils.convertMap(templateParams))); | ||
| 66 | + queryParam.put("OutId", sendLogId); | ||
| 67 | + JSONObject response = request("sendSms", queryParam); | ||
| 68 | + | ||
| 69 | + // 2. 解析请求 | ||
| 70 | + return new SmsSendRespDTO() | ||
| 71 | + .setSuccess(Objects.equals(response.getStr("Code"), RESPONSE_CODE_SUCCESS)) | ||
| 72 | + .setSerialNo(response.getStr("BizId")) | ||
| 73 | + .setApiRequestId(response.getStr("RequestId")) | ||
| 74 | + .setApiCode(response.getStr("Code")) | ||
| 75 | + .setApiMsg(response.getStr("Message")); | ||
| 84 | } | 76 | } |
| 85 | 77 | ||
| 86 | @Override | 78 | @Override |
| 87 | public List<SmsReceiveRespDTO> parseSmsReceiveStatus(String text) { | 79 | public List<SmsReceiveRespDTO> parseSmsReceiveStatus(String text) { |
| 88 | - List<SmsReceiveStatus> statuses = JsonUtils.parseArray(text, SmsReceiveStatus.class); | ||
| 89 | - return convertList(statuses, status -> new SmsReceiveRespDTO().setSuccess(status.getSuccess()) | ||
| 90 | - .setErrorCode(status.getErrCode()).setErrorMsg(status.getErrMsg()) | ||
| 91 | - .setMobile(status.getPhoneNumber()).setReceiveTime(status.getReportTime()) | ||
| 92 | - .setSerialNo(status.getBizId()).setLogId(Long.valueOf(status.getOutId()))); | 80 | + JSONArray statuses = JSONUtil.parseArray(text); |
| 81 | + // 字段参考 | ||
| 82 | + return convertList(statuses, status -> { | ||
| 83 | + JSONObject statusObj = (JSONObject) status; | ||
| 84 | + return new SmsReceiveRespDTO() | ||
| 85 | + .setSuccess(statusObj.getBool("success")) // 是否接收成功 | ||
| 86 | + .setErrorCode(statusObj.getStr("err_code")) // 状态报告编码 | ||
| 87 | + .setErrorMsg(statusObj.getStr("err_msg")) // 状态报告说明 | ||
| 88 | + .setMobile(statusObj.getStr("phone_number")) // 手机号 | ||
| 89 | + .setReceiveTime(statusObj.getLocalDateTime("report_time", null)) // 状态报告时间 | ||
| 90 | + .setSerialNo(statusObj.getStr("biz_id")) // 发送序列号 | ||
| 91 | + .setLogId(statusObj.getLong("out_id")); // 用户序列号 | ||
| 92 | + }); | ||
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | @Override | 95 | @Override |
| 96 | public SmsTemplateRespDTO getSmsTemplate(String apiTemplateId) throws Throwable { | 96 | public SmsTemplateRespDTO getSmsTemplate(String apiTemplateId) throws Throwable { |
| 97 | - // 构建请求 | ||
| 98 | - QuerySmsTemplateRequest request = new QuerySmsTemplateRequest(); | ||
| 99 | - request.setTemplateCode(apiTemplateId); | ||
| 100 | - // 执行请求 | ||
| 101 | - QuerySmsTemplateResponse response = client.getAcsResponse(request); | ||
| 102 | - if (response.getTemplateStatus() == null) { | 97 | + // 1. 执行请求 |
| 98 | + // 参考链接 https://api.aliyun.com/document/Dysmsapi/2017-05-25/QuerySmsTemplate | ||
| 99 | + TreeMap<String, Object> queryParam = new TreeMap<>(); | ||
| 100 | + queryParam.put("TemplateCode", apiTemplateId); | ||
| 101 | + JSONObject response = request("QuerySmsTemplate", queryParam); | ||
| 102 | + | ||
| 103 | + // 2.1 请求失败 | ||
| 104 | + String code = response.getStr("Code"); | ||
| 105 | + if (ObjectUtil.notEqual(code, RESPONSE_CODE_SUCCESS)) { | ||
| 106 | + log.error("[getSmsTemplate][模版编号({}) 响应不正确({})]", apiTemplateId, response); | ||
| 103 | return null; | 107 | return null; |
| 104 | } | 108 | } |
| 105 | - return new SmsTemplateRespDTO().setId(response.getTemplateCode()).setContent(response.getTemplateContent()) | ||
| 106 | - .setAuditStatus(convertSmsTemplateAuditStatus(response.getTemplateStatus())).setAuditReason(response.getReason()); | 109 | + // 2.2 请求成功 |
| 110 | + return new SmsTemplateRespDTO().setId(apiTemplateId) | ||
| 111 | + .setContent(response.getStr("TemplateContent")) | ||
| 112 | + .setAuditStatus(convertSmsTemplateAuditStatus(response.getInt("TemplateStatus"))) | ||
| 113 | + .setAuditReason(response.getStr("Reason")); | ||
| 107 | } | 114 | } |
| 108 | 115 | ||
| 109 | @VisibleForTesting | 116 | @VisibleForTesting |
| @@ -117,66 +124,71 @@ public class AliyunSmsClient extends AbstractSmsClient { | @@ -117,66 +124,71 @@ public class AliyunSmsClient extends AbstractSmsClient { | ||
| 117 | } | 124 | } |
| 118 | 125 | ||
| 119 | /** | 126 | /** |
| 120 | - * 短信接收状态 | 127 | + * 请求阿里云短信 |
| 121 | * | 128 | * |
| 122 | - * 参见 <a href="https://help.aliyun.com/document_detail/101867.html">文档</a> | ||
| 123 | - * | ||
| 124 | - * @author 芋道源码 | 129 | + * @see <a href="https://help.aliyun.com/zh/sdk/product-overview/v3-request-structure-and-signature">V3 版本请求体&签名机制</> |
| 130 | + * @param apiName 请求的 API 名称 | ||
| 131 | + * @param queryParams 请求参数 | ||
| 132 | + * @return 请求结果 | ||
| 125 | */ | 133 | */ |
| 126 | - @Data | ||
| 127 | - public static class SmsReceiveStatus { | ||
| 128 | - | ||
| 129 | - /** | ||
| 130 | - * 手机号 | ||
| 131 | - */ | ||
| 132 | - @JsonProperty("phone_number") | ||
| 133 | - private String phoneNumber; | ||
| 134 | - /** | ||
| 135 | - * 发送时间 | ||
| 136 | - */ | ||
| 137 | - @JsonProperty("send_time") | ||
| 138 | - @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT) | ||
| 139 | - private LocalDateTime sendTime; | ||
| 140 | - /** | ||
| 141 | - * 状态报告时间 | ||
| 142 | - */ | ||
| 143 | - @JsonProperty("report_time") | ||
| 144 | - @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT) | ||
| 145 | - private LocalDateTime reportTime; | ||
| 146 | - /** | ||
| 147 | - * 是否接收成功 | ||
| 148 | - */ | ||
| 149 | - private Boolean success; | ||
| 150 | - /** | ||
| 151 | - * 状态报告说明 | ||
| 152 | - */ | ||
| 153 | - @JsonProperty("err_msg") | ||
| 154 | - private String errMsg; | ||
| 155 | - /** | ||
| 156 | - * 状态报告编码 | ||
| 157 | - */ | ||
| 158 | - @JsonProperty("err_code") | ||
| 159 | - private String errCode; | ||
| 160 | - /** | ||
| 161 | - * 发送序列号 | ||
| 162 | - */ | ||
| 163 | - @JsonProperty("biz_id") | ||
| 164 | - private String bizId; | ||
| 165 | - /** | ||
| 166 | - * 用户序列号 | ||
| 167 | - * | ||
| 168 | - * 这里我们传递的是 SysSmsLogDO 的日志编号 | ||
| 169 | - */ | ||
| 170 | - @JsonProperty("out_id") | ||
| 171 | - private String outId; | ||
| 172 | - /** | ||
| 173 | - * 短信长度,例如说 1、2、3 | ||
| 174 | - * | ||
| 175 | - * 140 字节算一条短信,短信长度超过 140 字节时会拆分成多条短信发送 | ||
| 176 | - */ | ||
| 177 | - @JsonProperty("sms_size") | ||
| 178 | - private Integer smsSize; | 134 | + private JSONObject request(String apiName, TreeMap<String, Object> queryParams) { |
| 135 | + // 1. 请求参数 | ||
| 136 | + String queryString = queryParams.entrySet().stream() | ||
| 137 | + .map(entry -> percentCode(entry.getKey()) + "=" + percentCode(String.valueOf(entry.getValue()))) | ||
| 138 | + .collect(Collectors.joining("&")); | ||
| 139 | + | ||
| 140 | + // 2.1 请求 Header | ||
| 141 | + TreeMap<String, String> headers = new TreeMap<>(); | ||
| 142 | + headers.put("host", HOST); | ||
| 143 | + headers.put("x-acs-version", VERSION); | ||
| 144 | + headers.put("x-acs-action", apiName); | ||
| 145 | + headers.put("x-acs-date", FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss'Z'", TimeZone.getTimeZone("GMT")).format(new Date())); | ||
| 146 | + headers.put("x-acs-signature-nonce", IdUtil.randomUUID()); | ||
| 147 | + // 2.2 构建签名 Header | ||
| 148 | + StringBuilder canonicalHeaders = new StringBuilder(); // 构造请求头,多个规范化消息头,按照消息头名称(小写)的字符代码顺序以升序排列后拼接在一起 | ||
| 149 | + StringBuilder signedHeadersBuilder = new StringBuilder(); // 已签名消息头列表,多个请求头名称(小写)按首字母升序排列并以英文分号(;)分隔 | ||
| 150 | + headers.entrySet().stream().filter(entry -> entry.getKey().toLowerCase().startsWith("x-acs-") | ||
| 151 | + || entry.getKey().equalsIgnoreCase("host") | ||
| 152 | + || entry.getKey().equalsIgnoreCase("content-type")) | ||
| 153 | + .sorted(Map.Entry.comparingByKey()).forEach(entry -> { | ||
| 154 | + String lowerKey = entry.getKey().toLowerCase(); | ||
| 155 | + canonicalHeaders.append(lowerKey).append(":").append(String.valueOf(entry.getValue()).trim()).append("\n"); | ||
| 156 | + signedHeadersBuilder.append(lowerKey).append(";"); | ||
| 157 | + }); | ||
| 158 | + String signedHeaders = signedHeadersBuilder.substring(0, signedHeadersBuilder.length() - 1); | ||
| 159 | + | ||
| 160 | + // 3. 请求 Body | ||
| 161 | + String requestBody = ""; // 短信 API 为 RPC 接口,query parameters 在 uri 中拼接,因此 request body 如果没有特殊要求,设置为空。 | ||
| 162 | + String hashedRequestBody = DigestUtil.sha256Hex(requestBody); | ||
| 163 | + | ||
| 164 | + // 4. 构建 Authorization 签名 | ||
| 165 | + String hashedCanonicalRequest = DigestUtil.sha256Hex("POST" // httpMethod | ||
| 166 | + + "\n" + "/" // canonicalUri | ||
| 167 | + + "\n" + queryString + "\n" + canonicalHeaders + "\n" + signedHeaders + "\n" + hashedRequestBody); | ||
| 168 | + String stringToSign = "ACS3-HMAC-SHA256" + "\n" + hashedCanonicalRequest; | ||
| 169 | + String signature = SecureUtil.hmacSha256(properties.getApiSecret()).digestHex(stringToSign); // 计算签名 | ||
| 170 | + headers.put("Authorization", "ACS3-HMAC-SHA256" + " " + "Credential=" + properties.getApiKey() | ||
| 171 | + + ", " + "SignedHeaders=" + signedHeaders + ", " + "Signature=" + signature); | ||
| 172 | + | ||
| 173 | + // 5. 发起请求 | ||
| 174 | + String urlWithParams = URL + "?" + URLUtil.buildQuery(queryParams, null); | ||
| 175 | + try (HttpResponse response = HttpRequest.post(urlWithParams).addHeaders(headers).body(requestBody).execute()) { | ||
| 176 | + return JSONUtil.parseObj(response.body()); | ||
| 177 | + } | ||
| 178 | + } | ||
| 179 | 179 | ||
| 180 | + /** | ||
| 181 | + * 对指定的字符串进行 URL 编码,并对特定的字符进行替换,以符合URL编码规范 | ||
| 182 | + * | ||
| 183 | + * @param str 需要进行URL编码的字符串 | ||
| 184 | + * @return 编码后的字符串 | ||
| 185 | + */ | ||
| 186 | + private static String percentCode(String str) { | ||
| 187 | + Assert.notNull(str, "str 不能为空"); | ||
| 188 | + return URLUtil.encode(str) | ||
| 189 | + .replace("+", "%20") // 加号 "+" 被替换为 "%20" | ||
| 190 | + .replace("*", "%2A") // 星号 "*" 被替换为 "%2A" | ||
| 191 | + .replace("%7E", "~"); // 波浪号 "%7E" 被替换为 "~" | ||
| 180 | } | 192 | } |
| 181 | 193 | ||
| 182 | } | 194 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/sms/core/client/impl/AliyunSmsClient_old.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.system.framework.sms.core.client.impl; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.lang.Assert; | ||
| 4 | +import cn.hutool.core.util.HexUtil; | ||
| 5 | +import cn.hutool.core.util.URLUtil; | ||
| 6 | +import cn.hutool.crypto.SecureUtil; | ||
| 7 | +import cn.hutool.crypto.digest.DigestUtil; | ||
| 8 | +import cn.hutool.http.HttpRequest; | ||
| 9 | +import cn.hutool.http.HttpResponse; | ||
| 10 | +import cn.hutool.json.JSONObject; | ||
| 11 | +import cn.hutool.json.JSONUtil; | ||
| 12 | +import cn.iocoder.yudao.framework.common.core.KeyValue; | ||
| 13 | +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | ||
| 14 | +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | ||
| 15 | +import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsReceiveRespDTO; | ||
| 16 | +import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsSendRespDTO; | ||
| 17 | +import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsTemplateRespDTO; | ||
| 18 | +import cn.iocoder.yudao.module.system.framework.sms.core.enums.SmsTemplateAuditStatusEnum; | ||
| 19 | +import cn.iocoder.yudao.module.system.framework.sms.core.property.SmsChannelProperties; | ||
| 20 | +import com.fasterxml.jackson.annotation.JsonFormat; | ||
| 21 | +import com.fasterxml.jackson.annotation.JsonProperty; | ||
| 22 | +import com.google.common.annotations.VisibleForTesting; | ||
| 23 | +import lombok.Data; | ||
| 24 | +import lombok.extern.slf4j.Slf4j; | ||
| 25 | + | ||
| 26 | +import java.io.IOException; | ||
| 27 | +import java.io.UnsupportedEncodingException; | ||
| 28 | +import java.net.URISyntaxException; | ||
| 29 | +import java.net.URLEncoder; | ||
| 30 | +import java.text.SimpleDateFormat; | ||
| 31 | +import java.time.LocalDateTime; | ||
| 32 | +import java.util.*; | ||
| 33 | + | ||
| 34 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | ||
| 35 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | ||
| 36 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.TIME_ZONE_DEFAULT; | ||
| 37 | + | ||
| 38 | +/** | ||
| 39 | + * 阿里短信客户端的实现类 | ||
| 40 | + * | ||
| 41 | + * @author zzf | ||
| 42 | + * @since 2021/1/25 14:17 | ||
| 43 | + */ | ||
| 44 | +@Slf4j | ||
| 45 | +public class AliyunSmsClient_old extends AbstractSmsClient { | ||
| 46 | + | ||
| 47 | + public AliyunSmsClient_old(SmsChannelProperties properties) { | ||
| 48 | + super(properties); | ||
| 49 | + Assert.notEmpty(properties.getApiKey(), "apiKey 不能为空"); | ||
| 50 | + Assert.notEmpty(properties.getApiSecret(), "apiSecret 不能为空"); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + @Override | ||
| 54 | + protected void doInit() { | ||
| 55 | +// IClientProfile profile = DefaultProfile.getProfile(ENDPOINT, properties.getApiKey(), properties.getApiSecret()); | ||
| 56 | +// client = new DefaultAcsClient(profile); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + @Override | ||
| 60 | + public SmsSendRespDTO sendSms(Long sendLogId, String mobile, String apiTemplateId, | ||
| 61 | + List<KeyValue<String, Object>> templateParams) throws Throwable { | ||
| 62 | + | ||
| 63 | + TreeMap<String, Object> queryParam = new TreeMap<>(); | ||
| 64 | + queryParam.put("PhoneNumbers",mobile); | ||
| 65 | + queryParam.put("SignName",properties.getSignature()); | ||
| 66 | + queryParam.put("TemplateCode",apiTemplateId); | ||
| 67 | + queryParam.put("TemplateParam",JsonUtils.toJsonString(MapUtils.convertMap(templateParams))); | ||
| 68 | + | ||
| 69 | + JSONObject response = sendSmsRequest(queryParam,"sendSms"); | ||
| 70 | + SmsResponse smsResponse = getSmsSendResponse(response); | ||
| 71 | + | ||
| 72 | + return new SmsSendRespDTO().setSuccess(smsResponse.success).setApiMsg(smsResponse.data.toString()); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + JSONObject sendSmsRequest(TreeMap<String, Object> queryParam,String apiName) throws IOException, URISyntaxException { | ||
| 76 | + | ||
| 77 | + // ************* 步骤 1:拼接规范请求串 ************* | ||
| 78 | + String url = "https://dysmsapi.aliyuncs.com"; //APP接入地址+接口访问URI | ||
| 79 | + String httpMethod = "POST"; // 请求方式 | ||
| 80 | + String canonicalUri = "/"; | ||
| 81 | + // 请求参数,当请求的查询字符串为空时,使用空字符串作为规范化查询字符串 | ||
| 82 | + StringBuilder canonicalQueryString = new StringBuilder(); | ||
| 83 | + queryParam.entrySet().stream().map(entry -> percentCode(entry.getKey()) + "=" + percentCode(String.valueOf(entry.getValue()))).forEachOrdered(queryPart -> { | ||
| 84 | + // 如果canonicalQueryString已经不是空的,则在查询参数前添加"&" | ||
| 85 | + if (!canonicalQueryString.isEmpty()) { | ||
| 86 | + canonicalQueryString.append("&"); | ||
| 87 | + } | ||
| 88 | + canonicalQueryString.append(queryPart); | ||
| 89 | + System.out.println("canonicalQueryString=========>\n" + canonicalQueryString); | ||
| 90 | + }); | ||
| 91 | + | ||
| 92 | + SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); | ||
| 93 | + SDF.setTimeZone(new SimpleTimeZone(0, "GMT")); | ||
| 94 | + String SdfTime = SDF.format(new Date()); | ||
| 95 | + String randomUUID = UUID.randomUUID().toString(); | ||
| 96 | + | ||
| 97 | + TreeMap<String, String> headers = new TreeMap<>(); | ||
| 98 | + headers.put("host", "dysmsapi.aliyuncs.com"); | ||
| 99 | + headers.put("x-acs-action", apiName); | ||
| 100 | + headers.put("x-acs-version", "2017-05-25"); | ||
| 101 | + headers.put("x-acs-date", SdfTime); | ||
| 102 | + headers.put("x-acs-signature-nonce", randomUUID); | ||
| 103 | +// headers.put("content-type", "application/json;charset=utf-8"); | ||
| 104 | + | ||
| 105 | + // 构造请求头,多个规范化消息头,按照消息头名称(小写)的字符代码顺序以升序排列后拼接在一起 | ||
| 106 | + StringBuilder canonicalHeaders = new StringBuilder(); | ||
| 107 | + // 已签名消息头列表,多个请求头名称(小写)按首字母升序排列并以英文分号(;)分隔 | ||
| 108 | + StringBuilder signedHeadersSb = new StringBuilder(); | ||
| 109 | + headers.entrySet().stream().filter(entry -> entry.getKey().toLowerCase().startsWith("x-acs-") || entry.getKey().equalsIgnoreCase("host") || entry.getKey().equalsIgnoreCase("content-type")).sorted(Map.Entry.comparingByKey()).forEach(entry -> { | ||
| 110 | + String lowerKey = entry.getKey().toLowerCase(); | ||
| 111 | + String value = String.valueOf(entry.getValue()).trim(); | ||
| 112 | + canonicalHeaders.append(lowerKey).append(":").append(value).append("\n"); | ||
| 113 | + signedHeadersSb.append(lowerKey).append(";"); | ||
| 114 | + }); | ||
| 115 | + String signedHeaders = signedHeadersSb.substring(0, signedHeadersSb.length() - 1); | ||
| 116 | + | ||
| 117 | + String body = "";//短信API为RPC接口,query parameters在uri中拼接,因此request body如果没有特殊要求,设置为空。 | ||
| 118 | + String hashedRequestBody = HexUtil.encodeHexStr(DigestUtil.sha256(body)); | ||
| 119 | + | ||
| 120 | + | ||
| 121 | + String canonicalRequest = httpMethod + "\n" + canonicalUri + "\n" + canonicalQueryString + "\n" + canonicalHeaders + "\n" + signedHeaders + "\n" + hashedRequestBody; | ||
| 122 | + System.out.println("canonicalRequest=========>\n" + canonicalRequest); | ||
| 123 | + | ||
| 124 | + // ************* 步骤 2:拼接待签名字符串 ************* | ||
| 125 | + String hashedCanonicalRequest = HexUtil.encodeHexStr(DigestUtil.sha256(canonicalRequest)); | ||
| 126 | + String stringToSign = "ACS3-HMAC-SHA256" + "\n" + hashedCanonicalRequest; | ||
| 127 | + | ||
| 128 | + // ************* 步骤 3:计算签名 ************* | ||
| 129 | + String signature = SecureUtil.hmacSha256(properties.getApiSecret()).digestHex(stringToSign); | ||
| 130 | + | ||
| 131 | + // ************* 步骤 4:拼接 Authorization ************* | ||
| 132 | + String authorization = "ACS3-HMAC-SHA256" + " " + "Credential=" + properties.getApiKey() + ", " | ||
| 133 | + + "SignedHeaders=" + signedHeaders + ", " + "Signature=" + signature; | ||
| 134 | + headers.put("Authorization", authorization); | ||
| 135 | + | ||
| 136 | + // ************* 步骤 5:构造HttpRequest 并执行request请求,获得response ************* | ||
| 137 | +// url = url + canonicalUri; | ||
| 138 | + String urlWithParams = url + "?" + URLUtil.buildQuery(queryParam, null); | ||
| 139 | + | ||
| 140 | + HttpResponse response = HttpRequest.post(urlWithParams) | ||
| 141 | + .addHeaders(headers) | ||
| 142 | + .body(body) | ||
| 143 | + .execute(); | ||
| 144 | +// URIBuilder uriBuilder = new URIBuilder(url); | ||
| 145 | +// // 添加请求参数 | ||
| 146 | +// for (Map.Entry<String, Object> entry : queryParam.entrySet()) { | ||
| 147 | +// uriBuilder.addParameter(entry.getKey(), String.valueOf(entry.getValue())); | ||
| 148 | +// } | ||
| 149 | +// HttpUriRequest httpRequest = new HttpPost(uriBuilder.build()); | ||
| 150 | +//// HttpPost httpPost = new HttpPost(uriBuilder.build()); | ||
| 151 | +//// httpRequest = httpPost; | ||
| 152 | +// | ||
| 153 | +// // 添加http请求头 | ||
| 154 | +// for (Map.Entry<String, Object> entry : headers.entrySet()) { | ||
| 155 | +// httpRequest.addHeader(entry.getKey(), String.valueOf(entry.getValue())); | ||
| 156 | +// } | ||
| 157 | +// | ||
| 158 | +// // 发送请求 | ||
| 159 | +// CloseableHttpClient httpClient = HttpClients.createDefault(); | ||
| 160 | +// CloseableHttpResponse response = httpClient.execute(httpRequest); | ||
| 161 | + System.out.println("getEntity====="+response.body()); | ||
| 162 | + System.out.println("response====="+response); | ||
| 163 | + | ||
| 164 | + return JSONUtil.parseObj(response.body()); | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + @Override | ||
| 168 | + public List<SmsReceiveRespDTO> parseSmsReceiveStatus(String text) { | ||
| 169 | + List<SmsReceiveStatus> statuses = JsonUtils.parseArray(text, SmsReceiveStatus.class); | ||
| 170 | + return convertList(statuses, status -> new SmsReceiveRespDTO().setSuccess(status.getSuccess()) | ||
| 171 | + .setErrorCode(status.getErrCode()).setErrorMsg(status.getErrMsg()) | ||
| 172 | + .setMobile(status.getPhoneNumber()).setReceiveTime(status.getReportTime()) | ||
| 173 | + .setSerialNo(status.getBizId()).setLogId(Long.valueOf(status.getOutId()))); | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + @Override | ||
| 177 | + public SmsTemplateRespDTO getSmsTemplate(String apiTemplateId) throws Throwable { | ||
| 178 | + | ||
| 179 | + TreeMap<String, Object> queryParam = new TreeMap<>(); | ||
| 180 | + queryParam.put("TemplateCode",apiTemplateId); | ||
| 181 | + | ||
| 182 | + JSONObject response = sendSmsRequest(queryParam,"QuerySmsTemplate"); | ||
| 183 | + QuerySmsTemplateResponse smsTemplateResponse = getSmsTemplateResponse(response); | ||
| 184 | + return new SmsTemplateRespDTO().setId(smsTemplateResponse.getTemplateCode()).setContent(smsTemplateResponse.getTemplateContent()) | ||
| 185 | + .setAuditStatus(convertSmsTemplateAuditStatus(smsTemplateResponse.getTemplateStatus())).setAuditReason(smsTemplateResponse.getReason()); | ||
| 186 | + | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + @VisibleForTesting | ||
| 190 | + Integer convertSmsTemplateAuditStatus(Integer templateStatus) { | ||
| 191 | + switch (templateStatus) { | ||
| 192 | + case 0: return SmsTemplateAuditStatusEnum.CHECKING.getStatus(); | ||
| 193 | + case 1: return SmsTemplateAuditStatusEnum.SUCCESS.getStatus(); | ||
| 194 | + case 2: return SmsTemplateAuditStatusEnum.FAIL.getStatus(); | ||
| 195 | + default: throw new IllegalArgumentException(String.format("未知审核状态(%d)", templateStatus)); | ||
| 196 | + } | ||
| 197 | + } | ||
| 198 | + | ||
| 199 | + | ||
| 200 | + /** | ||
| 201 | + * 对指定的字符串进行URL编码。 | ||
| 202 | + * 使用UTF-8编码字符集对字符串进行编码,并对特定的字符进行替换,以符合URL编码规范。 | ||
| 203 | + * | ||
| 204 | + * @param str 需要进行URL编码的字符串。 | ||
| 205 | + * @return 编码后的字符串。其中,加号"+"被替换为"%20",星号"*"被替换为"%2A",波浪号"%7E"被替换为"~"。 | ||
| 206 | + */ | ||
| 207 | + public static String percentCode(String str) { | ||
| 208 | + if (str == null) { | ||
| 209 | + throw new IllegalArgumentException("输入字符串不可为null"); | ||
| 210 | + } | ||
| 211 | + try { | ||
| 212 | + return URLEncoder.encode(str, "UTF-8").replace("+", "%20").replace("*", "%2A").replace("%7E", "~"); | ||
| 213 | + } catch (UnsupportedEncodingException e) { | ||
| 214 | + throw new RuntimeException("UTF-8编码不被支持", e); | ||
| 215 | + } | ||
| 216 | + } | ||
| 217 | + | ||
| 218 | + private SmsResponse getSmsSendResponse(JSONObject resJson) { | ||
| 219 | + SmsResponse smsResponse = new SmsResponse(); | ||
| 220 | + smsResponse.setSuccess("OK".equals(resJson.getStr("Code"))); | ||
| 221 | + smsResponse.setData(resJson); | ||
| 222 | +// smsResponse.setConfigId(getConfigId()); | ||
| 223 | + return smsResponse; | ||
| 224 | + } | ||
| 225 | + | ||
| 226 | + private QuerySmsTemplateResponse getSmsTemplateResponse(JSONObject resJson) { | ||
| 227 | + | ||
| 228 | + QuerySmsTemplateResponse smsTemplateResponse = new QuerySmsTemplateResponse(); | ||
| 229 | + | ||
| 230 | + smsTemplateResponse.setRequestId(resJson.getStr("RequestId")); | ||
| 231 | + smsTemplateResponse.setTemplateContent(resJson.getStr("TemplateContent")); | ||
| 232 | + smsTemplateResponse.setReason(resJson.getStr("Reason")); | ||
| 233 | + smsTemplateResponse.setTemplateStatus(resJson.getInt("TemplateStatus")); | ||
| 234 | + | ||
| 235 | + return smsTemplateResponse; | ||
| 236 | + } | ||
| 237 | + | ||
| 238 | + /** | ||
| 239 | + * <p>类名: SmsResponse | ||
| 240 | + * <p>说明: 发送短信返回信息 | ||
| 241 | + * | ||
| 242 | + * @author :scholar | ||
| 243 | + * 2024/07/17 0:25 | ||
| 244 | + **/ | ||
| 245 | + @Data | ||
| 246 | + public static class SmsResponse { | ||
| 247 | + | ||
| 248 | + /** | ||
| 249 | + * 是否成功 | ||
| 250 | + */ | ||
| 251 | + private boolean success; | ||
| 252 | + | ||
| 253 | + /** | ||
| 254 | + * 厂商原返回体 | ||
| 255 | + */ | ||
| 256 | + private Object data; | ||
| 257 | + | ||
| 258 | + /** | ||
| 259 | + * 配置标识名 如未配置取对应渠道名例如 Alibaba | ||
| 260 | + */ | ||
| 261 | + private String configId; | ||
| 262 | + } | ||
| 263 | + | ||
| 264 | + | ||
| 265 | + /** | ||
| 266 | + * <p>类名: QuerySmsTemplateResponse | ||
| 267 | + * <p>说明: sms模板查询返回信息 | ||
| 268 | + * | ||
| 269 | + * @author :scholar | ||
| 270 | + * 2024/07/17 0:25 | ||
| 271 | + **/ | ||
| 272 | + @Data | ||
| 273 | + public static class QuerySmsTemplateResponse { | ||
| 274 | + private String requestId; | ||
| 275 | + private String code; | ||
| 276 | + private String message; | ||
| 277 | + private Integer templateStatus; | ||
| 278 | + private String reason; | ||
| 279 | + private String templateCode; | ||
| 280 | + private Integer templateType; | ||
| 281 | + private String templateName; | ||
| 282 | + private String templateContent; | ||
| 283 | + private String createDate; | ||
| 284 | + } | ||
| 285 | + | ||
| 286 | + /** | ||
| 287 | + * 短信接收状态 | ||
| 288 | + * | ||
| 289 | + * 参见 <a href="https://help.aliyun.com/document_detail/101867.html">文档</a> | ||
| 290 | + * | ||
| 291 | + * @author 润普源码 | ||
| 292 | + */ | ||
| 293 | + @Data | ||
| 294 | + public static class SmsReceiveStatus { | ||
| 295 | + | ||
| 296 | + /** | ||
| 297 | + * 手机号 | ||
| 298 | + */ | ||
| 299 | + @JsonProperty("phone_number") | ||
| 300 | + private String phoneNumber; | ||
| 301 | + /** | ||
| 302 | + * 发送时间 | ||
| 303 | + */ | ||
| 304 | + @JsonProperty("send_time") | ||
| 305 | + @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT) | ||
| 306 | + private LocalDateTime sendTime; | ||
| 307 | + /** | ||
| 308 | + * 状态报告时间 | ||
| 309 | + */ | ||
| 310 | + @JsonProperty("report_time") | ||
| 311 | + @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT) | ||
| 312 | + private LocalDateTime reportTime; | ||
| 313 | + /** | ||
| 314 | + * 是否接收成功 | ||
| 315 | + */ | ||
| 316 | + private Boolean success; | ||
| 317 | + /** | ||
| 318 | + * 状态报告说明 | ||
| 319 | + */ | ||
| 320 | + @JsonProperty("err_msg") | ||
| 321 | + private String errMsg; | ||
| 322 | + /** | ||
| 323 | + * 状态报告编码 | ||
| 324 | + */ | ||
| 325 | + @JsonProperty("err_code") | ||
| 326 | + private String errCode; | ||
| 327 | + /** | ||
| 328 | + * 发送序列号 | ||
| 329 | + */ | ||
| 330 | + @JsonProperty("biz_id") | ||
| 331 | + private String bizId; | ||
| 332 | + /** | ||
| 333 | + * 用户序列号 | ||
| 334 | + * | ||
| 335 | + * 这里我们传递的是 SysSmsLogDO 的日志编号 | ||
| 336 | + */ | ||
| 337 | + @JsonProperty("out_id") | ||
| 338 | + private String outId; | ||
| 339 | + /** | ||
| 340 | + * 短信长度,例如说 1、2、3 | ||
| 341 | + * | ||
| 342 | + * 140 字节算一条短信,短信长度超过 140 字节时会拆分成多条短信发送 | ||
| 343 | + */ | ||
| 344 | + @JsonProperty("sms_size") | ||
| 345 | + private Integer smsSize; | ||
| 346 | + | ||
| 347 | + } | ||
| 348 | + | ||
| 349 | +} |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/sms/core/client/impl/HuaweiSmsClient.java
| 1 | package cn.iocoder.yudao.module.system.framework.sms.core.client.impl; | 1 | package cn.iocoder.yudao.module.system.framework.sms.core.client.impl; |
| 2 | 2 | ||
| 3 | + | ||
| 3 | import cn.hutool.core.lang.Assert; | 4 | import cn.hutool.core.lang.Assert; |
| 4 | -import cn.hutool.core.util.HexUtil; | ||
| 5 | import cn.hutool.core.util.StrUtil; | 5 | import cn.hutool.core.util.StrUtil; |
| 6 | + | ||
| 6 | import cn.hutool.crypto.SecureUtil; | 7 | import cn.hutool.crypto.SecureUtil; |
| 7 | -import cn.hutool.crypto.digest.DigestUtil; | ||
| 8 | -import cn.hutool.json.JSONArray; | 8 | +import cn.hutool.http.HttpRequest; |
| 9 | +import cn.hutool.http.HttpResponse; | ||
| 10 | +import cn.hutool.json.JSONObject; | ||
| 11 | +import cn.hutool.json.JSONUtil; | ||
| 9 | import cn.iocoder.yudao.framework.common.core.KeyValue; | 12 | import cn.iocoder.yudao.framework.common.core.KeyValue; |
| 13 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | ||
| 10 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | 14 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 11 | import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsReceiveRespDTO; | 15 | import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsReceiveRespDTO; |
| 12 | import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsSendRespDTO; | 16 | import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsSendRespDTO; |
| 13 | import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsTemplateRespDTO; | 17 | import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsTemplateRespDTO; |
| 14 | import cn.iocoder.yudao.module.system.framework.sms.core.enums.SmsTemplateAuditStatusEnum; | 18 | import cn.iocoder.yudao.module.system.framework.sms.core.enums.SmsTemplateAuditStatusEnum; |
| 15 | import cn.iocoder.yudao.module.system.framework.sms.core.property.SmsChannelProperties; | 19 | import cn.iocoder.yudao.module.system.framework.sms.core.property.SmsChannelProperties; |
| 20 | + | ||
| 16 | import com.fasterxml.jackson.annotation.JsonFormat; | 21 | import com.fasterxml.jackson.annotation.JsonFormat; |
| 17 | import com.fasterxml.jackson.annotation.JsonProperty; | 22 | import com.fasterxml.jackson.annotation.JsonProperty; |
| 18 | import lombok.Data; | 23 | import lombok.Data; |
| 19 | import lombok.extern.slf4j.Slf4j; | 24 | import lombok.extern.slf4j.Slf4j; |
| 20 | -import org.apache.http.HttpResponse; | ||
| 21 | -import org.apache.http.client.methods.HttpUriRequest; | ||
| 22 | -import org.apache.http.client.methods.RequestBuilder; | ||
| 23 | -import org.apache.http.entity.StringEntity; | ||
| 24 | -import org.apache.http.impl.client.CloseableHttpClient; | ||
| 25 | -import org.apache.http.impl.client.HttpClientBuilder; | ||
| 26 | 25 | ||
| 26 | +import java.io.UnsupportedEncodingException; | ||
| 27 | import java.net.URLEncoder; | 27 | import java.net.URLEncoder; |
| 28 | -import java.nio.charset.StandardCharsets; | ||
| 29 | import java.text.SimpleDateFormat; | 28 | import java.text.SimpleDateFormat; |
| 30 | -import java.time.LocalDateTime; | ||
| 31 | import java.util.*; | 29 | import java.util.*; |
| 32 | 30 | ||
| 31 | + | ||
| 32 | +import java.time.LocalDateTime; | ||
| 33 | + | ||
| 34 | + | ||
| 35 | +import static cn.hutool.crypto.digest.DigestUtil.sha256Hex; | ||
| 33 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | 36 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; |
| 34 | import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | 37 | import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; |
| 35 | import static cn.iocoder.yudao.framework.common.util.date.DateUtils.TIME_ZONE_DEFAULT; | 38 | import static cn.iocoder.yudao.framework.common.util.date.DateUtils.TIME_ZONE_DEFAULT; |
| 36 | 39 | ||
| 40 | + | ||
| 37 | /** | 41 | /** |
| 38 | * 华为短信客户端的实现类 | 42 | * 华为短信客户端的实现类 |
| 39 | * | 43 | * |
| @@ -46,7 +50,14 @@ public class HuaweiSmsClient extends AbstractSmsClient { | @@ -46,7 +50,14 @@ public class HuaweiSmsClient extends AbstractSmsClient { | ||
| 46 | /** | 50 | /** |
| 47 | * 调用成功 code | 51 | * 调用成功 code |
| 48 | */ | 52 | */ |
| 49 | - public static final String API_CODE_SUCCESS = "OK"; | 53 | + public static final String URL = "https://smsapi.cn-north-4.myhuaweicloud.com:443/sms/batchSendSms/v1";//APP接入地址+接口访问URI |
| 54 | + public static final String HOST = "smsapi.cn-north-4.myhuaweicloud.com:443"; | ||
| 55 | + public static final String SIGNEDHEADERS = "content-type;host;x-sdk-date"; | ||
| 56 | + | ||
| 57 | + @Override | ||
| 58 | + protected void doInit() { | ||
| 59 | + | ||
| 60 | + } | ||
| 50 | 61 | ||
| 51 | public HuaweiSmsClient(SmsChannelProperties properties) { | 62 | public HuaweiSmsClient(SmsChannelProperties properties) { |
| 52 | super(properties); | 63 | super(properties); |
| @@ -55,95 +66,78 @@ public class HuaweiSmsClient extends AbstractSmsClient { | @@ -55,95 +66,78 @@ public class HuaweiSmsClient extends AbstractSmsClient { | ||
| 55 | } | 66 | } |
| 56 | 67 | ||
| 57 | @Override | 68 | @Override |
| 58 | - protected void doInit() { | ||
| 59 | - } | ||
| 60 | - | ||
| 61 | - @Override | ||
| 62 | public SmsSendRespDTO sendSms(Long sendLogId, String mobile, String apiTemplateId, | 69 | public SmsSendRespDTO sendSms(Long sendLogId, String mobile, String apiTemplateId, |
| 63 | List<KeyValue<String, Object>> templateParams) throws Throwable { | 70 | List<KeyValue<String, Object>> templateParams) throws Throwable { |
| 64 | - // TODO @scholar:https://smsapi.cn-north-4.myhuaweicloud.com:443 是不是枚举成静态变量 | ||
| 65 | - String url = "https://smsapi.cn-north-4.myhuaweicloud.com:443/sms/batchSendSms/v1"; //APP接入地址+接口访问URI | ||
| 66 | // 相比较阿里短信,华为短信发送的时候需要额外的参数“通道号”,考虑到不破坏原有的的结构 | 71 | // 相比较阿里短信,华为短信发送的时候需要额外的参数“通道号”,考虑到不破坏原有的的结构 |
| 67 | // 所以将 通道号 拼接到 apiTemplateId 字段中,格式为 "apiTemplateId 通道号"。空格为分隔符。 | 72 | // 所以将 通道号 拼接到 apiTemplateId 字段中,格式为 "apiTemplateId 通道号"。空格为分隔符。 |
| 68 | - // TODO @scholar:暂时只考虑中国大陆,所以不需要 sender 哈 | ||
| 69 | String sender = StrUtil.subAfter(apiTemplateId, " ", true); //中国大陆短信签名通道号或全球短信通道号 | 73 | String sender = StrUtil.subAfter(apiTemplateId, " ", true); //中国大陆短信签名通道号或全球短信通道号 |
| 70 | String templateId = StrUtil.subBefore(apiTemplateId, " ", true); //模板ID | 74 | String templateId = StrUtil.subBefore(apiTemplateId, " ", true); //模板ID |
| 71 | 75 | ||
| 72 | - // 选填,短信状态报告接收地址,推荐使用域名,为空或者不填表示不接收状态报告 | 76 | + //选填,短信状态报告接收地址,推荐使用域名,为空或者不填表示不接收状态报告 |
| 73 | String statusCallBack = properties.getCallbackUrl(); | 77 | String statusCallBack = properties.getCallbackUrl(); |
| 74 | 78 | ||
| 75 | - // TODO @scholar:1)是不是用 LocalDateTimeUtil.format();这样 3 行变成一行 | ||
| 76 | - // TODO @scholar:singerDate 叫 sdkDate 会更合适哈,这样理解起来简单。另外,singer 应该是 signed 么? | 79 | + List<String> templateParas = CollectionUtils.convertList(templateParams, kv -> String.valueOf(kv.getValue())); |
| 80 | + | ||
| 81 | + JSONObject JsonResponse = sendSmsRequest(sender,mobile,templateId,templateParas,statusCallBack); | ||
| 82 | + SmsResponse smsResponse = getSmsSendResponse(JsonResponse); | ||
| 83 | + | ||
| 84 | + return new SmsSendRespDTO().setSuccess(smsResponse.success).setApiMsg(smsResponse.data.toString()); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + JSONObject sendSmsRequest(String sender,String mobile,String templateId,List<String> templateParas,String statusCallBack) throws UnsupportedEncodingException { | ||
| 88 | + | ||
| 77 | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'", Locale.ENGLISH); | 89 | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'", Locale.ENGLISH); |
| 78 | sdf.setTimeZone(TimeZone.getTimeZone("UTC")); | 90 | sdf.setTimeZone(TimeZone.getTimeZone("UTC")); |
| 79 | - String singerDate = sdf.format(new Date()); | 91 | + String sdkDate = sdf.format(new Date()); |
| 80 | 92 | ||
| 81 | - // TODO @scholar:整个处理加密的过程,是不是应该抽成一个 private 方法哈。这样整个调用的主干更清晰。 | ||
| 82 | // ************* 步骤 1:拼接规范请求串 ************* | 93 | // ************* 步骤 1:拼接规范请求串 ************* |
| 83 | String httpRequestMethod = "POST"; | 94 | String httpRequestMethod = "POST"; |
| 84 | String canonicalUri = "/sms/batchSendSms/v1/"; | 95 | String canonicalUri = "/sms/batchSendSms/v1/"; |
| 85 | - String canonicalQueryString = ""; // 查询参数为空 | 96 | + String canonicalQueryString = "";//查询参数为空 |
| 86 | String canonicalHeaders = "content-type:application/x-www-form-urlencoded\n" | 97 | String canonicalHeaders = "content-type:application/x-www-form-urlencoded\n" |
| 87 | - + "host:smsapi.cn-north-4.myhuaweicloud.com:443\n" | ||
| 88 | - + "x-sdk-date:" + singerDate + "\n"; | ||
| 89 | - // TODO @scholar:静态枚举了 | ||
| 90 | - String signedHeaders = "content-type;host;x-sdk-date"; | ||
| 91 | - // TODO @scholar:下面的注释,可以考虑去掉 | ||
| 92 | - /* | ||
| 93 | - * 选填,使用无变量模板时请赋空值 String templateParas = ""; | ||
| 94 | - * 单变量模板示例:模板内容为"您的验证码是${NUM_6}"时,templateParas可填写为"[\"111111\"]" | ||
| 95 | - * 双变量模板示例:模板内容为"您有${NUM_2}件快递请到${TXT_20}领取"时,templateParas可填写为"[\"3\",\"人民公园正门\"]" | ||
| 96 | - */ | ||
| 97 | - // TODO @scholar:CollectionUtils.convertList 可以把 4 行变成 1 行。 | ||
| 98 | - // TODO @scholar:templateParams 拼写错误哈 | ||
| 99 | - List<String> templateParas = new ArrayList<>(); | ||
| 100 | - for (KeyValue<String, Object> kv : templateParams) { | ||
| 101 | - templateParas.add(String.valueOf(kv.getValue())); | ||
| 102 | - } | ||
| 103 | - | ||
| 104 | - // 请求Body,不携带签名名称时,signature请填null | 98 | + + "host:"+ HOST +"\n" |
| 99 | + + "x-sdk-date:" + sdkDate + "\n"; | ||
| 100 | + //请求Body,不携带签名名称时,signature请填null | ||
| 105 | String body = buildRequestBody(sender, mobile, templateId, templateParas, statusCallBack, null); | 101 | String body = buildRequestBody(sender, mobile, templateId, templateParas, statusCallBack, null); |
| 106 | - // TODO @scholar:Assert 断言,抛出异常 | ||
| 107 | if (null == body || body.isEmpty()) { | 102 | if (null == body || body.isEmpty()) { |
| 108 | return null; | 103 | return null; |
| 109 | } | 104 | } |
| 110 | - String hashedRequestBody = HexUtil.encodeHexStr(DigestUtil.sha256(body)); | 105 | + String hashedRequestBody = sha256Hex(body); |
| 111 | String canonicalRequest = httpRequestMethod + "\n" + canonicalUri + "\n" + canonicalQueryString + "\n" | 106 | String canonicalRequest = httpRequestMethod + "\n" + canonicalUri + "\n" + canonicalQueryString + "\n" |
| 112 | - + canonicalHeaders + "\n" + signedHeaders + "\n" + hashedRequestBody; | 107 | + + canonicalHeaders + "\n" + SIGNEDHEADERS + "\n" + hashedRequestBody; |
| 113 | 108 | ||
| 114 | // ************* 步骤 2:拼接待签名字符串 ************* | 109 | // ************* 步骤 2:拼接待签名字符串 ************* |
| 115 | - // TODO @scholar:sha256Hex 是不是更简洁哈 | ||
| 116 | - String hashedCanonicalRequest = HexUtil.encodeHexStr(DigestUtil.sha256(canonicalRequest)); | ||
| 117 | - String stringToSign = "SDK-HMAC-SHA256" + "\n" + singerDate + "\n" + hashedCanonicalRequest; | 110 | + String hashedCanonicalRequest = sha256Hex(canonicalRequest); |
| 111 | + String stringToSign = "SDK-HMAC-SHA256" + "\n" + sdkDate + "\n" + hashedCanonicalRequest; | ||
| 118 | 112 | ||
| 119 | // ************* 步骤 3:计算签名 ************* | 113 | // ************* 步骤 3:计算签名 ************* |
| 120 | String signature = SecureUtil.hmacSha256(properties.getApiSecret()).digestHex(stringToSign); | 114 | String signature = SecureUtil.hmacSha256(properties.getApiSecret()).digestHex(stringToSign); |
| 121 | 115 | ||
| 122 | // ************* 步骤 4:拼接 Authorization ************* | 116 | // ************* 步骤 4:拼接 Authorization ************* |
| 123 | String authorization = "SDK-HMAC-SHA256" + " " + "Access=" + properties.getApiKey() + ", " | 117 | String authorization = "SDK-HMAC-SHA256" + " " + "Access=" + properties.getApiKey() + ", " |
| 124 | - + "SignedHeaders=" + signedHeaders + ", " + "Signature=" + signature; | 118 | + + "SignedHeaders=" + SIGNEDHEADERS + ", " + "Signature=" + signature; |
| 125 | 119 | ||
| 126 | // ************* 步骤 5:构造HttpRequest 并执行request请求,获得response ************* | 120 | // ************* 步骤 5:构造HttpRequest 并执行request请求,获得response ************* |
| 127 | - // TODO @scholar:考虑了下,还是换 hutool 的 httpUtils。因为未来 httpclient 我们可能会移除掉 | ||
| 128 | - HttpUriRequest postMethod = RequestBuilder.post() | ||
| 129 | - .setUri(url) | ||
| 130 | - .setEntity(new StringEntity(body, StandardCharsets.UTF_8)) | ||
| 131 | - .setHeader("Content-Type","application/x-www-form-urlencoded") | ||
| 132 | - .setHeader("X-Sdk-Date", singerDate) | ||
| 133 | - .setHeader("Authorization", authorization) | ||
| 134 | - .build(); | ||
| 135 | - // TODO @scholar:这种不太适合一直 new 的哈 | ||
| 136 | - CloseableHttpClient client = HttpClientBuilder.create().build(); | ||
| 137 | - HttpResponse response = client.execute(postMethod); | ||
| 138 | - // TODO @scholar:失败的情况下的处理 | ||
| 139 | - // TODO @scholar:setSerialNo(Integer.toString(response.getStatusLine().getStatusCode())) 这部分,空一行。一行代码太多了,阅读性不太好哈 | ||
| 140 | - return new SmsSendRespDTO().setSuccess(Objects.equals(response.getStatusLine().getReasonPhrase(), API_CODE_SUCCESS)).setSerialNo(Integer.toString(response.getStatusLine().getStatusCode())) | ||
| 141 | - .setApiRequestId(null).setApiCode(null).setApiMsg(null); | 121 | + HttpResponse response = HttpRequest.post(URL) |
| 122 | + .header("Content-Type", "application/x-www-form-urlencoded") | ||
| 123 | + .header("X-Sdk-Date", sdkDate) | ||
| 124 | + .header("host",HOST) | ||
| 125 | + .header("Authorization", authorization) | ||
| 126 | + .body(body) | ||
| 127 | + .execute(); | ||
| 128 | + | ||
| 129 | + return JSONUtil.parseObj(response.body()); | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + private SmsResponse getSmsSendResponse(JSONObject resJson) { | ||
| 133 | + SmsResponse smsResponse = new SmsResponse(); | ||
| 134 | + smsResponse.setSuccess("000000".equals(resJson.getStr("code"))); | ||
| 135 | + smsResponse.setData(resJson); | ||
| 136 | + return smsResponse; | ||
| 142 | } | 137 | } |
| 143 | 138 | ||
| 144 | static String buildRequestBody(String sender, String receiver, String templateId, List<String> templateParas, | 139 | static String buildRequestBody(String sender, String receiver, String templateId, List<String> templateParas, |
| 145 | - String statusCallBack, @SuppressWarnings("SameParameterValue") String signature) { | ||
| 146 | - // TODO @scholar:参数不满足,是不是抛出异常更好哈;通过 hutool 的 Assert 去断言 | 140 | + String statusCallBack, String signature) throws UnsupportedEncodingException { |
| 147 | if (null == sender || null == receiver || null == templateId || sender.isEmpty() || receiver.isEmpty() | 141 | if (null == sender || null == receiver || null == templateId || sender.isEmpty() || receiver.isEmpty() |
| 148 | || templateId.isEmpty()) { | 142 | || templateId.isEmpty()) { |
| 149 | System.out.println("buildRequestBody(): sender, receiver or templateId is null."); | 143 | System.out.println("buildRequestBody(): sender, receiver or templateId is null."); |
| @@ -154,20 +148,17 @@ public class HuaweiSmsClient extends AbstractSmsClient { | @@ -154,20 +148,17 @@ public class HuaweiSmsClient extends AbstractSmsClient { | ||
| 154 | appendToBody(body, "from=", sender); | 148 | appendToBody(body, "from=", sender); |
| 155 | appendToBody(body, "&to=", receiver); | 149 | appendToBody(body, "&to=", receiver); |
| 156 | appendToBody(body, "&templateId=", templateId); | 150 | appendToBody(body, "&templateId=", templateId); |
| 157 | - // TODO @scholar:new JSONArray(templateParas).toString(),是不是 JsonUtils.toString 呀? | ||
| 158 | - appendToBody(body, "&templateParas=", new JSONArray(templateParas).toString()); | 151 | + appendToBody(body, "&templateParas=", JsonUtils.toJsonString(templateParas)); |
| 159 | appendToBody(body, "&statusCallback=", statusCallBack); | 152 | appendToBody(body, "&statusCallback=", statusCallBack); |
| 160 | appendToBody(body, "&signature=", signature); | 153 | appendToBody(body, "&signature=", signature); |
| 161 | return body.toString(); | 154 | return body.toString(); |
| 162 | } | 155 | } |
| 163 | 156 | ||
| 164 | - private static void appendToBody(StringBuilder body, String key, String val) { | ||
| 165 | - // TODO @scholar:StrUtils.isNotEmpty(val),是不是更简洁哈 | 157 | + private static void appendToBody(StringBuilder body, String key, String val) throws UnsupportedEncodingException { |
| 166 | if (null != val && !val.isEmpty()) { | 158 | if (null != val && !val.isEmpty()) { |
| 167 | - body.append(key).append(URLEncoder.encode(val, StandardCharsets.UTF_8)); | 159 | + body.append(key).append(URLEncoder.encode(val, "UTF-8")); |
| 168 | } | 160 | } |
| 169 | } | 161 | } |
| 170 | - | ||
| 171 | @Override | 162 | @Override |
| 172 | public List<SmsReceiveRespDTO> parseSmsReceiveStatus(String text) { | 163 | public List<SmsReceiveRespDTO> parseSmsReceiveStatus(String text) { |
| 173 | List<SmsReceiveStatus> statuses = JsonUtils.parseArray(text, SmsReceiveStatus.class); | 164 | List<SmsReceiveStatus> statuses = JsonUtils.parseArray(text, SmsReceiveStatus.class); |
| @@ -179,12 +170,28 @@ public class HuaweiSmsClient extends AbstractSmsClient { | @@ -179,12 +170,28 @@ public class HuaweiSmsClient extends AbstractSmsClient { | ||
| 179 | 170 | ||
| 180 | @Override | 171 | @Override |
| 181 | public SmsTemplateRespDTO getSmsTemplate(String apiTemplateId) throws Throwable { | 172 | public SmsTemplateRespDTO getSmsTemplate(String apiTemplateId) throws Throwable { |
| 182 | - // 华为短信模板查询和发送短信,是不同的两套 key 和 secret,与阿里、腾讯的区别较大,这里模板查询校验暂不实现 | ||
| 183 | - // 对应文档 https://support.huaweicloud.com/api-msgsms/sms_05_0040.html | ||
| 184 | - return new SmsTemplateRespDTO().setId(apiTemplateId).setContent(null) | 173 | + //华为短信模板查询和发送短信,是不同的两套key和secret,与阿里、腾讯的区别较大,这里模板查询校验暂不实现。 |
| 174 | + return new SmsTemplateRespDTO().setId(null).setContent(null) | ||
| 185 | .setAuditStatus(SmsTemplateAuditStatusEnum.SUCCESS.getStatus()).setAuditReason(null); | 175 | .setAuditStatus(SmsTemplateAuditStatusEnum.SUCCESS.getStatus()).setAuditReason(null); |
| 176 | + | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + @Data | ||
| 180 | + public static class SmsResponse { | ||
| 181 | + | ||
| 182 | + /** | ||
| 183 | + * 是否成功 | ||
| 184 | + */ | ||
| 185 | + private boolean success; | ||
| 186 | + | ||
| 187 | + /** | ||
| 188 | + * 厂商原返回体 | ||
| 189 | + */ | ||
| 190 | + private Object data; | ||
| 191 | + | ||
| 186 | } | 192 | } |
| 187 | 193 | ||
| 194 | + | ||
| 188 | /** | 195 | /** |
| 189 | * 短信接收状态 | 196 | * 短信接收状态 |
| 190 | * | 197 | * |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java
| @@ -82,7 +82,11 @@ public class SocialClientServiceImpl implements SocialClientService { | @@ -82,7 +82,11 @@ public class SocialClientServiceImpl implements SocialClientService { | ||
| 82 | @Value("${yudao.wxa-code.env-version:release}") | 82 | @Value("${yudao.wxa-code.env-version:release}") |
| 83 | public String envVersion; | 83 | public String envVersion; |
| 84 | /** | 84 | /** |
| 85 | - * 订阅消息跳转小程序类型:developer为开发版;trial为体验版;formal为正式版; | 85 | + * 订阅消息跳转小程序类型 |
| 86 | + * | ||
| 87 | + * 1. developer:开发版 | ||
| 88 | + * 2. trial:体验版 | ||
| 89 | + * 3. formal:正式版 | ||
| 86 | */ | 90 | */ |
| 87 | @Value("${yudao.wxa-subscribe-message.miniprogram-state:formal}") | 91 | @Value("${yudao.wxa-subscribe-message.miniprogram-state:formal}") |
| 88 | public String miniprogramState; | 92 | public String miniprogramState; |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/framework/sms/core/client/impl/AliyunSmsClientTest.java
| 1 | package cn.iocoder.yudao.module.system.framework.sms.core.client.impl; | 1 | package cn.iocoder.yudao.module.system.framework.sms.core.client.impl; |
| 2 | 2 | ||
| 3 | -import cn.hutool.core.util.ReflectUtil; | ||
| 4 | -import cn.iocoder.yudao.framework.common.core.KeyValue; | ||
| 5 | -import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | ||
| 6 | import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; | 3 | import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; |
| 7 | import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsReceiveRespDTO; | 4 | import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsReceiveRespDTO; |
| 8 | -import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsSendRespDTO; | ||
| 9 | -import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsTemplateRespDTO; | ||
| 10 | import cn.iocoder.yudao.module.system.framework.sms.core.enums.SmsTemplateAuditStatusEnum; | 5 | import cn.iocoder.yudao.module.system.framework.sms.core.enums.SmsTemplateAuditStatusEnum; |
| 11 | import cn.iocoder.yudao.module.system.framework.sms.core.property.SmsChannelProperties; | 6 | import cn.iocoder.yudao.module.system.framework.sms.core.property.SmsChannelProperties; |
| 12 | -import com.aliyuncs.IAcsClient; | ||
| 13 | -import com.aliyuncs.dysmsapi.model.v20170525.QuerySmsTemplateRequest; | ||
| 14 | -import com.aliyuncs.dysmsapi.model.v20170525.QuerySmsTemplateResponse; | ||
| 15 | -import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest; | ||
| 16 | -import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; | ||
| 17 | -import com.google.common.collect.Lists; | ||
| 18 | import org.junit.jupiter.api.Test; | 7 | import org.junit.jupiter.api.Test; |
| 19 | -import org.mockito.ArgumentMatcher; | ||
| 20 | import org.mockito.InjectMocks; | 8 | import org.mockito.InjectMocks; |
| 21 | -import org.mockito.Mock; | ||
| 22 | 9 | ||
| 23 | import java.time.LocalDateTime; | 10 | import java.time.LocalDateTime; |
| 24 | import java.util.List; | 11 | import java.util.List; |
| 25 | 12 | ||
| 26 | -import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString; | ||
| 27 | -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | 13 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString; |
| 28 | import static org.junit.jupiter.api.Assertions.*; | 14 | import static org.junit.jupiter.api.Assertions.*; |
| 29 | -import static org.mockito.ArgumentMatchers.argThat; | ||
| 30 | -import static org.mockito.Mockito.when; | ||
| 31 | 15 | ||
| 16 | +// TODO 芋艿:需要优化 | ||
| 32 | /** | 17 | /** |
| 33 | - * {@link AliyunSmsClient} 的单元测试 | 18 | + * {@link cn.iocoder.yudao.module.system.framework.sms.core.client.impl.AliyunSmsClient_old} 的单元测试 |
| 34 | * | 19 | * |
| 35 | * @author 芋道源码 | 20 | * @author 芋道源码 |
| 36 | */ | 21 | */ |
| @@ -44,9 +29,6 @@ public class AliyunSmsClientTest extends BaseMockitoUnitTest { | @@ -44,9 +29,6 @@ public class AliyunSmsClientTest extends BaseMockitoUnitTest { | ||
| 44 | @InjectMocks | 29 | @InjectMocks |
| 45 | private final AliyunSmsClient smsClient = new AliyunSmsClient(properties); | 30 | private final AliyunSmsClient smsClient = new AliyunSmsClient(properties); |
| 46 | 31 | ||
| 47 | - @Mock | ||
| 48 | - private IAcsClient client; | ||
| 49 | - | ||
| 50 | @Test | 32 | @Test |
| 51 | public void testDoInit() { | 33 | public void testDoInit() { |
| 52 | // 准备参数 | 34 | // 准备参数 |
| @@ -54,68 +36,66 @@ public class AliyunSmsClientTest extends BaseMockitoUnitTest { | @@ -54,68 +36,66 @@ public class AliyunSmsClientTest extends BaseMockitoUnitTest { | ||
| 54 | 36 | ||
| 55 | // 调用 | 37 | // 调用 |
| 56 | smsClient.doInit(); | 38 | smsClient.doInit(); |
| 57 | - // 断言 | ||
| 58 | - assertNotSame(client, ReflectUtil.getFieldValue(smsClient, "acsClient")); | ||
| 59 | - } | ||
| 60 | - | ||
| 61 | - @Test | ||
| 62 | - public void tesSendSms_success() throws Throwable { | ||
| 63 | - // 准备参数 | ||
| 64 | - Long sendLogId = randomLongId(); | ||
| 65 | - String mobile = randomString(); | ||
| 66 | - String apiTemplateId = randomString(); | ||
| 67 | - List<KeyValue<String, Object>> templateParams = Lists.newArrayList( | ||
| 68 | - new KeyValue<>("code", 1234), new KeyValue<>("op", "login")); | ||
| 69 | - // mock 方法 | ||
| 70 | - SendSmsResponse response = randomPojo(SendSmsResponse.class, o -> o.setCode("OK")); | ||
| 71 | - when(client.getAcsResponse(argThat((ArgumentMatcher<SendSmsRequest>) acsRequest -> { | ||
| 72 | - assertEquals(mobile, acsRequest.getPhoneNumbers()); | ||
| 73 | - assertEquals(properties.getSignature(), acsRequest.getSignName()); | ||
| 74 | - assertEquals(apiTemplateId, acsRequest.getTemplateCode()); | ||
| 75 | - assertEquals(toJsonString(MapUtils.convertMap(templateParams)), acsRequest.getTemplateParam()); | ||
| 76 | - assertEquals(sendLogId.toString(), acsRequest.getOutId()); | ||
| 77 | - return true; | ||
| 78 | - }))).thenReturn(response); | ||
| 79 | - | ||
| 80 | - // 调用 | ||
| 81 | - SmsSendRespDTO result = smsClient.sendSms(sendLogId, mobile, | ||
| 82 | - apiTemplateId, templateParams); | ||
| 83 | - // 断言 | ||
| 84 | - assertTrue(result.getSuccess()); | ||
| 85 | - assertEquals(response.getRequestId(), result.getApiRequestId()); | ||
| 86 | - assertEquals(response.getCode(), result.getApiCode()); | ||
| 87 | - assertEquals(response.getMessage(), result.getApiMsg()); | ||
| 88 | - assertEquals(response.getBizId(), result.getSerialNo()); | ||
| 89 | } | 39 | } |
| 90 | 40 | ||
| 91 | - @Test | ||
| 92 | - public void tesSendSms_fail() throws Throwable { | ||
| 93 | - // 准备参数 | ||
| 94 | - Long sendLogId = randomLongId(); | ||
| 95 | - String mobile = randomString(); | ||
| 96 | - String apiTemplateId = randomString(); | ||
| 97 | - List<KeyValue<String, Object>> templateParams = Lists.newArrayList( | ||
| 98 | - new KeyValue<>("code", 1234), new KeyValue<>("op", "login")); | ||
| 99 | - // mock 方法 | ||
| 100 | - SendSmsResponse response = randomPojo(SendSmsResponse.class, o -> o.setCode("ERROR")); | ||
| 101 | - when(client.getAcsResponse(argThat((ArgumentMatcher<SendSmsRequest>) acsRequest -> { | ||
| 102 | - assertEquals(mobile, acsRequest.getPhoneNumbers()); | ||
| 103 | - assertEquals(properties.getSignature(), acsRequest.getSignName()); | ||
| 104 | - assertEquals(apiTemplateId, acsRequest.getTemplateCode()); | ||
| 105 | - assertEquals(toJsonString(MapUtils.convertMap(templateParams)), acsRequest.getTemplateParam()); | ||
| 106 | - assertEquals(sendLogId.toString(), acsRequest.getOutId()); | ||
| 107 | - return true; | ||
| 108 | - }))).thenReturn(response); | ||
| 109 | - | ||
| 110 | - // 调用 | ||
| 111 | - SmsSendRespDTO result = smsClient.sendSms(sendLogId, mobile, apiTemplateId, templateParams); | ||
| 112 | - // 断言 | ||
| 113 | - assertFalse(result.getSuccess()); | ||
| 114 | - assertEquals(response.getRequestId(), result.getApiRequestId()); | ||
| 115 | - assertEquals(response.getCode(), result.getApiCode()); | ||
| 116 | - assertEquals(response.getMessage(), result.getApiMsg()); | ||
| 117 | - assertEquals(response.getBizId(), result.getSerialNo()); | ||
| 118 | - } | 41 | +// @Test |
| 42 | +// public void tesSendSms_success() throws Throwable { | ||
| 43 | +// // 准备参数 | ||
| 44 | +// Long sendLogId = randomLongId(); | ||
| 45 | +// String mobile = randomString(); | ||
| 46 | +// String apiTemplateId = randomString(); | ||
| 47 | +// List<KeyValue<String, Object>> templateParams = Lists.newArrayList( | ||
| 48 | +// new KeyValue<>("code", 1234), new KeyValue<>("op", "login")); | ||
| 49 | +// // mock 方法 | ||
| 50 | +// SendSmsResponse response = randomPojo(SendSmsResponse.class, o -> o.setCode("OK")); | ||
| 51 | +// when(client.getAcsResponse(argThat((ArgumentMatcher<SendSmsRequest>) acsRequest -> { | ||
| 52 | +// assertEquals(mobile, acsRequest.getPhoneNumbers()); | ||
| 53 | +// assertEquals(properties.getSignature(), acsRequest.getSignName()); | ||
| 54 | +// assertEquals(apiTemplateId, acsRequest.getTemplateCode()); | ||
| 55 | +// assertEquals(toJsonString(MapUtils.convertMap(templateParams)), acsRequest.getTemplateParam()); | ||
| 56 | +// assertEquals(sendLogId.toString(), acsRequest.getOutId()); | ||
| 57 | +// return true; | ||
| 58 | +// }))).thenReturn(response); | ||
| 59 | +// | ||
| 60 | +// // 调用 | ||
| 61 | +// SmsSendRespDTO result = smsClient.sendSms(sendLogId, mobile, | ||
| 62 | +// apiTemplateId, templateParams); | ||
| 63 | +// // 断言 | ||
| 64 | +// assertTrue(result.getSuccess()); | ||
| 65 | +// assertEquals(response.getRequestId(), result.getApiRequestId()); | ||
| 66 | +// assertEquals(response.getCode(), result.getApiCode()); | ||
| 67 | +// assertEquals(response.getMessage(), result.getApiMsg()); | ||
| 68 | +// assertEquals(response.getBizId(), result.getSerialNo()); | ||
| 69 | +// } | ||
| 70 | + | ||
| 71 | +// @Test | ||
| 72 | +// public void tesSendSms_fail() throws Throwable { | ||
| 73 | +// // 准备参数 | ||
| 74 | +// Long sendLogId = randomLongId(); | ||
| 75 | +// String mobile = randomString(); | ||
| 76 | +// String apiTemplateId = randomString(); | ||
| 77 | +// List<KeyValue<String, Object>> templateParams = Lists.newArrayList( | ||
| 78 | +// new KeyValue<>("code", 1234), new KeyValue<>("op", "login")); | ||
| 79 | +// // mock 方法 | ||
| 80 | +// SendSmsResponse response = randomPojo(SendSmsResponse.class, o -> o.setCode("ERROR")); | ||
| 81 | +// when(client.getAcsResponse(argThat((ArgumentMatcher<SendSmsRequest>) acsRequest -> { | ||
| 82 | +// assertEquals(mobile, acsRequest.getPhoneNumbers()); | ||
| 83 | +// assertEquals(properties.getSignature(), acsRequest.getSignName()); | ||
| 84 | +// assertEquals(apiTemplateId, acsRequest.getTemplateCode()); | ||
| 85 | +// assertEquals(toJsonString(MapUtils.convertMap(templateParams)), acsRequest.getTemplateParam()); | ||
| 86 | +// assertEquals(sendLogId.toString(), acsRequest.getOutId()); | ||
| 87 | +// return true; | ||
| 88 | +// }))).thenReturn(response); | ||
| 89 | +// | ||
| 90 | +// // 调用 | ||
| 91 | +// SmsSendRespDTO result = smsClient.sendSms(sendLogId, mobile, apiTemplateId, templateParams); | ||
| 92 | +// // 断言 | ||
| 93 | +// assertFalse(result.getSuccess()); | ||
| 94 | +// assertEquals(response.getRequestId(), result.getApiRequestId()); | ||
| 95 | +// assertEquals(response.getCode(), result.getApiCode()); | ||
| 96 | +// assertEquals(response.getMessage(), result.getApiMsg()); | ||
| 97 | +// assertEquals(response.getBizId(), result.getSerialNo()); | ||
| 98 | +// } | ||
| 119 | 99 | ||
| 120 | @Test | 100 | @Test |
| 121 | public void testParseSmsReceiveStatus() { | 101 | public void testParseSmsReceiveStatus() { |
| @@ -149,28 +129,28 @@ public class AliyunSmsClientTest extends BaseMockitoUnitTest { | @@ -149,28 +129,28 @@ public class AliyunSmsClientTest extends BaseMockitoUnitTest { | ||
| 149 | assertEquals(67890L, statuses.get(0).getLogId()); | 129 | assertEquals(67890L, statuses.get(0).getLogId()); |
| 150 | } | 130 | } |
| 151 | 131 | ||
| 152 | - @Test | ||
| 153 | - public void testGetSmsTemplate() throws Throwable { | ||
| 154 | - // 准备参数 | ||
| 155 | - String apiTemplateId = randomString(); | ||
| 156 | - // mock 方法 | ||
| 157 | - QuerySmsTemplateResponse response = randomPojo(QuerySmsTemplateResponse.class, o -> { | ||
| 158 | - o.setCode("OK"); | ||
| 159 | - o.setTemplateStatus(1); // 设置模板通过 | ||
| 160 | - }); | ||
| 161 | - when(client.getAcsResponse(argThat((ArgumentMatcher<QuerySmsTemplateRequest>) acsRequest -> { | ||
| 162 | - assertEquals(apiTemplateId, acsRequest.getTemplateCode()); | ||
| 163 | - return true; | ||
| 164 | - }))).thenReturn(response); | ||
| 165 | - | ||
| 166 | - // 调用 | ||
| 167 | - SmsTemplateRespDTO result = smsClient.getSmsTemplate(apiTemplateId); | ||
| 168 | - // 断言 | ||
| 169 | - assertEquals(response.getTemplateCode(), result.getId()); | ||
| 170 | - assertEquals(response.getTemplateContent(), result.getContent()); | ||
| 171 | - assertEquals(SmsTemplateAuditStatusEnum.SUCCESS.getStatus(), result.getAuditStatus()); | ||
| 172 | - assertEquals(response.getReason(), result.getAuditReason()); | ||
| 173 | - } | 132 | +// @Test |
| 133 | +// public void testGetSmsTemplate() throws Throwable { | ||
| 134 | +// // 准备参数 | ||
| 135 | +// String apiTemplateId = randomString(); | ||
| 136 | +// // mock 方法 | ||
| 137 | +// QuerySmsTemplateResponse response = randomPojo(QuerySmsTemplateResponse.class, o -> { | ||
| 138 | +// o.setCode("OK"); | ||
| 139 | +// o.setTemplateStatus(1); // 设置模板通过 | ||
| 140 | +// }); | ||
| 141 | +// when(client.getAcsResponse(argThat((ArgumentMatcher<QuerySmsTemplateRequest>) acsRequest -> { | ||
| 142 | +// assertEquals(apiTemplateId, acsRequest.getTemplateCode()); | ||
| 143 | +// return true; | ||
| 144 | +// }))).thenReturn(response); | ||
| 145 | +// | ||
| 146 | +// // 调用 | ||
| 147 | +// SmsTemplateRespDTO result = smsClient.getSmsTemplate(apiTemplateId); | ||
| 148 | +// // 断言 | ||
| 149 | +// assertEquals(response.getTemplateCode(), result.getId()); | ||
| 150 | +// assertEquals(response.getTemplateContent(), result.getContent()); | ||
| 151 | +// assertEquals(SmsTemplateAuditStatusEnum.SUCCESS.getStatus(), result.getAuditStatus()); | ||
| 152 | +// assertEquals(response.getReason(), result.getAuditReason()); | ||
| 153 | +// } | ||
| 174 | 154 | ||
| 175 | @Test | 155 | @Test |
| 176 | public void testConvertSmsTemplateAuditStatus() { | 156 | public void testConvertSmsTemplateAuditStatus() { |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/framework/sms/core/client/impl/SmsClientTests.java
| 1 | package cn.iocoder.yudao.module.system.framework.sms.core.client.impl; | 1 | package cn.iocoder.yudao.module.system.framework.sms.core.client.impl; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.core.KeyValue; | 3 | import cn.iocoder.yudao.framework.common.core.KeyValue; |
| 4 | +import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsReceiveRespDTO; | ||
| 4 | import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsSendRespDTO; | 5 | import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsSendRespDTO; |
| 6 | +import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsTemplateRespDTO; | ||
| 5 | import cn.iocoder.yudao.module.system.framework.sms.core.property.SmsChannelProperties; | 7 | import cn.iocoder.yudao.module.system.framework.sms.core.property.SmsChannelProperties; |
| 6 | import org.junit.jupiter.api.Disabled; | 8 | import org.junit.jupiter.api.Disabled; |
| 7 | import org.junit.jupiter.api.Test; | 9 | import org.junit.jupiter.api.Test; |
| @@ -17,7 +19,7 @@ public class SmsClientTests { | @@ -17,7 +19,7 @@ public class SmsClientTests { | ||
| 17 | 19 | ||
| 18 | @Test | 20 | @Test |
| 19 | @Disabled | 21 | @Disabled |
| 20 | - public void testHuaweiSmsClient() throws Throwable { | 22 | + public void testHuaweiSmsClient_sendSms() throws Throwable { |
| 21 | SmsChannelProperties properties = new SmsChannelProperties() | 23 | SmsChannelProperties properties = new SmsChannelProperties() |
| 22 | .setApiKey("123") | 24 | .setApiKey("123") |
| 23 | .setApiSecret("456"); | 25 | .setApiSecret("456"); |
| @@ -33,4 +35,67 @@ public class SmsClientTests { | @@ -33,4 +35,67 @@ public class SmsClientTests { | ||
| 33 | System.out.println(smsSendRespDTO); | 35 | System.out.println(smsSendRespDTO); |
| 34 | } | 36 | } |
| 35 | 37 | ||
| 38 | + // ========== 阿里云 ========== | ||
| 39 | + | ||
| 40 | + @Test | ||
| 41 | + @Disabled | ||
| 42 | + public void testAliyunSmsClient_getSmsTemplate() throws Throwable { | ||
| 43 | + SmsChannelProperties properties = new SmsChannelProperties() | ||
| 44 | + .setApiKey("LTAI5tAicJAxaSFiZuGGeXHR") | ||
| 45 | + .setApiSecret("Fdr9vadxnDvS6GJU0W1tijQ0VmLhYz"); | ||
| 46 | + AliyunSmsClient client = new AliyunSmsClient(properties); | ||
| 47 | + // 准备参数 | ||
| 48 | + String apiTemplateId = "SMS_207945135"; | ||
| 49 | + // 调用 | ||
| 50 | + SmsTemplateRespDTO template = client.getSmsTemplate(apiTemplateId); | ||
| 51 | + // 打印结果 | ||
| 52 | + System.out.println(template); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + @Test | ||
| 56 | + @Disabled | ||
| 57 | + public void testAliyunSmsClient_sendSms() throws Throwable { | ||
| 58 | + SmsChannelProperties properties = new SmsChannelProperties() | ||
| 59 | + .setApiKey("LTAI5tAicJAxaSFiZuGGeXHR") | ||
| 60 | + .setApiSecret("Fdr9vadxnDvS6GJU0W1tijQ0VmLhYz"); | ||
| 61 | + AliyunSmsClient client = new AliyunSmsClient(properties); | ||
| 62 | + // 准备参数 | ||
| 63 | + Long sendLogId = System.currentTimeMillis(); | ||
| 64 | + String mobile = "17321315478"; | ||
| 65 | + String apiTemplateId = "SMS_207945135"; | ||
| 66 | + // 调用 | ||
| 67 | + SmsSendRespDTO sendRespDTO = client.sendSms(sendLogId, mobile, apiTemplateId, List.of(new KeyValue<>("code", "1024"))); | ||
| 68 | + // 打印结果 | ||
| 69 | + System.out.println(sendRespDTO); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + @Test | ||
| 73 | + @Disabled | ||
| 74 | + public void testAliyunSmsClient_parseSmsReceiveStatus() { | ||
| 75 | + SmsChannelProperties properties = new SmsChannelProperties() | ||
| 76 | + .setApiKey("LTAI5tAicJAxaSFiZuGGeXHR") | ||
| 77 | + .setApiSecret("Fdr9vadxnDvS6GJU0W1tijQ0VmLhYz"); | ||
| 78 | + AliyunSmsClient client = new AliyunSmsClient(properties); | ||
| 79 | + // 准备参数 | ||
| 80 | + String text = "[\n" + | ||
| 81 | + " {\n" + | ||
| 82 | + " \"phone_number\" : \"13900000001\",\n" + | ||
| 83 | + " \"send_time\" : \"2017-01-01 11:12:13\",\n" + | ||
| 84 | + " \"report_time\" : \"2017-02-02 22:23:24\",\n" + | ||
| 85 | + " \"success\" : true,\n" + | ||
| 86 | + " \"err_code\" : \"DELIVERED\",\n" + | ||
| 87 | + " \"err_msg\" : \"用户接收成功\",\n" + | ||
| 88 | + " \"sms_size\" : \"1\",\n" + | ||
| 89 | + " \"biz_id\" : \"12345\",\n" + | ||
| 90 | + " \"out_id\" : \"67890\"\n" + | ||
| 91 | + " }\n" + | ||
| 92 | + "]"; | ||
| 93 | + // mock 方法 | ||
| 94 | + | ||
| 95 | + // 调用 | ||
| 96 | + List<SmsReceiveRespDTO> statuses = client.parseSmsReceiveStatus(text); | ||
| 97 | + // 打印结果 | ||
| 98 | + System.out.println(statuses); | ||
| 99 | + } | ||
| 100 | + | ||
| 36 | } | 101 | } |
yudao-server/src/main/resources/application-local.yaml
| @@ -224,7 +224,7 @@ yudao: | @@ -224,7 +224,7 @@ yudao: | ||
| 224 | wxa-code: | 224 | wxa-code: |
| 225 | env-version: develop # 小程序版本: 正式版为 "release";体验版为 "trial";开发版为 "develop" | 225 | env-version: develop # 小程序版本: 正式版为 "release";体验版为 "trial";开发版为 "develop" |
| 226 | wxa-subscribe-message: | 226 | wxa-subscribe-message: |
| 227 | - miniprogram-state: developer # 跳转小程序类型:developer为开发版;trial为体验版;formal为正式版; | 227 | + miniprogram-state: developer # 跳转小程序类型:开发版为 “developer”;体验版为 “trial”为;正式版为 “formal” |
| 228 | tencent-lbs-key: TVDBZ-TDILD-4ON4B-PFDZA-RNLKH-VVF6E # QQ 地图的密钥 https://lbs.qq.com/service/staticV2/staticGuide/staticDoc | 228 | tencent-lbs-key: TVDBZ-TDILD-4ON4B-PFDZA-RNLKH-VVF6E # QQ 地图的密钥 https://lbs.qq.com/service/staticV2/staticGuide/staticDoc |
| 229 | 229 | ||
| 230 | justauth: | 230 | justauth: |