使用Go发送短信
使用HTTP和Go发送短信
Go : API文档
使用Go发送短信
Este método le permite enviar SMS a un destinatario utilizando Go. Enviar un SMS con Go es tan sencillo como enviar el origin, destino y el mensaje a enviar a través de una petición a nuestra API.
package main
import (
"io/ioutil"
"log"
"net/http"
)
func main() {
var aclass string = "sms"
var method string = "sendsms"
var user string = "user"
var password string = "password"
var from string = "Afilnet"
var to string = "34600000000"
var sms string = "sms+test"
var scheduledatetime string = ""
var output string = ""
var request string = "https://www.afilnet.com/api/http/?class="+aclass+"&method="+method+"&user="+user+"&password="+password+"&from="+from+"&to="+to+"&sms="+sms+"&scheduledatetime="+scheduledatetime+"&output="+output
resp, err := http.Get(request)
if(err != nil) {
log.Fatalln(err)
}
defer resp.Body.Close()
ioutil.ReadAll(resp.Body)
if(err != nil) {
log.Fatalln(err)
}
}
package main
import (
"io/ioutil"
"log"
"net/http"
"net/url"
)
func main() {
formData := url.Values{
"class" : {"sms"},
"method" : {"sendsms"},
"user" : {"user"},
"password" : {"password"},
"from" : {"Afilnet"},
"to" : {"34600000000"},
"sms" : {"sms+test"},
"scheduledatetime" : {""},
"output" : {""},
}
resp, err := http.PostForm("https://www.afilnet.com/api/http/", formData)
if(err != nil) {
log.Fatalln(err)
}
defer resp.Body.Close()
ioutil.ReadAll(resp.Body)
if(err != nil) {
log.Fatalln(err)
}
}
参数 | 描述 | 必修/可选 |
---|---|---|
class=sms | 要求的课程:要求的课程 | 必修 |
method=sendsms | 请求的类方法:发出请求的类的方法 | 必修 |
user | 您的Afilnet帐户的用户和电子邮件 | 必修 |
password | 您的Afilnet帐户的密码 | 必修 |
from | 发件人 | 必修 |
to | 收件人的手机号码 | 必修 |
sms | 短信发送 | 必修 |
scheduledatetime | 以yyyy-mm-dd hh:mm:ss格式发送日期和时间 | 可选的 |
output | 结果的输出格式 | 可选的 |
发出请求时,您将收到以下字段:
- status
-
结果(如果status = success),您将在此处收到以下值:
- messageid
- credits
- 错误(如果status = error),在这里您将收到错误代码
下面列出了可能的错误代码
码 | 描述 |
---|---|
MISSING_USER | 不包括用户或电子邮件 |
MISSING_PASSWORD | 不包含密码 |
MISSING_CLASS | 不包括课程 |
MISSING_METHOD | 不包括方法 |
MISSING_COMPULSORY_PARAM | 不包括强制参数 |
INCORRECT_USER_PASSWORD | 用户或密码错误 |
INCORRECT_CLASS | 班级不正确 |
INCORRECT_METHOD | 方法不正确 |
NO_ROUTE_AVAILABLE | 指定的目的地没有可用的路径 |
NO_CREDITS | 您的余额不足 |
参数:
- class : sms
- method : sendsms
- user : user
- password : password
- from : Afilnet
- to : 34600000000
- sms : sms+test
- scheduledatetime :
- output :
请求:
https://www.afilnet.com/api/http/?class=sms&method=sendsms&user=user&password=password&from=Afilnet&to=34600000000&sms=sms+test&scheduledatetime=&output=