参考项目: RuoYi-Vue-Plus

添加依赖

     <dependency><groupId>com.tencentcloudapi</groupId><artifactId>tencentcloud-sdk-java</artifactId><version>3.1.500</version></dependency>

配置相关

配置项

#--- # sms 短信
sms:enabled: trueendpoint: "sms.tencentcloudapi.com"accessKeyId: XXXXXXaccessKeySecret: XXXXXXsignName: sdkAppId:

相关代码

配置文件 SmsProperties 映射类

/*** SMS短信 配置属性** @author Lion Li* @version 4.2.0*/
@Data
@Component
@ConfigurationProperties(prefix = "sms")
public class SmsProperties {private Boolean enabled;/*** 配置节点* 腾讯云 sms.tencentcloudapi.com*/private String endpoint;/*** key*/private String accessKeyId;/*** 密匙*/private String accessKeySecret;/** 短信签名*/private String signName;/*** 短信应用ID (腾讯专属)*/private String sdkAppId;}

配置类 SmsConfig

@Configuration
@ConditionalOnProperty(value = "sms.enabled", havingValue = "true")
public class SmsConfig {@Beanpublic SmsTemplate tencentSmsTemplate(SmsProperties smsProperties) {return new TencentSmsTemplate(smsProperties);}}

模板接口类 SmsTemplate

/*** 短信模板** @author Lion Li* @version 4.2.0*/
public interface SmsTemplate {/*** 发送短信** @param phones     电话号(多个逗号分割)* @param templateId 模板id* @param param      模板对应参数*                   腾讯 需使用 模板变量顺序对应内容 例如: 1=1234, 1为模板内第一个参数*/SmsResult send(String phones, String templateId, Map<String, String> param);}

模块实现类 TencentSmsTemplate

/*** Tencent 短信模板** @author Lion Li* @version 4.2.0*/
public class TencentSmsTemplate implements SmsTemplate {private SmsProperties properties;private SmsClient client;@SneakyThrows(Exception.class)public TencentSmsTemplate(SmsProperties smsProperties) {this.properties = smsProperties;Credential credential = new Credential(smsProperties.getAccessKeyId(), smsProperties.getAccessKeySecret());HttpProfile httpProfile = new HttpProfile();httpProfile.setEndpoint(smsProperties.getEndpoint());ClientProfile clientProfile = new ClientProfile();clientProfile.setHttpProfile(httpProfile);this.client = new SmsClient(credential, "", clientProfile);}public SmsResult send(String phones, String templateId, Map<String, String> param) {if (StringUtils.isBlank(phones)) {throw new SmsException("手机号不能为空");}if (StringUtils.isBlank(templateId)) {throw new SmsException("模板ID不能为空");}SendSmsRequest req = new SendSmsRequest();Set<String> set = Arrays.stream(phones.split(",")).map(p -> "+86" + p).collect(Collectors.toSet());req.setPhoneNumberSet(ArrayUtil.toArray(set, String.class));if (CollUtil.isNotEmpty(param)) {req.setTemplateParamSet(ArrayUtil.toArray(param.values(), String.class));}req.setTemplateID(templateId);req.setSign(properties.getSignName());req.setSmsSdkAppid(properties.getSdkAppId());try {SendSmsResponse resp = client.SendSms(req);SmsResult.SmsResultBuilder builder = SmsResult.builder().isSuccess(true).message("send success").response(resp);for (SendStatus sendStatus : resp.getSendStatusSet()) {if (!"Ok".equals(sendStatus.getCode())) {builder.isSuccess(false).message(sendStatus.getMessage());break;}}return builder.build();} catch (Exception e) {throw new SmsException(e.getMessage());}}}

结果类 SmsResult

/*** 上传返回体** @author Lion Li*/
@Data
@Builder
public class SmsResult {/*** 是否成功*/private boolean isSuccess;/*** 响应消息*/private String message;/*** 实际响应体*/private Object response;
}

Spring Boot 整合 腾讯云短信(模板模式)相关推荐

  1. Spring Boot 整合 阿里云短信(模板模式)

    参考项目: RuoYi-Vue-Plus 添加依赖 <dependency><groupId>com.aliyun</groupId><artifactId& ...

  2. Java整合腾讯云短信发送

    1. 引入相关maven依赖 <dependency><groupId>com.github.qcloudsms</groupId><artifactId&g ...

  3. 使用腾讯云短信服务实现Spring Boot短信发送

    发送短信 01 注册微信公众号 02 注册腾讯云账号 03 创建签名和模板 第一步 创建签名 第二部 创建模板 04 发送短信 01 注册微信公众号 在百度搜索微信公众平台,并在进入官网后注册.在账号 ...

  4. SpringBoot集成腾讯云短信实现注册/登录功能

    前言 笔记参考 Duktig丶 JavaSDK地址:短信 Java SDK - SDK 文档 - 文档中心 - 腾讯云 1.导入依赖 <dependency><groupId> ...

  5. 使用Python开通腾讯云短信(sms)【亲测有效·超详细】

    使用Python开通腾讯云短信(sms) 1.开通腾讯云短信服务 2.创建应用 3.创建签名 4.Python 操作腾讯云短信接口 模块安装 详细代码[可直接作为接口] 1.开通腾讯云短信服务 腾讯云 ...

  6. 如何通过腾讯云短信实现发送验证码并校验验证码以实现登录功能

    如何通过腾讯云短信实现发送验证码并校验验证码以实现登录功能 验证码相关的10种技术 图像处理技术:生成.识别.验证验证码的图像. 机器学习技术:让计算机自动学习并识别验证码. 文字识别技术:将图像中的 ...

  7. 快速集成腾讯云短信实现短信发送(Spring Boot)

    前言 腾讯云活动白嫖 1.地址 地址:https://cloud.tencent.com/act/free?from=14600 2.创建签名(根据实际情况选择) 我的是网站 3.创建模板 选择模板内 ...

  8. Spring Boot腾讯云短信申请

    1.在pom.xml文件中添加依赖 <dependency><groupId>com.tencentcloudapi</groupId><artifactId ...

  9. Spring Boot中使用腾讯云短信服务

    第一步:在腾讯云官方网站开通短信服务 第二部:开通后,在短信控制面板中找到国内短信 第三步:点击签名管理并创建签名 第五步:点击正文模板管理并创建正文模板 第六步:在pom文件中添加腾讯云短信依赖 & ...

最新文章

  1. 在一个有返回值的方法中,用block回传的解决方法
  2. intellij idea操作maven时控制台中文乱码
  3. CRM_OPPORT_H_READ_OW used not so often
  4. spark写出分布式的训练算法_利用 Spark 和 scikit-learn 将你的模型训练加快 100 倍...
  5. 无敌简单快速的文件服务器sgfs
  6. java中间件是什么意思_数据库中间件漫谈
  7. PHP目前比较常见的五大运行模式
  8. MaxCompute平台非标准日期和气象数据处理方法--以电力AI赛为例
  9. Kerberos安装及拖管Ambari 2.7
  10. 18 个 JavaScript 入门技巧
  11. HDL语言三种描述方式--结构化描述方式、数据流描述方式、行为级描述方式
  12. 算式最大值 (思维题)
  13. NLog NETCore 3.0 Porting
  14. 家用空气净化器除甲醛什么品牌好 能除甲醛吗
  15. 如何取SQL结果集的第一条记录
  16. Win10邮件应用怎么添加网易邮箱
  17. php怎么查看qq邮箱,thinkphp实现163、QQ邮箱收发邮件的方法
  18. 安卓海豚wii模拟器_dolphin模拟器安卓版
  19. 英汉小字典java_java 学习案例之英汉字典
  20. SNAT和DNAT原理及配置方法

热门文章

  1. “合”而不同,持“智”以恒,幂律智能2022产品升级发布会全程回顾!
  2. artDialog和iframe嵌入页面
  3. TI AM64x工业核心板规格书(双核ARM Cortex-A53 + 单/四核Cortex-R5F + 单核Cortex-M4F,主频1GHz)
  4. 计算机一级电子表格和PP多少,2017年计算机一级《MSOffice》基本操作考前必做试题及答案5...
  5. Ultraedit Mac(文本编辑器)V15.1.0.1 最新中文破解版
  6. mysql navicat 组合索引_mysql组合索引与字段顺序
  7. android 描边 投影 textview,TextView 文字描边
  8. C4D模型工具—循环/路径切割
  9. i9 10885h和i7 10875h 哪个好
  10. 安卓miracast花屏_Miracast无线投屏技术优缺点有哪些?