diff --git a/.flattened-pom.xml b/.flattened-pom.xml index 22918bc4..45c77047 100644 --- a/.flattened-pom.xml +++ b/.flattened-pom.xml @@ -24,16 +24,17 @@ - sms-aggregation-api sms-aggregation-comm - sms-aggregation-aliyun - sms-aggregation-unisms - sms-aggregation-tencent - sms-aggregation-yunpian - sms-aggregation-spring-boot-starter - sms-aggregation-huawei - sms-aggregation-autoimmit + sms-aggregation-api sms-aggregation-core + sms-aggregation-autoimmit + sms-aggregation-spring-boot-starter + sms-aggregation-aliyun + sms-aggregation-tencent + sms-aggregation-unisms + sms-aggregation-yunpian + sms-aggregation-huawei + sms-aggregation-jdcloud scm:git:https://gitee.com/MR-wind/sms_aggregation.git @@ -61,6 +62,7 @@ 5.8.16 3.1.622 1.0.5 + 1.3.3 @@ -76,6 +78,31 @@ spring-boot-starter ${spring.boot.version} + + kim.wind + sms-aggregation-spring-boot-starter + 1.0.5 + + + kim.wind + sms-aggregation-autoimmit + 1.0.5 + + + kim.wind + sms-aggregation-core + 1.0.5 + + + kim.wind + sms-aggregation-comm + 1.0.5 + + + kim.wind + sms-aggregation-api + 1.0.5 + kim.wind sms-aggregation-aliyun @@ -103,27 +130,7 @@ kim.wind - sms-aggregation-spring-boot-starter - 1.0.5 - - - kim.wind - sms-aggregation-autoimmit - 1.0.5 - - - kim.wind - sms-aggregation-core - 1.0.5 - - - kim.wind - sms-aggregation-comm - 1.0.5 - - - kim.wind - sms-aggregation-api + sms-aggregation-jdcloud 1.0.5 @@ -180,6 +187,11 @@ + + com.jdcloud.sdk + sms + ${jdcloud.version} + com.squareup.okhttp3 okhttp diff --git a/pom.xml b/pom.xml index bcd5922a..e7e1ff8d 100644 --- a/pom.xml +++ b/pom.xml @@ -11,16 +11,17 @@ https://gitee.com/dromara/sms_aggregation - sms-aggregation-api sms-aggregation-comm - sms-aggregation-aliyun - sms-aggregation-unisms - sms-aggregation-tencent - sms-aggregation-yunpian - sms-aggregation-spring-boot-starter - sms-aggregation-huawei - sms-aggregation-autoimmit + sms-aggregation-api sms-aggregation-core + sms-aggregation-autoimmit + sms-aggregation-spring-boot-starter + sms-aggregation-aliyun + sms-aggregation-tencent + sms-aggregation-unisms + sms-aggregation-yunpian + sms-aggregation-huawei + sms-aggregation-jdcloud @@ -53,10 +54,11 @@ 2.7.10 1.0.5 2.0.23 + 3.1.622 + 0.0.4 + 1.3.3 2.0.15 3.14.9 - 0.0.4 - 3.1.622 1.5.30 5.8.16 3.14.9 @@ -79,6 +81,38 @@ ${spring.boot.version} + + kim.wind + sms-aggregation-spring-boot-starter + ${revision} + + + + kim.wind + sms-aggregation-autoimmit + ${revision} + + + + kim.wind + sms-aggregation-core + ${revision} + + + + + kim.wind + sms-aggregation-comm + ${revision} + + + + + kim.wind + sms-aggregation-api + ${revision} + + kim.wind sms-aggregation-aliyun @@ -111,33 +145,7 @@ kim.wind - sms-aggregation-spring-boot-starter - ${revision} - - - - kim.wind - sms-aggregation-autoimmit - ${revision} - - - - kim.wind - sms-aggregation-core - ${revision} - - - - - kim.wind - sms-aggregation-comm - ${revision} - - - - - kim.wind - sms-aggregation-api + sms-aggregation-jdcloud ${revision} @@ -208,6 +216,14 @@ + + + + com.jdcloud.sdk + sms + ${jdcloud.version} + + com.squareup.okhttp3 diff --git a/sms-aggregation-autoimmit/src/main/java/org/dromara/sms/autoimmit/config/SupplierConfig.java b/sms-aggregation-autoimmit/src/main/java/org/dromara/sms/autoimmit/config/SupplierConfig.java index a64ea963..9c2e889c 100644 --- a/sms-aggregation-autoimmit/src/main/java/org/dromara/sms/autoimmit/config/SupplierConfig.java +++ b/sms-aggregation-autoimmit/src/main/java/org/dromara/sms/autoimmit/config/SupplierConfig.java @@ -3,6 +3,7 @@ package org.dromara.sms.autoimmit.config; import org.dromara.sms.aliyun.config.AlibabaConfig; import org.dromara.sms.core.config.SupplierFactory; import org.dromara.sms.huawei.config.HuaweiConfig; +import org.dromara.sms.jdcloud.config.JdCloudConfig; import org.dromara.sms.tencent.config.TencentConfig; import org.dromara.sms.unisms.config.UniConfig; import org.dromara.sms.yunpian.config.YunpianConfig; @@ -44,4 +45,11 @@ public class SupplierConfig { protected TencentConfig tencentConfig(){ return SupplierFactory.getTencentConfig(); } + + /** 京东云短信差异化配置 */ + @Bean + @ConfigurationProperties(prefix = "sms.jdcloud") + protected JdCloudConfig jdCloudConfig(){ + return SupplierFactory.getJdCloudConfig(); + } } diff --git a/sms-aggregation-comm/src/main/java/org/dromara/sms/comm/enumerate/SupplierType.java b/sms-aggregation-comm/src/main/java/org/dromara/sms/comm/enumerate/SupplierType.java index 44d59ac6..520261ca 100644 --- a/sms-aggregation-comm/src/main/java/org/dromara/sms/comm/enumerate/SupplierType.java +++ b/sms-aggregation-comm/src/main/java/org/dromara/sms/comm/enumerate/SupplierType.java @@ -16,7 +16,9 @@ public enum SupplierType { /** 腾讯云*/ TENCENT("腾讯云短信"), /** 合一短信*/ - UNI_SMS("合一短信") + UNI_SMS("合一短信"), + /** 京东云 */ + JD_CLOUD("京东云短信"), ; diff --git a/sms-aggregation-core/.flattened-pom.xml b/sms-aggregation-core/.flattened-pom.xml index b927f7a2..cc27c480 100644 --- a/sms-aggregation-core/.flattened-pom.xml +++ b/sms-aggregation-core/.flattened-pom.xml @@ -41,6 +41,10 @@ kim.wind sms-aggregation-huawei + + kim.wind + sms-aggregation-jdcloud + diff --git a/sms-aggregation-core/pom.xml b/sms-aggregation-core/pom.xml index 0677aca8..51ab6c95 100644 --- a/sms-aggregation-core/pom.xml +++ b/sms-aggregation-core/pom.xml @@ -40,6 +40,11 @@ kim.wind sms-aggregation-huawei + + + kim.wind + sms-aggregation-jdcloud + diff --git a/sms-aggregation-core/src/main/java/org/dromara/sms/core/config/SupplierFactory.java b/sms-aggregation-core/src/main/java/org/dromara/sms/core/config/SupplierFactory.java index d77a8b41..c15b157a 100644 --- a/sms-aggregation-core/src/main/java/org/dromara/sms/core/config/SupplierFactory.java +++ b/sms-aggregation-core/src/main/java/org/dromara/sms/core/config/SupplierFactory.java @@ -2,6 +2,7 @@ package org.dromara.sms.core.config; import org.dromara.sms.aliyun.config.AlibabaConfig; import org.dromara.sms.huawei.config.HuaweiConfig; +import org.dromara.sms.jdcloud.config.JdCloudConfig; import org.dromara.sms.tencent.config.TencentConfig; import org.dromara.sms.unisms.config.UniConfig; import org.dromara.sms.yunpian.config.YunpianConfig; @@ -31,6 +32,9 @@ public class SupplierFactory { /** 云片短信差异配置*/ private static YunpianConfig yunpianConfig; + /** 京东云短信差异配置 */ + private static JdCloudConfig jdCloudConfig; + /** 阿里云配置获取*/ public static AlibabaConfig getAlibabaConfig() { if (alibabaConfig == null){ @@ -70,4 +74,12 @@ public class SupplierFactory { } return yunpianConfig; } + + /** 京东云短信配置获取 */ + public static JdCloudConfig getJdCloudConfig() { + if (jdCloudConfig == null){ + jdCloudConfig = new JdCloudConfig(); + } + return jdCloudConfig; + } } diff --git a/sms-aggregation-core/src/main/java/org/dromara/sms/core/factory/SmsFactory.java b/sms-aggregation-core/src/main/java/org/dromara/sms/core/factory/SmsFactory.java index efadcbd5..fbcfff67 100644 --- a/sms-aggregation-core/src/main/java/org/dromara/sms/core/factory/SmsFactory.java +++ b/sms-aggregation-core/src/main/java/org/dromara/sms/core/factory/SmsFactory.java @@ -6,6 +6,7 @@ import org.dromara.sms.comm.enumerate.SupplierType; import org.dromara.sms.comm.exception.SmsBlendException; import org.dromara.sms.core.config.SupplierFactory; import org.dromara.sms.huawei.config.HuaweiSmsConfig; +import org.dromara.sms.jdcloud.config.JdCloudSmsConfig; import org.dromara.sms.tencent.config.TencentSmsConfig; import org.dromara.sms.unisms.config.UniSmsConfig; @@ -34,6 +35,8 @@ public class SmsFactory { return UniSmsConfig.createUniSms(SupplierFactory.getUniConfig()); case TENCENT: return TencentSmsConfig.createTencentSms(SupplierFactory.getTencentConfig()); + case JD_CLOUD: + return JdCloudSmsConfig.createJdCloudSms(SupplierFactory.getJdCloudConfig()); } throw new SmsBlendException("An attempt to construct a SmsBlend object failed. Please check that the enumeration is valid"); } diff --git a/sms-aggregation-jdcloud/.flattened-pom.xml b/sms-aggregation-jdcloud/.flattened-pom.xml new file mode 100644 index 00000000..a89983e6 --- /dev/null +++ b/sms-aggregation-jdcloud/.flattened-pom.xml @@ -0,0 +1,37 @@ + + + 4.0.0 + + kim.wind + sms_aggregation + 1.0.5 + + kim.wind + sms-aggregation-jdcloud + 1.0.5 + sms-aggregation-jdcloud + sms-aggregation-jdcloud + + + Apache 2 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + A business-friendly OSS license + + + + + com.jdcloud.sdk + sms + + + kim.wind + sms-aggregation-comm + + + kim.wind + sms-aggregation-api + + + diff --git a/sms-aggregation-jdcloud/.mvn/wrapper/maven-wrapper.jar b/sms-aggregation-jdcloud/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 00000000..bf82ff01 Binary files /dev/null and b/sms-aggregation-jdcloud/.mvn/wrapper/maven-wrapper.jar differ diff --git a/sms-aggregation-jdcloud/.mvn/wrapper/maven-wrapper.properties b/sms-aggregation-jdcloud/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 00000000..ca5ab4ba --- /dev/null +++ b/sms-aggregation-jdcloud/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar diff --git a/sms-aggregation-jdcloud/pom.xml b/sms-aggregation-jdcloud/pom.xml new file mode 100644 index 00000000..73c27fac --- /dev/null +++ b/sms-aggregation-jdcloud/pom.xml @@ -0,0 +1,35 @@ + + + 4.0.0 + + kim.wind + sms_aggregation + ${revision} + ../pom.xml + + + sms-aggregation-jdcloud + sms-aggregation-jdcloud + sms-aggregation-jdcloud + ${revision} + + + + + com.jdcloud.sdk + sms + + + + kim.wind + sms-aggregation-comm + + + + kim.wind + sms-aggregation-api + + + \ No newline at end of file diff --git a/sms-aggregation-jdcloud/src/main/java/org/dromara/sms/jdcloud/config/JdCloudConfig.java b/sms-aggregation-jdcloud/src/main/java/org/dromara/sms/jdcloud/config/JdCloudConfig.java new file mode 100644 index 00000000..83982ad5 --- /dev/null +++ b/sms-aggregation-jdcloud/src/main/java/org/dromara/sms/jdcloud/config/JdCloudConfig.java @@ -0,0 +1,28 @@ +package org.dromara.sms.jdcloud.config; + +import lombok.Data; + +/** + * 京东云短信配置属性 + * + * @author Charles7c + * @since 2023/4/10 20:01 + */ +@Data +public class JdCloudConfig { + + /** Access Key */ + private String accessKeyId; + + /** Access Key Secret */ + private String accessKeySecret; + + /** 短信签名 */ + private String signature; + + /** 模板 ID */ + private String templateId; + + /** 地域信息 */ + private String region = "cn-north-1"; +} diff --git a/sms-aggregation-jdcloud/src/main/java/org/dromara/sms/jdcloud/config/JdCloudSmsConfig.java b/sms-aggregation-jdcloud/src/main/java/org/dromara/sms/jdcloud/config/JdCloudSmsConfig.java new file mode 100644 index 00000000..7b10b746 --- /dev/null +++ b/sms-aggregation-jdcloud/src/main/java/org/dromara/sms/jdcloud/config/JdCloudSmsConfig.java @@ -0,0 +1,69 @@ +package org.dromara.sms.jdcloud.config; + +import com.jdcloud.sdk.auth.CredentialsProvider; +import com.jdcloud.sdk.auth.StaticCredentialsProvider; +import com.jdcloud.sdk.http.HttpRequestConfig; +import com.jdcloud.sdk.http.Protocol; +import com.jdcloud.sdk.service.sms.client.SmsClient; +import org.dromara.sms.comm.factory.BeanFactory; +import org.dromara.sms.jdcloud.service.JdCloudSmsImpl; + +/** + * 京东云短信配置 + * + * @author Charles7c + * @since 2023/4/10 20:01 + */ +public class JdCloudSmsConfig { + + private static JdCloudSmsImpl jdCloudSms; + + private static JdCloudSmsConfig jdCloudSmsConfig; + + /** + * 客户端对象 + * + * @param jdCloudConfig 京东云短信配置属性 + * @return 客户端对象 + */ + public SmsClient client(JdCloudConfig jdCloudConfig) { + CredentialsProvider credentialsProvider = new StaticCredentialsProvider(jdCloudConfig.getAccessKeyId(), + jdCloudConfig.getAccessKeySecret()); + return SmsClient.builder().credentialsProvider(credentialsProvider) + .httpRequestConfig(new HttpRequestConfig.Builder().protocol(Protocol.HTTP).build()).build(); + } + + /** + * 创建京东云短信实现 + */ + public static JdCloudSmsImpl createJdCloudSms(JdCloudConfig jdCloudConfig) { + if (jdCloudSmsConfig == null) { + jdCloudSmsConfig = new JdCloudSmsConfig(); + } + if (jdCloudSms == null) { + jdCloudSms = new JdCloudSmsImpl( + jdCloudSmsConfig.client(jdCloudConfig), + jdCloudConfig, + BeanFactory.getExecutor(), + BeanFactory.getDelayedTime() + ); + } + return jdCloudSms; + } + + /** + * 刷新对象 + */ + public static JdCloudSmsImpl refresh(JdCloudConfig jdCloudConfig) { + if (jdCloudSmsConfig == null) { + jdCloudSmsConfig = new JdCloudSmsConfig(); + } + jdCloudSms = new JdCloudSmsImpl( + jdCloudSmsConfig.client(jdCloudConfig), + jdCloudConfig, + BeanFactory.getExecutor(), + BeanFactory.getDelayedTime() + ); + return jdCloudSms; + } +} diff --git a/sms-aggregation-jdcloud/src/main/java/org/dromara/sms/jdcloud/service/JdCloudSmsImpl.java b/sms-aggregation-jdcloud/src/main/java/org/dromara/sms/jdcloud/service/JdCloudSmsImpl.java new file mode 100644 index 00000000..674f6e44 --- /dev/null +++ b/sms-aggregation-jdcloud/src/main/java/org/dromara/sms/jdcloud/service/JdCloudSmsImpl.java @@ -0,0 +1,181 @@ +package org.dromara.sms.jdcloud.service; + +import cn.hutool.core.util.IdUtil; +import com.jdcloud.sdk.service.sms.client.SmsClient; +import com.jdcloud.sdk.service.sms.model.BatchSendRequest; +import com.jdcloud.sdk.service.sms.model.BatchSendResult; +import lombok.extern.slf4j.Slf4j; +import org.dromara.sms.api.SmsBlend; +import org.dromara.sms.api.callback.CallBack; +import org.dromara.sms.api.entity.SmsResponse; +import org.dromara.sms.comm.annotation.Restricted; +import org.dromara.sms.comm.delayedTime.DelayedTime; +import org.dromara.sms.comm.exception.SmsBlendException; +import org.dromara.sms.jdcloud.config.JdCloudConfig; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.TimerTask; +import java.util.concurrent.Executor; +import java.util.stream.Collectors; + +/** + * 京东云短信实现 + * + * @author Charles7c + * @since 2023/4/10 20:01 + */ +@Slf4j +public class JdCloudSmsImpl implements SmsBlend { + + private final SmsClient client; + + private final JdCloudConfig config; + + private final Executor pool; + + private final DelayedTime delayed; + + public JdCloudSmsImpl(SmsClient client, JdCloudConfig config, Executor pool, DelayedTime delayed) { + this.client = client; + this.config = config; + this.pool = pool; + this.delayed = delayed; + } + + @Override + @Restricted + public SmsResponse sendMessage(String phone, String message) { + return massTexting(Collections.singletonList(phone), message); + } + + @Override + @Restricted + public SmsResponse sendMessage(String phone, String templateId, LinkedHashMap messages) { + return massTexting(Collections.singletonList(phone), templateId, messages); + } + + @Override + @Restricted + public SmsResponse massTexting(List phones, String message) { + LinkedHashMap map = new LinkedHashMap<>(); + map.put(IdUtil.fastSimpleUUID(), message); + return massTexting(phones, config.getTemplateId(), map); + } + + @Override + @Restricted + public SmsResponse massTexting(List phones, String templateId, LinkedHashMap messages) { + try { + BatchSendRequest request = new BatchSendRequest(); + request.setPhoneList(phones); + request.setRegionId(config.getRegion()); + request.setTemplateId(templateId); + request.setSignId(config.getSignature()); + List params = messages.entrySet().stream().map(messages::get) + .collect(Collectors.toList()); + request.setParams(params); + + BatchSendResult result = client.batchSend(request).getResult(); + return getSmsResponse(result); + } catch (Exception e) { + throw new SmsBlendException(e.getMessage()); + } + } + + @Override + @Restricted + public void sendMessageAsync(String phone, String message, CallBack callBack) { + pool.execute(() -> { + SmsResponse smsResponse = sendMessage(phone, message); + callBack.callBack(smsResponse); + }); + } + + @Override + @Restricted + public void sendMessageAsync(String phone, String message) { + pool.execute(() -> sendMessage(phone, message)); + } + + @Override + @Restricted + public void sendMessageAsync(String phone, String templateId, LinkedHashMap messages, CallBack callBack) { + pool.execute(() -> { + SmsResponse smsResponse = sendMessage(phone, templateId, messages); + callBack.callBack(smsResponse); + }); + } + + @Override + @Restricted + public void sendMessageAsync(String phone, String templateId, LinkedHashMap messages) { + pool.execute(() -> sendMessage(phone, templateId, messages)); + } + + @Override + @Restricted + public void delayedMessage(String phone, String message, Long delayedTime) { + this.delayed.schedule(new TimerTask() { + @Override + public void run() { + sendMessage(phone, message); + } + }, delayedTime); + } + + @Override + @Restricted + public void delayedMessage(String phone, String templateId, LinkedHashMap messages, Long delayedTime) { + this.delayed.schedule(new TimerTask() { + @Override + public void run() { + sendMessage(phone, templateId, messages); + } + }, delayedTime); + } + + @Override + @Restricted + public void delayMassTexting(List phones, String message, Long delayedTime) { + this.delayed.schedule(new TimerTask() { + @Override + public void run() { + massTexting(phones, message); + } + }, delayedTime); + } + + @Override + @Restricted + public void delayMassTexting(List phones, String templateId, LinkedHashMap messages, Long delayedTime) { + this.delayed.schedule(new TimerTask() { + @Override + public void run() { + massTexting(phones, templateId, messages); + } + }, delayedTime); + } + + /** + * 获取短信返回信息 + * + * @param res 云商原始响应信息 + * @return 发送短信返回信息 + */ + private SmsResponse getSmsResponse(BatchSendResult res) { + SmsResponse smsResponse = new SmsResponse(); + smsResponse.setBizId(res.getData().getSequenceNumber()); + smsResponse.setData(res.getData()); + smsResponse.setCode(String.valueOf(res.getCode())); + smsResponse.setMessage(res.getMessage()); + Boolean status = res.getStatus(); + boolean isSuccess = status != null && status; + if (!isSuccess) { + smsResponse.setErrMessage(res.getMessage()); + smsResponse.setErrorCode(String.valueOf(res.getCode())); + } + return smsResponse; + } +} diff --git a/sms-aggregation-jdcloud/src/main/resources/application.properties b/sms-aggregation-jdcloud/src/main/resources/application.properties new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/sms-aggregation-jdcloud/src/main/resources/application.properties @@ -0,0 +1 @@ +