跳到主要内容

uSpeedo

查看我们的API参考文档和快速入门。从使用SDK到针对Web、iOS和Android的示例应用程序,您将获得所需的内容。

快速发送信息

查看文档、示例代码和开发工具,您需要快速构建所需的内容。我们将处理移动运营商和全球法规的复杂性。让我们开始构建。

Golang SDK

package main

import (
"fmt"
"time"

"github.com/uspeedo/uspeedo-sdk-go/services/asms"
"github.com/uspeedo/uspeedo-sdk-go/services/asms/models"
"github.com/uspeedo/uspeedo-sdk-go/uspeedo"
"github.com/uspeedo/uspeedo-sdk-go/uspeedo/auth"
"github.com/uspeedo/uspeedo-sdk-go/uspeedo/log"
)

func TestTemplateApi() {
asmsClient := getAsmsClient()

// Create Template

createTemplateReq := asmsClient.NewCreateUSMSTemplateReq()
createTemplateReq.Template = uspeedo.String("Your verification code is {1}")
createTemplateReq.Purpose = uspeedo.Int(1)
createTemplateReq.Remark = uspeedo.String("this is a test template")
createTemplateReq.TemplateName = uspeedo.String("test template")

createTemplateResp, err := asmsClient.CreateUSMSTemplate(createTemplateReq)
if err != nil {
fmt.Printf("something bad happened: %s
", err)
} else {
fmt.Printf("response of the request: %v
", createTemplateResp)
}

// Query Template

queryTemplateReq := asmsClient.NewQueryUSMSTemplateReq()
queryTemplateReq.TemplateId = []string{"UTAXXXXXXXXXXX"}
queryTemplateResp, err := asmsClient.QueryUSMSTemplate(queryTemplateReq)
if err != nil {
fmt.Printf("something bad happened: %s
", err)
} else {
fmt.Printf("response of the request: %v
", queryTemplateResp)
}

// Update Template

updateTemplateReq := asmsClient.NewUpdateUSMSTemplateReq()
updateTemplateReq.TemplateId = uspeedo.String("UTAXXXXXXXXXXX")
updateTemplateReq.Template = uspeedo.String("Your verification code is {1},thanks")
updateTemplateResp, err := asmsClient.UpdateUSMSTemplate(updateTemplateReq)
if err != nil {
fmt.Printf("something bad happened: %s
", err)
} else {
fmt.Printf("response of the request: %v
", updateTemplateResp)
}

// Delete Template

deleteTemplateReq := asmsClient.NewDeleteUSMSTemplateReq()
deleteTemplateReq.TemplateIds = []string{"UTAXXXXXXXXXXX"}
deleteTemplateResp, err := asmsClient.DeleteUSMSTemplate(deleteTemplateReq)
if err != nil {
fmt.Printf("something bad happened: %s
", err)
} else {
fmt.Printf("response of the request: %v
", deleteTemplateResp)
}

}

func getAsmsClient() *asms.AsmsClient {
cfg := uspeedo.NewConfig()
cfg.LogLevel = log.DebugLevel
cfg.Timeout = 5 * time.Second
cfg.MaxRetries = 1

credential := auth.NewCredential()

credential.PublicKey = "Get the access key id from uspeedo"
credential.PrivateKey = "Get the access key secret from uspeedo"

asmsClient := asms.NewClient(&cfg, &credential)

return asmsClient
}

func TestSendMessage() {
asmsClient := getAsmsClient()
req := asmsClient.NewSendBatchUSMSMessageReq()
req.TaskContent = []models.SendInfo{
{
TemplateId: uspeedo.String("UTAXXXXXXXXXXX"),
SenderId: uspeedo.String("uspeedo"),
Target: []models.TargetPhone{
{
Phone: uspeedo.String("(11)11111111"),
TemplateParams: []string{"111111"},
},
},
},
}

// send request
resp, err := asmsClient.SendBatchUSMSMessage(req)
if err != nil {
fmt.Printf("something bad happened: %s
", err)
} else {
fmt.Printf("response of the request: %v
", resp)
}
}

func main() {
TestTemplateApi()
TestSendMessage()
}