uSpeedo
查看我们的API参考文档和快速入门。从使用SDK到针对Web、iOS和Android的示例应用程序,您将获得所需的内容。
快速发送信息
查看文档、示例代码和开发工具,您需要快速构建所需的内容。我们将处理移动运营商和全球法规的复杂性。让我们开始构建。
- Golang
- Java
- Python
- Php
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()
}
Java SDK
package com.uspeedo.example;
import com.uspeedo.common.config.Config;
import com.uspeedo.common.credential.Credential;
import com.uspeedo.common.exception.USpeedoException;
import com.uspeedo.asms.models.*;
import com.uspeedo.asms.client.AsmsClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays;
import java.util.Collections;
public class Main {
private static final Logger logger = LoggerFactory.getLogger(Main.class);
public static void invokeSendMessage() {
AsmsClient asmsClient = getClient();
SendBatchUSMSMessageReq req = new SendBatchUSMSMessageReq();
SendBatchUSMSMessageReq.SendInfo info = new SendBatchUSMSMessageReq.SendInfo();
SendBatchUSMSMessageReq.TargetPhone targetPhone = new SendBatchUSMSMessageReq.TargetPhone();
info.setSenderId("uspeedo");
info.setTemplateId("UTAXXXXXXXXXXX");
targetPhone.setPhone("(11)11111111");
String[] templateParams = {"xxxx"};
targetPhone.setTemplateParams(Arrays.asList(templateParams));
info.setTarget(Collections.singletonList(targetPhone));
req.setTaskContent(Collections.singletonList(info));
try {
SendBatchUSMSMessageResp resp = asmsClient.sendBatchUSMSMessage(req);
System.out.println(resp);
} catch (USpeedoException e) {
System.out.println(e.getMessage());
}
}
public static void invokeTemplateAPi() {
AsmsClient asmsClient = getClient();
// Create Template
CreateUSMSTemplateReq createUSMSTemplateReq = new CreateUSMSTemplateReq();
createUSMSTemplateReq.setTemplate("Your verification code is1 {1}");
createUSMSTemplateReq.setPurpose(1);
createUSMSTemplateReq.setRemark("this is a test template");
createUSMSTemplateReq.setTemplateName("test template");
try {
CreateUSMSTemplateResp createUSMSTemplateResp = asmsClient.createUSMSTemplate(createUSMSTemplateReq);
System.out.println(createUSMSTemplateResp);
} catch (USpeedoException e) {
System.out.println(e.getMessage());
}
// Query Template
QueryUSMSTemplateReq queryTemplateReq = new QueryUSMSTemplateReq();
String[] templateIds = {"UTAxxxxxxxxx"};
queryTemplateReq.setTemplateId(Arrays.asList(templateIds));
try {
QueryUSMSTemplateResp queryTemplateResp = asmsClient.queryUSMSTemplate(queryTemplateReq);
System.out.println(queryTemplateResp.getData());
} catch (USpeedoException e) {
System.out.println(e.getMessage());
}
// Update Template
UpdateUSMSTemplateReq updateTemplateReq = new UpdateUSMSTemplateReq();
updateTemplateReq.setTemplateId("UTAxxxxxxxxx");
updateTemplateReq.setTemplate("Your verification code is {1},thanks");
try {
UpdateUSMSTemplateResp updateTemplateResp = asmsClient.updateUSMSTemplate(updateTemplateReq);
System.out.println(updateTemplateResp);
} catch (USpeedoException e) {
System.out.println(e.getMessage());
}
// Delete Template
DeleteUSMSTemplateReq deleteTemplateReq = new DeleteUSMSTemplateReq();
deleteTemplateReq.setTemplateIds(Arrays.asList(templateIds));
try {
DeleteUSMSTemplateResp deleteTemplateResp = asmsClient.deleteUSMSTemplate(deleteTemplateReq);
System.out.println(deleteTemplateResp);
} catch (USpeedoException e) {
System.out.println(e.getMessage());
}
}
public static AsmsClient getClient() {
Config config = new Config();
config.setLogger(logger);
String publicKey = System.getenv("USpeedo_PUBLIC_KEY");
String privateKey = System.getenv("USpeedo_PRIVATE_KEY");
Credential credential = new Credential(publicKey, privateKey);
return new AsmsClient(config, credential);
}
public static void main(String[] args) {
// invokeTemplateAPi();
invokeSendMessage();
}
}
Python SDK
import logging
import os
from uspeedo.client import Client
from uspeedo.core.exc import USpeedoException
logger = logging.getLogger("uspeedo")
logger.setLevel(logging.DEBUG)
def get_asms_client():
client = Client(
{
"public_key": os.getenv("USPEEDO_PUBLIC_KEY"),
"private_key": os.getenv("USPEEDO_PRIVATE_KEY"),
"base_url": "https://api.xxx.com/api/"
}
)
return client
def invoke_send_message():
client = get_asms_client()
req = {
"TaskContent": [{
"TemplateId": "UTAXXXXXXXXXXX",
"SenderId": "uspeedo",
"Target": [{
"Phone": "(1)11111111",
"TemplateParams": ["1111"]
}]
}]
}
try:
response_json = client.asms().send_batch_usms_message(req)
print(response_json)
except USpeedoException as e:
print(e)
def invoke_template_api():
client = get_asms_client()
try:
create_template_req = {
"Template": "Your verification code is {1}",
"Purpose": 1,
"Remark": "this is a test template",
"TemplateName": "test template"
}
response_json = client.asms().create_usms_template(create_template_req)
print(response_json)
except USpeedoException as e:
print(e)
try:
query_template_req = {
"AccountId": "60000011",
"TemplateId": ["UTA230227EL4IW1", "UTA230227JVIB02"],
}
response_json = client.asms().query_usms_template(query_template_req)
print(response_json)
except USpeedoException as e:
print(e)
try:
update_template_req = {
"TemplateId": "UTAXXXXXXXXXXX",
"Template": "Your verification code is {1},thanks"
}
response_json = client.asms().update_usms_template(update_template_req)
print(response_json)
except USpeedoException as e:
print(e)
try:
delete_template_req = {
"TemplateIds": ["UTAXXXXXXXXXXX"],
}
response_json = client.asms().delete_usms_template(delete_template_req)
print(response_json)
except USpeedoException as e:
print(e)
def main():
# invoke_send_message()
invoke_template_api()
if __name__ == '__main__':
main()
Php SDK
use USpeedo\UHost\UHostClient;
use USpeedo\Core\Exception\USpeedoException;
use USpeedo\UHost\Apis\CreateUHostInstanceRequest;
use USpeedo\UHost\Params\CreateUHostInstanceParamDisks;
$client = new UHostClient([
"publicKey" => getenv("USPEEDO_PUBLIC_KEY"),
"privateKey" => getenv("USPEEDO_PRIVATE_KEY"),
]);
// Create Instance
try {
$req = new CreateUHostInstanceRequest();
$req->setName("sdk-php-example");
$req->setImageId("...");
$req->setLoginMode("Password");
$req->setPassword(base64_encode("USpeedo1234!"));
$req->setCPU(1);
$req->setMemory(1024);
$disk = new CreateUHostInstanceParamDisks();
$disk->setSize(40);
$disk->setType("CLOUD_SSD");
$disk->setIsBoot("True");
$req->setDisks([$disk]);
$resp = $client->createUHostInstance($req);
} catch (USpeedoException $e) {
throw $e;
}
$id = $resp->getUHostIds()[0];