diff --git a/ThunderSoft_smstx/README.md b/ThunderSoft_smstx/README.md new file mode 100644 index 000000000..73364c641 --- /dev/null +++ b/ThunderSoft_smstx/README.md @@ -0,0 +1,45 @@ +# ShortUrl +smsx是一个发送短信的依赖库,提供了单个号码发送短信验证码和多个号码发送不同的消息内容2种方法 + + +## 逻辑详情 + +### sendSms + +单个号码发送验证码 + +入参: +* List phone 手机号 +* List templateParam 随机6位验证码 +* String smsSdkAppId 应用ID +* String signName 验证码签名名称 +* String temlateId 验证码模板ID + + +出参: + +### batchSendSms + +批量发送短信消息 + +入参: +* String smsSdkAppId 应用ID +* String signName 验证码签名名称 +* String temlateId 验证码模板ID +* List phoneParam 手机号对应的文本内容 + + +出参: + + +## 使用步骤说明 + +1. 应用引用依赖库 +2. 配置应用配置参数 (无需配置) +3. 逻辑调用示例截图 + +参考文档 + +## 应用演示链接 + +[使用了本依赖库的制品应用链接] diff --git a/ThunderSoft_smstx/jar/nasl-metadata-collector-0.7.0.jar b/ThunderSoft_smstx/jar/nasl-metadata-collector-0.7.0.jar new file mode 100644 index 000000000..f085868b0 Binary files /dev/null and b/ThunderSoft_smstx/jar/nasl-metadata-collector-0.7.0.jar differ diff --git a/ThunderSoft_smstx/pom.xml b/ThunderSoft_smstx/pom.xml new file mode 100644 index 000000000..f8cadedb8 --- /dev/null +++ b/ThunderSoft_smstx/pom.xml @@ -0,0 +1,86 @@ + + + 4.0.0 + com.smstxy + smstx + 1.3.1 + 腾讯云sms短信 + + + org.springframework.boot + spring-boot-starter-parent + 2.2.9.RELEASE + + + + 8 + 8 + UTF-8 + 3.3 + + + + + com.tencentcloudapi + tencentcloud-sdk-java + 3.1.994 + + + nasl-metadata-collector + com.netease.lowcode + 0.7.0 + true + system + ${project.basedir}/jar/nasl-metadata-collector-0.7.0.jar + + + org.springframework.boot + spring-boot-starter-web + provided + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.3.0 + + + jar-with-dependencies + + false + + + + make-assembly + package + + single + + + + + + com.netease.lowcode + nasl-metadata-maven-plugin + 1.3.0 + + true + + + + + archive + + + + + + + diff --git a/ThunderSoft_smstx/smstx.iml b/ThunderSoft_smstx/smstx.iml new file mode 100644 index 000000000..f82ff661c --- /dev/null +++ b/ThunderSoft_smstx/smstx.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/ThunderSoft_smstx/src/main/java/com/smstxy/lib/smstool/LibraryAutoScan.java b/ThunderSoft_smstx/src/main/java/com/smstxy/lib/smstool/LibraryAutoScan.java new file mode 100644 index 000000000..3707ae9bc --- /dev/null +++ b/ThunderSoft_smstx/src/main/java/com/smstxy/lib/smstool/LibraryAutoScan.java @@ -0,0 +1,8 @@ +package com.smstxy.lib.smstool; + +/** + * 依赖库自动扫描类 + * @author system + */ +public class LibraryAutoScan { +} diff --git a/ThunderSoft_smstx/src/main/java/com/smstxy/lib/smstool/Temp.java b/ThunderSoft_smstx/src/main/java/com/smstxy/lib/smstool/Temp.java new file mode 100644 index 000000000..9ae6b52f4 --- /dev/null +++ b/ThunderSoft_smstx/src/main/java/com/smstxy/lib/smstool/Temp.java @@ -0,0 +1,10 @@ +package com.smstxy.lib.smstool; + +import com.netease.lowcode.core.annotation.NaslStructure; + +/** + * 由于打包必须有nasl标签,所以创建临时类。若项目中有nasl标签的类,则不需要此类。 + */ +@NaslStructure +public class Temp { +} diff --git a/ThunderSoft_smstx/src/main/java/com/smstxy/lib/smstool/config/SmsConfig.java b/ThunderSoft_smstx/src/main/java/com/smstxy/lib/smstool/config/SmsConfig.java new file mode 100644 index 000000000..dddf08817 --- /dev/null +++ b/ThunderSoft_smstx/src/main/java/com/smstxy/lib/smstool/config/SmsConfig.java @@ -0,0 +1,57 @@ +package com.smstxy.lib.smstool.config; + +import com.netease.lowcode.core.EnvironmentType; +import com.netease.lowcode.core.annotation.Environment; +import com.netease.lowcode.core.annotation.NaslConfiguration; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; + + +@Configuration +@Component +public class SmsConfig { + /** + * 地域 + */ + @Value("${region}") + @NaslConfiguration + public String region; + + /** + * 认证的用户名 + */ + @Value("${secretId}") + @NaslConfiguration + public String secretId; + /** + * 认证的密码 + */ + @Value("${secretKey}") + @NaslConfiguration + public String secretKey; + + public String getRegion() { + return region; + } + + public void setRegion(String region) { + this.region = region; + } + + public String getSecretId() { + return secretId; + } + + public void setSecretId(String secretId) { + this.secretId = secretId; + } + + public String getSecretKey() { + return secretKey; + } + + public void setSecretKey(String secretKey) { + this.secretKey = secretKey; + } +} diff --git a/ThunderSoft_smstx/src/main/java/com/smstxy/lib/smstool/service/SmsTXService.java b/ThunderSoft_smstx/src/main/java/com/smstxy/lib/smstool/service/SmsTXService.java new file mode 100644 index 000000000..e756361ec --- /dev/null +++ b/ThunderSoft_smstx/src/main/java/com/smstxy/lib/smstool/service/SmsTXService.java @@ -0,0 +1,137 @@ +package com.smstxy.lib.smstool.service; + +import com.smstxy.lib.smstool.config.SmsConfig; +import com.smstxy.lib.smstool.structure.PhoneParam; +import com.netease.lowcode.core.annotation.NaslLogic; +import com.tencentcloudapi.common.Credential; +import com.tencentcloudapi.common.exception.TencentCloudSDKException; +import com.tencentcloudapi.common.profile.ClientProfile; +import com.tencentcloudapi.common.profile.HttpProfile; +import com.tencentcloudapi.sms.v20210111.SmsClient; +import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest; +import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse; +import com.tencentcloudapi.sms.v20210111.models.SendStatus; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.*; + +@Component +public class SmsTXService { + private static final Logger log = LoggerFactory.getLogger(SmsTXService.class); + + @Autowired + private SmsConfig smsConfig; + + + @NaslLogic(enhance = false) + public Map> sendSms(List phone, List templateParam, String smsSdkAppId, + String signName, String templateId) { +// log.info ("手机号列表:"+phone.toString ()); + ArrayList phoneSuccess = new ArrayList<>(); + ArrayList phoneError = new ArrayList<>(); + Map> map = new HashMap<>(); + try { + // 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密 + // 代码泄露可能会导致 SecretId 和 SecretKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议采用更安全的方式来使用密钥,请参见:https://cloud.tencent.com/document/product/1278/85305 + // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取 + Credential cred = new Credential(smsConfig.getSecretId(), smsConfig.getSecretKey()); + log.error("腾讯sdk异常--smsConfig.getSecretId():-----"+smsConfig.getSecretId()); + log.error("腾讯sdk异常--smsConfig.getSecretKey():---------"+smsConfig.getSecretKey()); + + // 实例化一个http选项,可选的,没有特殊需求可以跳过 + HttpProfile httpProfile = new HttpProfile(); + httpProfile.setEndpoint("sms.tencentcloudapi.com"); + // 实例化一个client选项,可选的,没有特殊需求可以跳过 + ClientProfile clientProfile = new ClientProfile(); + clientProfile.setHttpProfile(httpProfile); + // 实例化要请求产品的client对象,clientProfile是可选的 + SmsClient client = new SmsClient(cred, smsConfig.getRegion(), clientProfile); + // 实例化一个请求对象,每个接口都会对应一个request对象 + SendSmsRequest req = new SendSmsRequest(); + String[] phoneNumberSet = phone.toArray(new String[phone.size()]); + req.setPhoneNumberSet(phoneNumberSet); + req.setSmsSdkAppId(smsSdkAppId); + req.setSignName(signName); + req.setTemplateId(templateId); + String[] templateParamSet = templateParam.toArray(new String[templateParam.size()]); + req.setTemplateParamSet(templateParamSet); + // 返回的resp是一个SendSmsResponse的实例,与请求对象对应 + SendSmsResponse resp = client.SendSms(req); + SendStatus[] sendStatusSet = resp.getSendStatusSet(); + List sendStatuses = Arrays.asList(sendStatusSet); + sendStatuses.forEach(sendStatus -> { + if ("Ok".equals(sendStatus.getCode())) { + phoneSuccess.add(sendStatus.getPhoneNumber()); + log.info("发送成功手机号:" + sendStatus.getPhoneNumber()); + } else { + phoneError.add(sendStatus.getPhoneNumber()); + log.info("发送失败手机号:" + sendStatus.getPhoneNumber()); + } + }); + map.put("success", phoneSuccess); + map.put("error", phoneError); + } catch (TencentCloudSDKException e) { + log.error("腾讯sdk异常--TencentCloudSDKException"+e.toString()); + } catch (Exception e) { + log.error("未知异常--Exception"+e.toString()); + } + return map; + } + + @NaslLogic(enhance = false) + public Map> batchSendSms(List phoneParam, String smsSdkAppId, + String signName, String templateId) { +// log.info ("手机号列表:"+phone.toString ()); + ArrayList phoneSuccess = new ArrayList<>(); + ArrayList phoneError = new ArrayList<>(); + Map> map = new HashMap<>(); + // 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密 + // 代码泄露可能会导致 SecretId 和 SecretKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议采用更安全的方式来使用密钥,请参见:https://cloud.tencent.com/document/product/1278/85305 + // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取 + Credential cred = new Credential(smsConfig.getSecretId(), smsConfig.getSecretKey()); + + // 实例化一个http选项,可选的,没有特殊需求可以跳过 + HttpProfile httpProfile = new HttpProfile(); + httpProfile.setEndpoint("sms.tencentcloudapi.com"); + // 实例化一个client选项,可选的,没有特殊需求可以跳过 + ClientProfile clientProfile = new ClientProfile(); + clientProfile.setHttpProfile(httpProfile); + // 实例化要请求产品的client对象,clientProfile是可选的 + SmsClient client = new SmsClient(cred, smsConfig.getRegion(), clientProfile); + // 实例化一个请求对象,每个接口都会对应一个request对象 +// 工具手机号实例化多个请求对象 + phoneParam.forEach(phoneSin -> { + SendSmsRequest req = new SendSmsRequest(); + String[] phoneNumberSet = {phoneSin.getPhone()}; + req.setPhoneNumberSet(phoneNumberSet); + req.setSmsSdkAppId(smsSdkAppId); + req.setSignName(signName); + req.setTemplateId(templateId); + req.setTemplateParamSet(phoneSin.getParam().toArray(new String[phoneSin.getParam().size()])); + // 返回的resp是一个SendSmsResponse的实例,与请求对象对应 + SendSmsResponse resp = null; + try { + resp = client.SendSms(req); + } catch (TencentCloudSDKException e) { + e.printStackTrace(); + } + SendStatus[] sendStatusSet = resp.getSendStatusSet(); + List sendStatuses = Arrays.asList(sendStatusSet); + sendStatuses.forEach(sendStatus -> { + if ("Ok".equals(sendStatus.getCode())) { + phoneSuccess.add(sendStatus.getPhoneNumber()); + log.info("发送成功手机号:" + sendStatus.getPhoneNumber()); + } else { + phoneError.add(sendStatus.getPhoneNumber()); + log.info("发送失败手机号:" + sendStatus.getPhoneNumber()); + } + }); + map.put("success", phoneSuccess); + map.put("error", phoneError); + }); + return map; + } +} diff --git a/ThunderSoft_smstx/src/main/java/com/smstxy/lib/smstool/spring/LibSmstxySpringEnvironmentConfiguration.java b/ThunderSoft_smstx/src/main/java/com/smstxy/lib/smstool/spring/LibSmstxySpringEnvironmentConfiguration.java new file mode 100644 index 000000000..6be06dda2 --- /dev/null +++ b/ThunderSoft_smstx/src/main/java/com/smstxy/lib/smstool/spring/LibSmstxySpringEnvironmentConfiguration.java @@ -0,0 +1,17 @@ +package com.smstxy.lib.smstool.spring; + +import com.smstxy.lib.smstool.LibraryAutoScan; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +/** + * 加入spring环境配置(在spring.factories中指定) + */ +@Configuration +@ComponentScan(basePackageClasses=LibraryAutoScan.class) +public class LibSmstxySpringEnvironmentConfiguration { + public LibSmstxySpringEnvironmentConfiguration() { + System.out.println ("LibDemoRedisSpringEnvironmentConfiguration"); + } +} + diff --git a/ThunderSoft_smstx/src/main/java/com/smstxy/lib/smstool/structure/PhoneParam.java b/ThunderSoft_smstx/src/main/java/com/smstxy/lib/smstool/structure/PhoneParam.java new file mode 100644 index 000000000..e2169dbe0 --- /dev/null +++ b/ThunderSoft_smstx/src/main/java/com/smstxy/lib/smstool/structure/PhoneParam.java @@ -0,0 +1,37 @@ +package com.smstxy.lib.smstool.structure; + +import com.netease.lowcode.core.annotation.NaslStructure; + +import java.util.List; + +/** + * 相加入参,声明为code-wave认识的结构体 + */ +@NaslStructure +public class PhoneParam { + /** + * 返回参数 + */ + public String phone; + /** + * 结果名称 + */ + public List param; + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + + public List getParam() { + return param; + } + + public void setParam(List param) { + this.param = param; + } +} diff --git a/ThunderSoft_smstx/src/main/resources/META-INF/spring.factories b/ThunderSoft_smstx/src/main/resources/META-INF/spring.factories new file mode 100644 index 000000000..d826fe0c1 --- /dev/null +++ b/ThunderSoft_smstx/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.smstxy.lib.smstool.spring.LibSmstxySpringEnvironmentConfiguration diff --git "a/ThunderSoft_smstx/\350\205\276\350\256\257\344\272\221\347\237\255\344\277\241\344\275\277\347\224\250\344\276\235\350\265\226\345\214\205.docx" "b/ThunderSoft_smstx/\350\205\276\350\256\257\344\272\221\347\237\255\344\277\241\344\275\277\347\224\250\344\276\235\350\265\226\345\214\205.docx" new file mode 100644 index 000000000..0f76dccb9 Binary files /dev/null and "b/ThunderSoft_smstx/\350\205\276\350\256\257\344\272\221\347\237\255\344\277\241\344\275\277\347\224\250\344\276\235\350\265\226\345\214\205.docx" differ