aliyuncs

package module
v0.0.0-...-8694d5b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2021 License: MIT Imports: 13 Imported by: 0

README

aliyuncs

阿里云通讯(原阿里大于)Golang SDK

准备

创建阿里云账号

为了访问短信服务,需要有一个阿里云账号。

获取阿里云访问密钥

阿里云访问密钥是阿里云为用户使用 API(非控制台)来访问其云资源设计的“安全口令”。 您可以用它来签名 API 请求内容以通过服务端的安全验证。

该访问秘钥成对(AccessKeyId 与 AccessKeySecret)生成和使用。

短信签名

根据用户属性来创建符合自身属性的签名信息。签名申请手册

注意:短信签名需要审核通过后才可以使用。

短信模版

短信模板,即具体发送的短信内容。模版申请手册

使用

import (
    cs "github.com/crazytaxii/aliyuncs"
)


func main() {
    tmpl := cs.CSTemplate{
        "code": "123456",
    }

    client := cs.NewClient("access_id", "access_secret", 10 * time.Second)
    if _, err := client.SendSMS(
        "13712341234", // 指定手机号
        "sign_name", // 短信签名
        "SMS_123456789", // 短信模板ID
        tmpl, // 短信模板变量
    ); err != nil {
        log.Fatal("err:", err)
    }
}

Documentation

Index

Constants

View Source
const (
	BaseURL = "http://dysmsapi.aliyuncs.com"

	Format           = "JSON"
	SignatureMethod  = "HMAC-SHA1"
	SignatureVersion = "1.0"
	APIVersion       = "2017-05-25"
	RegionID         = "cn-hangzhou"

	ActionSMS      = "SendSms"
	ActionBatchSMS = "SendBatchSms"
	ActionCall     = "SingleCallByTts"
)
View Source
const (
	StatusOK = "OK"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CSContext

type CSContext interface {
	// contains filtered or unexported methods
}

type CSTemplate

type CSTemplate map[string]string

func (CSTemplate) Marshal

func (t CSTemplate) Marshal() (string, error)

type Client

type Client struct {
	*http.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient(keyID, secret string, timeout time.Duration) *Client

func (*Client) CallByTTS

func (c *Client) CallByTTS(phone, showAs, ttsCode string, template CSTemplate) (string, error)

func (*Client) SendSMS

func (c *Client) SendSMS(phone, signName, templateCode string, template CSTemplate) (string, error)

*

  • 向指定手机号发送短信

type ResponseMessage

type ResponseMessage interface {
	// contains filtered or unexported methods
}

type SendSMSResponse

type SendSMSResponse struct {
	BizID string `json:"BizId"`
	// contains filtered or unexported fields
}

type SingleCallByTTSResponse

type SingleCallByTTSResponse struct {
	CallID string `json:"CallId"`
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL