腾讯云发送短信验证码

1、在腾讯云平台中 开通短信服务

2、发送短信

2.1引用jar包

xml 复制代码
<dependency>
    <groupId>com.tencentcloudapi</groupId>
    <artifactId>tencentcloud-sdk-java-sms</artifactId>
    <version>3.1.1043</version>
</dependency>

2.2

发送短信内容:

java 复制代码
public SendResult send(SMData data) throws Exception {
		SendResult sendResult = new SendResult();
		try{
            // 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
            // 代码泄露可能会导致 SecretId 和 SecretKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议采用更安全的方式来使用密钥,请参见:https://cloud.tencent.com/document/product/1278/85305
            // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
            // 实例化一个http选项,可选的,没有特殊需求可以跳过
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("sms.tencentcloudapi.com");
            // 实例化一个client选项,可选的,没有特殊需求可以跳过
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            // 实例化要请求产品的client对象,clientProfile是可选的
            SmsClient client = new SmsClient(new Credential(getParamValue("SecretId"), getParamValue("SecretKey")), "ap-guangzhou", clientProfile);
            // 实例化一个请求对象,每个接口都会对应一个request对象
            SendSmsRequest req = new SendSmsRequest();
            String[] phoneNumberSet1 = {data.getReveivePhoneList()};
            req.setPhoneNumberSet(phoneNumberSet1);

            req.setSmsSdkAppId(getParamValue("SDKAppID"));
            req.setTemplateId(getParamValue("msg_template"));
            req.setSignName(getParamValue("signName"));
            //短信内容 参数个数和模板中数量匹配
            String[] param = {data.getContent()};
            req.setTemplateParamSet(param);
            
            // 返回的resp是一个SendSmsResponse的实例,与请求对象对应
            SendSmsResponse resp = client.SendSms(req);
            SendStatus status = resp.getSendStatusSet()[0];
            sendResult.setMessage(status.getMessage());
            sendResult.setSuccess(status.getCode().equalsIgnoreCase("ok"));
            
            String res = AbstractModel.toJsonString(resp);
            // 输出json格式的字符串回包
            LogHelper.Log("log_send_msg response:", res);
             
        } catch (TencentCloudSDKException e) {
            e.printStackTrace();
            LogHelper.Log("log_send_msg error:", e.getMessage());
        }
		return sendResult;
	}
相关推荐
SH11HF2 小时前
小菜狗的云计算之旅,学习了解rsync+sersync实现数据实时同步(详细操作步骤)
学习·云计算
搞笑的秀儿5 小时前
信息新技术
大数据·人工智能·物联网·云计算·区块链
泊浮目13 小时前
未来数据库硬件-网络篇
数据库·架构·云计算
m0_653031361 天前
腾讯云认证考试报名 - TDSQL数据库交付运维专家(TCCE PostgreSQL版)
运维·数据库·腾讯云
m0_653031361 天前
腾讯云认证考试报名 - TDSQL数据库交付运维专家(TCCE MySQL版)
运维·数据库·腾讯云
UI设计和前端开发从业者1 天前
UI前端大数据处理策略优化:基于云计算的数据存储与计算
前端·ui·云计算
我是小bā吖1 天前
阿里云服务网格ASM实践
网络·阿里云·云计算·服务发现
长征coder1 天前
AWS MySQL 读写分离配置指南
mysql·云计算·aws
摘星编程2 天前
CloudBase AI ToolKit实战:从0到1开发一个智能医疗网站
人工智能·腾讯云·ai代码远征季#h5应用·ai医疗应用·cloudbase开发
Johny_Zhao2 天前
Docker 一键安装部署 JumpServer 堡垒机
linux·网络安全·信息安全·云计算·shell·jumpserver·ldap·yum源·系统运维