当前位置:网站首页>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"
}
}
边栏推荐
- ^34 scope interview questions
- Sendmail Dovecot 邮件服务器
- Differences among various cross compiling tools of arm
- 【CF1392D】D. Omkar and Bed Wars(环形与后效性dp)
- Lambda表达式 | 浅解
- M-Arch(番外10)GD32L233评测-SPI驱动DS1302
- Several solutions across domains
- Thinking about the cooperation process of Network Library -- Some Thoughts on reading brpc
- 35. search insertion position
- 模块8作业
猜你喜欢

人类想要拥有金钱、权力、美丽、永生、幸福……但海龟只想做一只海龟

^33 variable promotion and function promotion interview questions

Les humains veulent de l'argent, du pouvoir, de la beauté, de l'immortalité, du bonheur... Mais les tortues ne veulent être qu'une tortue.

k52.第一章 基于kubeadm安装kubernetes v1.22 -- 集群部署

Reading mysql45 lecture - self summary (part)

The reason why scanf return value is ignored and its solution

Network topology

多普勒效应的基本原理

logrotate日志轮转方式create和copytruncate原理
![[Blue Bridge Cup SCM 11th National race]](/img/da/3c8a9efd5b28f67816f239531a0339.png)
[Blue Bridge Cup SCM 11th National race]
随机推荐
Construction and construction of meta Universe System
^34 scope interview questions
套接字编程Udp篇
【蓝桥杯单片机 国赛 第十一届】
AI - face
Create vite source code analysis
套接字编程TCP篇
FPGA key experiment
tensorflow 2. X multi classification confusion matrix and evaluation index calculation method (accuracy rate, recall rate, F1 score)
模块8作业
Golang Foundation (7)
arm各种交叉编译工具的区别
(37) How bee uses different data source instances at the same time
FormatConversionTool. exe
Leetcode 162 Looking for peak value (June 11, 2022)
MySQL45讲 01 | 基础架构:一条SQL查询语句是如何执行的?
【clickhouse专栏】基础数据类型说明
Clickhouse column basic data type description
Lambda表达式 | 浅解
【CF1392D】D. Omkar and Bed Wars(环形与后效性dp)