使用PHP从模板发送短信
使用HTTP和PHP发送短信模板
PHP : API文档
使用PHP从模板发送短信
<?
$class="sms";
$method="sendsmsfromtemplate";
$user="user";
$password="password";
$to="34600000000";
$idtemplate=1000;
$params="mobile:123456789,name:test+name";
$scheduledatetime="";
$output="";
$result = file_get_contents("https://www.afilnet.com/api/http/?class=".$class."&method=".$method."&user=".$user."&password=".$password."&to=".$to."&idtemplate=".$idtemplate."¶ms=".$params."&scheduledatetime=".$scheduledatetime."&output=".$output);
?>
<?
$url = "https://www.afilnet.com/api/http/";
$fields = array(
"class" => urlencode("sms"),
"method" => urlencode("sendsmsfromtemplate"),
"user" => urlencode("user"),
"password" => urlencode("password"),
"to" => urlencode("34600000000"),
"idtemplate" => urlencode(1000),
"params" => urlencode("mobile:123456789,name:test+name"),
"scheduledatetime" => urlencode(""),
"output" => urlencode(""),
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
curl_close($ch);
?>
<?
$url = "https://www.afilnet.com/api/basic/";
$fields = array(
"class" => urlencode("sms"),
"method" => urlencode("sendsmsfromtemplate"),
"to" => urlencode("34600000000"),
"idtemplate" => urlencode(1000),
"params" => urlencode("mobile:123456789,name:test+name"),
"scheduledatetime" => urlencode(""),
"output" => urlencode(""),
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_USERPWD, $user.":".$password);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch,CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpcode == 401)
{
// LOGIN ERROR
} else {
// SUCCESS LOGIN
}
?>
<?
# This example requires nusoap
require_once('nusoap.php');
$class="sms";
$method="sendsmsfromtemplate";
$user="user";
$password="password";
$to="34600000000";
$idtemplate=1000;
$params="mobile:123456789,name:test+name";
$scheduledatetime="";
$output="";
# Create SOAP Client
$soapclient = new soapclient('https://www.afilnet.com/api/soap/index.php?wsdl');
# Call to method
$result = $soapclient->call($user, $password, $class, $method, '{"to":"'.$to.'","idtemplate":"'.$idtemplate.'","params":"'.$params.'","scheduledatetime":"'.$scheduledatetime.'","output":"'.$output.'"}');
?>
参数 | 描述 | 必修/可选 |
---|---|---|
class=sms | 要求的课程:要求的课程 | 必修 |
method=sendsmsfromtemplate | 请求的类方法:发出请求的类的方法 | 必修 |
user | 您的Afilnet帐户的用户和电子邮件 | 必修 |
password | 您的Afilnet帐户的密码 | 必修 |
to | 目的地手机号码 | 必修 |
idtemplate | 范本编号 | 必修 |
params |
自定义模板中要替换的参数(< |
可选的 |
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 | 您的余额不足 |
NOT_ACCESS_TO_TEMPLATE | 您无权访问所选模板 |
参数:
- class : sms
- method : sendsmsfromtemplate
- user : user
- password : password
- to : 34600000000
- idtemplate : 1000
- params : mobile:123456789,name:test+name
- scheduledatetime :
- output :
请求:
https://www.afilnet.com/api/http/?class=sms&method=sendsmsfromtemplate&user=user&password=password&to=34600000000&idtemplate=1000¶ms=mobile:123456789,name:test+name&scheduledatetime=&output=