49
aliyun sms 非官方sdk
source link: https://www.tuicool.com/articles/BrARNfq
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
由于没有注意到ali官方发布到新版的golang sdk for SMS service 快实现完成完成了才发现, 索性把它实现完成,只是没有补充足够的测试. 相比官方sdk, 个人认为实现要比官方版简洁,调用优雅, 可扩展性强于官方版.
description: golang version short message sender underline with ali sms service
Installation
Use go get
to install SDK
$ go get -u github.com/guoapeng/gosms
Quick Examples
Before you begin, you need to sign up for an Alibaba Cloud account and retrieve your Credentials .
Create sender and send short message
package main import "github.com/guoapeng/gosms" func main() { sender := gosms.NewSender("your_accessKeyId", "your_AccessSecret", "your_SignName") msgJSON := `{code:"1234"}` if response, err := sender.Send("13288888888", msgJSON, "SMS_9999999"); err ==nil { // SMS_9999999 is message template id defined in aliyun's sms service if "OK" == response.Code { log.Println("sent message successfully and get response ",response) } else { log.Println("sent message with issue ",response) } } else { log.Fatal("failed to send message with error", err) } }
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK