腾讯云发送短信验证码

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;
	}
相关推荐
云边云科技_云网融合4 小时前
基于深度学习的设备监控技术:从被动报警到主动预警的革新
网络·人工智能·云计算
七夜zippoe5 小时前
腾讯云轻量服务器部署OpenClaw实战:打造智能日程管理助手
服务器·云计算·腾讯云·openclaw·腾讯云openclaw玩虾大赛
翼龙云_cloud8 小时前
阿里云代理商:如何基于百炼模型数据构建企业级智能分析平台?
阿里云·大模型·云计算
麦田里的稻草人w8 小时前
【OpenClaw第一讲】介绍和安装
人工智能·ai·云计算
天草二十六_简村人9 小时前
阿里云的NAT和弹性公网IP,解决ECS机器访问外网的实现方案
运维·后端·网络协议·阿里云·云计算·ip
天天讯通10 小时前
火山引擎ASR & 阿里云ASR 怎么选
阿里云·云计算·火山引擎
前进的李工10 小时前
SSH隧道实现Dify与Ollama跨服务器通信
开发语言·大模型·github·腾讯云·autodl·dify
同聘云10 小时前
阿里云国际站独立服务器有哪些优点?独立服务器和云服务器的区别
服务器·阿里云·云计算
Luke~10 小时前
已上架阿里云计算巢!Loki AI 事故分析引擎正式开放一键部署,帮 SRE 快速完成故障复盘
人工智能·阿里云·云计算·loki·devops·aiops·sre
G佳伟11 小时前
阿里云,腾讯云 Docker Hub国内云服务器无法访问解决方案
阿里云·docker·腾讯云