当前位置:网站首页>Alibaba cloud sends SMS verification code
Alibaba cloud sends SMS verification code
2022-07-05 09:05:00 【I want to express myself to the girl I like with code】
1. Buy Alibaba cloud SMS and templates
2. Mobile phone verification code generation
3. Alibaba cloud sends SMS verification code
rely on
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>dysmsapi20170525</artifactId>
<version>2.0.10</version>
</dependency>
Code ( Copy and use )
Add your own id and secret after
package com.example.etf.story.service;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.tea.*;
import com.aliyun.dysmsapi20170525.models.*;
import com.aliyun.teautil.models.*;
import java.util.Random;
public class AliSMS {
/**
* Use AK&SK Initialization account Client
* @param accessKeyId
* @param accessKeySecret
* @return Client
* @throws Exception
*/
public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
Config config = new Config()
// Your AccessKey ID
.setAccessKeyId("ss")
// Your AccessKey Secret
.setAccessKeySecret("xxx");
// Domain name visited
config.endpoint = "dysmsapi.aliyuncs.com";
return new com.aliyun.dysmsapi20170525.Client(config);
}
// Generate random number
/**
*
* @param strSource// Add letters and random numbers into the set , Raw random string , You can define
* @param num // Generate a few digit verification code , You can define
* @return
*/
public static String suijiNum(String strSource,int num){
Random random = new Random();
int maxLength=strSource.length()-1;// Random index maximization , Because the index is from 0 Start , So the index of the maximum It's length. -1
String[] strSources = strSource.split("");// The segmentation string is an optional character array , Used for index selection
// The final verification code is spliced ,stringBuffer Create only one object to save memory , And fast , This scenario does not require thread safety
StringBuffer appendStrEnd = new StringBuffer();
for (int i = 0; i < num; i++) {
int suijiIndex = random.nextInt(maxLength);// Build index , Index the position of a character in your original string
String strAlone = strSources[suijiIndex];// Get the single character value in the string
appendStrEnd.append(strAlone);
}
return appendStrEnd.toString();
}
public static void SendSMSByAli(String phone,String code) throws Exception {
com.aliyun.dysmsapi20170525.Client client = AliSMS.createClient("accessKeyId", "accessKeySecret");
SendSmsRequest sendSmsRequest = new SendSmsRequest()
.setPhoneNumbers(phone)
.setSignName("learning Ah, friend ")// Signature name 【 Be careful not to write the name of the template 】
.setTemplateCode("SMS_243991108")// Templates id
.setTemplateParam("{\"code\":\""+code+"\"}");
RuntimeOptions runtime = new RuntimeOptions();
try {
// Please print the copy code yourself API The return value of
client.sendSmsWithOptions(sendSmsRequest, runtime);
} catch (TeaException error) {
// If necessary , Please print error
com.aliyun.teautil.Common.assertAsString(error.message);
} catch (Exception _error) {
TeaException error = new TeaException(_error.getMessage(), _error);
// If necessary , Please print error
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
}
边栏推荐
- Golang foundation -- map, array and slice store different types of data
- 多元线性回归(梯度下降法)
- 混淆矩阵(Confusion Matrix)
- Jenkins Pipeline 方法(函数)定义及调用
- TF coordinate transformation of common components of ros-9 ROS
- Introduction Guide to stereo vision (1): coordinate system and camera parameters
- AUTOSAR从入门到精通100讲(103)-dbc文件的格式以及创建详解
- np. allclose
- Confusing basic concepts member variables local variables global variables
- Multiple linear regression (sklearn method)
猜你喜欢
nodejs_ 01_ fs. readFile
Halcon blob analysis (ball.hdev)
Nodejs modularization
Introduction Guide to stereo vision (3): Zhang calibration method of camera calibration [ultra detailed and worthy of collection]
Huber Loss
Huber Loss
混淆矩阵(Confusion Matrix)
Summary and Reflection on issues related to seq2seq, attention and transformer in hands-on deep learning
Blogger article navigation (classified, real-time update, permanent top)
C#【必备技能篇】ConfigurationManager 类的使用(文件App.config的使用)
随机推荐
Add discount recharge and discount shadow ticket plug-ins to the resource realization applet
[Niuke brush questions day4] jz55 depth of binary tree
AUTOSAR从入门到精通100讲(103)-dbc文件的格式以及创建详解
Introduction Guide to stereo vision (2): key matrix (essential matrix, basic matrix, homography matrix)
scipy. misc. imread()
Generate confrontation network
12、动态链接库,dll
The location search property gets the login user name
Illustrated network: what is gateway load balancing protocol GLBP?
Applet (use of NPM package)
Applet (subcontracting)
Dynamic dimensions required for input: input, but no shapes were provided. Automatically overriding
Introduction Guide to stereo vision (1): coordinate system and camera parameters
js异步错误处理
C#【必备技能篇】ConfigurationManager 类的使用(文件App.config的使用)
Applet (global data sharing)
一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]
kubeadm系列-01-preflight究竟有多少check
Halcon: check of blob analysis_ Blister capsule detection
[daiy4] jz32 print binary tree from top to bottom