当前位置:网站首页>Go sends SMS based on alicloud
Go sends SMS based on alicloud
2022-06-12 11:27:00 【. fried eggs with tomatoes】
brief introduction
Code
package main
import (
"fmt"
"github.com/alibabacloud-go/darabonba-openapi/client"
dysmsapi20170525 "github.com/alibabacloud-go/dysmsapi-20170525/v2/client"
"math/rand"
"strings"
"time"
)
func main() {
accessKeyId := " Yours accessKeyId"
accessKeySecret := " Yours accessKeySecret "
endpoint := "dysmsapi.aliyuncs.com"
c := &client.Config{
AccessKeyId: &accessKeyId, AccessKeySecret: &accessKeySecret, Endpoint: &endpoint}
newClient, err := dysmsapi20170525.NewClient(c)
if err != nil {
panic(err)
}
phoneNumber := " Mobile number to send "
templateCode := "SMS_154950909"
signName := " Alibaba cloud SMS test "
code := "{\"code\":" + GenerateSmsCode(6) + "}"
request := &dysmsapi20170525.SendSmsRequest{
PhoneNumbers: &phoneNumber,
TemplateCode: &templateCode,
SignName: &signName,
TemplateParam: &code,
}
sms, err := newClient.SendSms(request)
if err != nil {
panic(err)
}
fmt.Println(sms)
}
// GenerateSmsCode Generate verification code ;length Represents the length of the verification code
func GenerateSmsCode(length int) string {
numberic := [10]byte{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
rand.Seed(time.Now().Unix())
var sb strings.Builder
for i := 0; i < length; i++ {
fmt.Fprintf(&sb, "%d", numberic[rand.Intn(len(numberic))])
}
return sb.String()
}
Back to sms
{
"headers": {
"access-control-allow-headers": "X-Requested-With, X-Sequence, _aop_secret, _aop_signature, x-acs-action, x-acs-version, x-acs-date, Content-Type",
"access-control-allow-methods": "POST, GET, OPTIONS, PUT, DELETE",
"access-control-allow-origin": "*",
"access-control-max-age": "172800",
"connection": "keep-alive",
"content-length": "110",
"content-type": "application/json;charset=utf-8",
"date": "Sun, 12 Jun 2022 02:15:49 GMT",
"x-acs-request-id": "6BC0AE17-B50A-5B0F-B5BF-10AEDC602909",
"x-acs-trace-id": "fc4f2bf6ec8a9f9541103cfa0395c47a"
},
"body": {
"BizId": "361607455000149340^0",
"Code": "OK",
"Message": "OK",
"RequestId": "6BC0AE17-B50A-5B0F-B5BF-10AEDC602909"
}
}
边栏推荐
- 网络的拓扑结构
- Thinking about the cooperation process of Network Library -- Some Thoughts on reading brpc
- SOT23(Small Outline Transistor)
- M-Arch(番外11)GD32L233评测-PWM驱动有源蜂鸣器
- Heavyweight proxy cache server squid
- Humans want to have money, power, beauty, eternal life and happiness... But turtles only want to be a turtle
- Golang基础(6)
- 字节序(网络/主机)转换
- AcWing 131. The largest rectangle in the histogram (monotone stack classic application template)
- Several solutions across domains
猜你喜欢

M-arch (fanwai 12) gd32l233 evaluation -cau encryption and decryption (tease Xiaobian)

AcWing 41. 包含min函数的栈(单调栈)

Create vite source code analysis

M-Arch(番外12)GD32L233评测-CAU加解密(捉弄下小编)

Clickhouse column basic data type description

【clickhouse专栏】基础数据类型说明

DS18B20数字温度计 (一) 电气特性, 寄生供电模式和远距离接线

Don't swallow rice with vinegar! Teach you 2 moves to make the fish bones "run out" safely

Using stairs function in MATLAB

890. 查找和替换模式
随机推荐
go基于腾讯云实现发送短信
M-Arch(番外13)GD32L233评测-来点音乐
AcWing 128. Editor (to effectively modify the specified position in the top stack)
scanf返回值被忽略的原因及其解决方法
Clickhouse column basic data type description
K58. Chapter 1 installing kubernetes V1.23 based on kubeadm -- cluster deployment
Pytoch notes
k53.第二章 基于二进制包安装kubernetes v1.22 --集群部署
go基于阿里云实现发送短信
Windows10 install mysql-8.0.28-winx64
元宇宙链游与传统游戏的区别
无限生长,我们都将奔赴未来 | InfoQ中国成立15周年
AcWing 131. The largest rectangle in the histogram (monotone stack classic application template)
[the 11th national competition of Blue Bridge Cup single chip microcomputer]
^34 scope interview questions
k59.第二章 基于二进制包安装kubernetes v1.23 --集群部署
selenium使用代理IP
Reading mysql45 lecture - self summary (part)
tensorflow 2.x 多分类混淆矩阵及评价指标计算方法(精确率、召回率、f1分数)
AcWing 131. 直方图中最大的矩形(单调栈经典运用 模板)