当前位置:网站首页>Ali cloud message service, SMS
Ali cloud message service, SMS
2022-08-07 06:20:00 【less cute】
Official Documentation:
Product Introduction(aliyun.com)
https://help.aliyun.com/document_detail/55287.htmlSpecific code operations:
1. Import the Jar package
com.aliyun dysmsapi20170525 2.0.9 2. Package tool class
package com.example.redisDemo.business.utils;import com.aliyun.dysmsapi20170525.Client;import com.aliyun.dysmsapi20170525.models.SendSmsRequest;import com.aliyun.dysmsapi20170525.models.SendSmsResponse;import com.aliyun.teaopenapi.models.Config;/*** Based on Alibaba Cloud's SMS service, realize the package of SMS sending*/public class AliSmsUtil {//Alibaba cloud's key and secret key involve costsprivate static final String KEY="";//AccessKey IDprivate static final String KEYSECRET="";//AccessKeySecret//Signature of SMS servicepublic static final String SIGN="";//Template for SMS service//Used to distinguish between notification SMS ${name} and verification code SMS ${code}public static final String TEMCODE_VALID="";//SMS verification code (code)public static final String TEMCODE_NOTIFY="";//SMS notification (name)/**The above needs to be applied in Alibaba Cloud SMS service**///Sms client objectprivate static Client client;/*** Use AK&SK to initialize the account Client*/static {Config config = new Config()// your AccessKey ID.setAccessKeyId(KEY)// your AccessKey Secret.setAccessKeySecret(KEYSECRET);// Visited domain nameconfig.endpoint = "dysmsapi.aliyuncs.com";try {client= new Client(config);} catch (Exception e) {e.printStackTrace();}}/*** Send the verification code* @param phone phone number* @param code verification code */public static boolean sendVCode(String phone,int code){return sendSms(TEMCODE_VALID,phone,code);}private static boolean sendSms(String tmcode,String phone,Object value){try {//1. Create the request objectSendSmsRequest request=new SendSmsRequest().setPhoneNumbers(phone).setSignName(SIGN) //Signature of SMS service.setTemplateCode(tmcode);//Used to distinguish between notification SMS ${name} and verification code SMS ${code}String param="";//Verify the SMS template, the template is different, the variables are different (name/code)if(tmcode.equals(TEMCODE_NOTIFY)){param="{\"name\":"+value+"}";}else{param="{\"code\":"+value+"}";}request.setTemplateParam(param);//3. Send the requestSendSmsResponse response=client.sendSms(request);//4. Verify the sending resultif("OK".equals(response.body.getCode())){return true;}} catch (Exception e) {e.printStackTrace();}return false;}}边栏推荐
猜你喜欢
随机推荐
pytest框架之fixture测试夹具详解
从浏览器到堆栈
jwt 认证机制
Linux下MySQL的安装与使用
数组去重的几种办法
Qt 使用SQLite的性能优化的亿点点记录
R文件找不到问题
#region 与 #endregion 用法(注释代码的折叠)
TRACE32——变量显示选项Setup.Var
slot插槽二三事
R语言sys函数系列(二)
腾讯云服务器 2003 Can‘t connect to MySQL server on ‘124.221.222.175‘ (0)
开发依赖vs生产依赖
何为“天道”?
提高分层 SQL 结构的性能
如何处理SQL Server中附加数据库时出现的错误
Nacos集群搭建(图文教程)
Calculate FLOPs of your own model in Pytorch | thop.profile() method
2022年T电梯修理考试题模拟考试题库及答案
C语言力扣第60题之排列序列。广度优先搜索、简单除法定位








