SpringBoot-短信发送
1、环境准备
1 打开腾讯云短信服务,领取免费短信
国内短信活动_短信优惠活动_短信新购活动 - 腾讯云
2 打开腾讯公众号申请平台,申请公众号,申请类型选择个人类型。
记录下公平号名称,
微信公众平台
3 登录腾讯云短信发送平台,按照步骤申请国内短信发送
登录 - 腾讯云
4 申请短信签名和短信模板,等待审核通过,获取审核通过的短信模板ID和短信签名
5 获取腾讯密钥: secretId和secretKey
登录 - 腾讯云
6 获取个人短信SDK
登录 - 腾讯云
7 下载短信发送依赖
<!--腾讯云短信-->
<dependency><groupId>com.tencentcloudapi</groupId><artifactId>tencentcloud-sdk-java</artifactId><version>3.1.424</version>
</dependency>
2 短信发送
1 创建短信发送配置类,代码如下:
package com.hqyj.config;import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.sms.v20210111.SmsClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class TencentSmsConfig {@Beanpublic SmsClient getSmsCilent(){//创建腾讯云短信发送凭证对象,填入secretId和secretKeyCredential cred = new Credential("填入secretId", "填入secretKey");HttpProfile httpProfile = new HttpProfile();httpProfile.setEndpoint("sms.tencentcloudapi.com");ClientProfile clientProfile = new ClientProfile();clientProfile.setHttpProfile(httpProfile);//创建短信发送服务平台对象SmsClient client = new SmsClient(cred, "ap-guangzhou", clientProfile);return client;}
}
2 创建短信发送工具类
package com.hqyj.utile;import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.sms.v20210111.SmsClient;
import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;import java.util.HashMap;
import java.util.List;
import java.util.Map;@Component
public class SmsSend {@AutowiredSmsClient smsClient;public HashMap<String,Object> send(String tel) throws TencentCloudSDKException {HashMap<String,Object> map = new HashMap<String,Object>();//创建短信发送请求对象SendSmsRequest req = new SendSmsRequest();//接收短信手机号String[] phone = {tel};req.setPhoneNumberSet(phone);//个人短信模板模板Idreq.setTemplateId("短信模板模板Id");//个人短信发送SDKreq.setSmsSdkAppId("短信发送SDK");//个人短信签名req.setSignName("短信签名");//短信验证码String[] p = {"2345"};req.setTemplateParamSet(p);//发送对象,并获取获取响应对象SendSmsResponse resp = smsClient.SendSms(req);//将响应结果转换成字符串格式String info = SendSmsResponse.toJsonString(resp);// 打印结果信息System.out.println(info);try {//将字符串格式转换成Map 接口对象,获取短信发送成功的提示ObjectMapper mapper = new ObjectMapper();Map<String,Object> m = mapper.readValue(info, Map.class);List<Map<String,Object>> list =( List<Map<String,Object>>) m.get("SendStatusSet");System.out.println(list.get(0).get("Code"));if(list.get(0).get("Code").equals("Ok")){System.out.println("发送成功");}} catch (JsonProcessingException e) {e.printStackTrace();}return map;}
}
3 创建测试类,测试
package com.hqyj.utile;import com.hqyj.MyApp;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;import static org.junit.Assert.*;@RunWith(SpringRunner.class)
@SpringBootTest(classes = MyApp.class)
public class SmsSendTest {@AutowiredSmsSend smsSend;@Testpublic void send() {try {smsSend.send("电话");} catch (TencentCloudSDKException e) {e.printStackTrace();}}
}
SpringBoot-短信发送相关推荐
- SpringBoot——短信发送、手机验证码登录
目录 一.短信发送 1.1 阿里云短信服务 1.1.1 设置短信签名 1.1.2 模板管理 1.1.3 设置AccessKey 1.2 短信发送--代码开发 1.2.1 导入maven坐标 1.2.2 ...
- 【短信发送】实现腾讯云发送短信功能--工具类和SpringBoot配置两种方法实现
实现腾讯云发送短信功能--工具类和SpringBoot配置两种方法实现 一.开通腾讯云短信服务 二.工具类--使用qcloudsms实现短信发送 三.Spring Boot项目引入短信发送功能 我们发 ...
- 快速实现短信发送功能(SpringBoot)
Springboot集成短信发送 准备工作:确定要使用的第三方容联云通讯接口因为是免费测试送8元礼包才选择的,首先注册一个账户,主界面的账户信息是我们所需的,复制代码后,包名.位置自己解决; 一.导入 ...
- SpringBoot+腾讯云实现短信发送
SpringBoot+腾讯云实现短信发送 在腾讯云创建短信签名 短信签名审核通过后创建短信模板 短信发送SDK(java)文档,将com.tencentcloudapi包导入 <dependen ...
- springboot +秒嘀 实现短信发送
短信发送 步骤一:注册秒嘀(或者用其他短信平台) 第二步:添加短信模板,验证通过即可 第三步:在springboot项目中添加依赖 <dependency><groupId>n ...
- SpringBoot代码实现移动云 模板短信发送
springboot实现移动云 模板短信发送 引入这几个依赖 <dependency><groupId>commons-codec</groupId><art ...
- springboot实现阿里短信发送并查询状态
改pom <!-- 阿里云短信服务依赖 --><dependency><groupId>com.aliyun</groupId><artifact ...
- 快速集成腾讯云短信实现短信发送(Spring Boot)
前言 腾讯云活动白嫖 1.地址 地址:https://cloud.tencent.com/act/free?from=14600 2.创建签名(根据实际情况选择) 我的是网站 3.创建模板 选择模板内 ...
- jeecg 手机注册 阿里云短信API 【 阿里云短信发送验证码 平台配置和项目中使用】
文章目录 jeecg 项目效果展示 短息通知页面入口 代码中调用短信api 配置和代码 API中的重要参数配置项: 阿里控制台注册 注册签名 注册短信模板 阿里云短信发送验证码配置和项目使用 je ...
- java实现阿里大于短信发送服务
这篇文章主要介绍一下手机号注册,发送短信验证码的功能 觉得有帮助的点赞支持一下吧. 这里我们采用的是阿里大于的服务来实现,链接如下:阿里云 界面描述还是比较详细的,展示了短信服务的完整流程快速学习短信 ...
最新文章
- 一文读懂傅立叶变换处理图像的原理
- nginx日志通过rsyslog传入到日志服务器指定目录
- 201571030310/201571030329《小学四则运算训练软件》结对项目报告
- python string.format()_Python string.format()百分比,不取整
- 麒麟810处理器_华为nova5跑分公布,麒麟810到底是什么水平?
- OTSU大津法对图像二值化
- 面试题:synchronized的底层实现(偏向锁,轻量级锁,重量级锁)
- About scrum reports
- 雷达相关书籍学习顺序推荐
- pinyin4j获取汉字正确的全拼和简拼
- Clone 2. 肿瘤克隆进化之不同进化模式
- presto字符串转日期
- 家用空气净化器除甲醛什么品牌好 能除甲醛吗
- android网络转圈,网络请求时显示正在请求转圈
- 4G摄像头采用GB28181协议成功接入LiveGBS国标流媒体平台的设置流程
- 云平台短信验证码通知短信java/php/.net开发实现
- opencv - viz 画出SLAM轨迹
- 重头系统的学习,不会咱就学!2014.6.18
- Android dex修复工具,安卓热修复----手动加载dex文件到设备并执行
- 绩效面谈的4种技巧(一)