腾讯云发送短信验证码

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;
	}
相关推荐
GDAL2 小时前
全面讲解GNU:从起源到应用
服务器·云计算·gnu
九河云8 小时前
确保在AWS上的资源安全:构建坚不可摧的云安全防线
安全·云计算·aws
KubeSphere 云原生8 小时前
云原生周刊:Prometheus 3.0 Beta 发布|2024.09.16
云计算·k8s·容器平台·kubesphere
Jasonakeke16 小时前
本地镜像发布到阿里云
阿里云·云计算
奔跑的蜗牛fzq1 天前
阿里云专业翻译api对接
阿里云·云计算
仙剑魔尊重楼1 天前
FL Studio 24.1.1.4285中文破解完整版免费下载FL 2024注册密钥完整版crack百度云安装包下载
云计算·百度云·fl studio·fl studio 21·fl studio 24
风清已存在1 天前
阿里云OSS与IOT使用详解
物联网·阿里云·云计算
阿里云视频云1 天前
信通院发布首个《大模型媒体生产与处理》标准,阿里云智能媒体服务作为业界首家“卓越级”通过
阿里云·云计算·媒体
阿里云视频云2 天前
直播标准权威发布,阿里云RTS获首批卓越级评估认证
阿里云·云计算
MGT_97962 天前
ESP01的AT指令连接到阿里云平台
嵌入式硬件·物联网·阿里云·云计算