Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions ThunderSoft_smstx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# ShortUrl
smsx是一个发送短信的依赖库,提供了单个号码发送短信验证码和多个号码发送不同的消息内容2种方法


## 逻辑详情

### sendSms

单个号码发送验证码

入参:
* List<String> phone 手机号
* List<String> templateParam 随机6位验证码
* String smsSdkAppId 应用ID
* String signName 验证码签名名称
* String temlateId 验证码模板ID


出参:

### batchSendSms

批量发送短信消息

入参:
* String smsSdkAppId 应用ID
* String signName 验证码签名名称
* String temlateId 验证码模板ID
* List<String> phoneParam 手机号对应的文本内容


出参:


## 使用步骤说明

1. 应用引用依赖库
2. 配置应用配置参数 (无需配置)
3. 逻辑调用示例截图

参考文档

## 应用演示链接

[使用了本依赖库的制品应用链接]
Binary file not shown.
86 changes: 86 additions & 0 deletions ThunderSoft_smstx/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.smstxy</groupId>
<artifactId>smstx</artifactId>
<version>1.3.1</version>
<name>腾讯云sms短信</name>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.9.RELEASE</version><!--与当前制品应用默认版本统一-->
</parent>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<nasl.ide.version>3.3</nasl.ide.version>
</properties>
<dependencies>
<!--本案例是本地系统引入nasl-metadata-collector-0.7.0.jar的方式。
若把nasl-metadata-collector-0.7.0.jar安装到自己的maven仓库,
注意修改artifactId和groupId的情况下,不要使用<scope>system</scope>,会在发布时造成依赖中断。
不修改artifactId和groupId的情况下,nasl-metadata-maven-plugin会做特殊处理-->
<dependency>
<groupId>com.tencentcloudapi</groupId>
<artifactId>tencentcloud-sdk-java</artifactId>
<version>3.1.994</version>
</dependency>
<dependency>
<artifactId>nasl-metadata-collector</artifactId>
<groupId>com.netease.lowcode</groupId>
<version>0.7.0</version>
<optional>true</optional>
<scope>system</scope>
<systemPath>${project.basedir}/jar/nasl-metadata-collector-0.7.0.jar</systemPath>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.netease.lowcode</groupId>
<artifactId>nasl-metadata-maven-plugin</artifactId>
<version>1.3.0</version>
<configuration>
<jarWithDependencies>true</jarWithDependencies>
</configuration>
<executions>
<execution>
<goals>
<goal>archive</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
13 changes: 13 additions & 0 deletions ThunderSoft_smstx/smstx.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="FacetManager">
<facet type="web" name="Web">
<configuration>
<webroots />
</configuration>
</facet>
<facet type="Spring" name="Spring">
<configuration />
</facet>
</component>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.smstxy.lib.smstool;

/**
* 依赖库自动扫描类
* @author system
*/
public class LibraryAutoScan {
}
10 changes: 10 additions & 0 deletions ThunderSoft_smstx/src/main/java/com/smstxy/lib/smstool/Temp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.smstxy.lib.smstool;

import com.netease.lowcode.core.annotation.NaslStructure;

/**
* 由于打包必须有nasl标签,所以创建临时类。若项目中有nasl标签的类,则不需要此类。
*/
@NaslStructure
public class Temp {
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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<String, List<String>> sendSms(List<String> phone, List<String> templateParam, String smsSdkAppId,
String signName, String templateId) {
// log.info ("手机号列表:"+phone.toString ());
ArrayList<String> phoneSuccess = new ArrayList<>();
ArrayList<String> phoneError = new ArrayList<>();
Map<String, List<String>> 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<SendStatus> 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<String, List<String>> batchSendSms(List<PhoneParam> phoneParam, String smsSdkAppId,
String signName, String templateId) {
// log.info ("手机号列表:"+phone.toString ());
ArrayList<String> phoneSuccess = new ArrayList<>();
ArrayList<String> phoneError = new ArrayList<>();
Map<String, List<String>> 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<SendStatus> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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");
}
}

Loading