八信通API调用说明(Url版)

发送短信,< 提交方式:Post >

发送接口地址

http://18dx.cn/API/Services.aspx?action=操作类型&user=本站用户名&mobile=手机号码&content=短信内容&time=发送时间&msgid=批次ID&hashcode=校验码&encode=编码类型

提示:HTTP调用URL接口时, 参数值必须URL编码后再调用(注:未URL编码短信将会是乱码)

参数变量 说明
发送接口地址Url http://18dx.cn/API/Services.aspx
action 操作类型
user 本站用户名(如您无本站用户名请先联系客服开通)
hashcode 用户密码(明文或MD5加密)
mobile 目的手机号码(多个手机号请用半角逗号或封号隔开)
content 短信内容,最多支持250个字,67个字按一条短信计费
time 短信定时发送时间,可以传空值,为空则视为立即发送,格式:yyyy-MM-dd HH:mm:ss
msgid 短信批次的唯一ID,长整型,可以传空值,若不传空值请做好唯一判断
发送成功后返回字符串中,将返回系统自动给出的批次ID,
该ID可以与手机号码一起用于配置短信报告与上行短信记录
encode 编码,为空或不加该参数,默认为UTF-8, 可以传: GB2312 ,gbk 等

多个手机号请用半角“,”隔开,如:13888888886,13888888887,1388888888 。

短信内容支持长短信,最多250个字,67个字按一条短信计费。

短信发送后返回值 说明
1 发送成功
0 系统原因失败
-1 用户不存在或已禁用
-2 hashcode或密码不正确
-3 接收号码不正确
-4 内容为空或超长
-6 内容含非法字符
-7 帐户余额不足
-8 当天小批次限额不足
-9 提交过于频繁,超过1分钟内限定的流量
-10 未添加通道签名

一次提交号码数小于某个限定值被视为小批次短信(默认值为2000),小批次短信的总和不能超过限定的值(默认为20000),否则提交不成功,返回-8 。

每分钟最多提交短信批次不能超过某个限定值(默认值20)。

返回字符串 说 明
errid 返回值
msg 返回说明字符串
msgid 批次ID
balance 余额
fee 扣费号码数

发送成功返回字符串例:1&errid=1&fee=2&balance=2582&fails=&msgid=634541149212681528&msg=全部发送成功。

发送失败返回字符串例: -1&errid=-1&msg=用户不存在或已禁用。

操作类型 说 明 参 数 返回值
msgsend 发送短信 action=msgsend&user=本站用户名&mobile=手机号码&content=短信内容&time=发送时间&msgid=批次ID&hashcode=校验码
例:1&errid=1&fee=2&balance=2
582&fails=&msgid=6345411492
12681528&msg=全部发送成功 
getbalance 取余额 action=getbalance&user=本站用户名&hashcode=校验码 例:2582

实例目录

ASP程序实例 | C#程序示例 | JAVA程序示例 | PHP程序示例 | VB.NET程序实例


ASP程序实例

<%
'常用函数
'输入url目标网页地址,返回值getHTTPPage是目标网页的html代码
function getHTTPPage(url)
dim Http
set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then 
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
set http=nothing
if err.number<>0 then err.Clear 
end function
Function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText 
objstream.Close
set objstream = nothing
End Function

'自已组合一下提交的URL加入自己的账号和密码
sms_url="http://18dx.cn/API/Services.aspx?action=msgsend&user=本站用户名&mobile=手机号码&content=短信内容&time=发送时间&msgid=批次ID&hashcode=校验码&encode=GB2312"
response.write getHTTPPage(sms_url)
%>
        

C#程序示例

//需要用到的命名空间
using System.Net;
using System.IO;
using System.Text;
//调用时只需要把拼成的URL传给该函数即可。判断返回值即可
public string GetHtmlFromUrl(string url)
{
string strRet = null;
if(url==null || url.Trim().ToString()=="")
{
return strRet;
}
string targeturl = url.Trim().ToString();
try
{
HttpWebRequest hr = (HttpWebRequest)WebRequest.Create(targeturl);
hr.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
hr.Method = "GET";
hr.Timeout = 30 * 60 * 1000;
WebResponse hs = hr.GetResponse();
Stream sr = hs.GetResponseStream();
StreamReader ser = new StreamReader(sr, Encoding.Default);
strRet = ser.ReadToEnd(); 
}
catch (Exception ex)
{
strRet = null;
}
return strRet;
}
        

JAVA程序示例

import java.io.UnsupportedEncodingException;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

public class SendMsg {

public static void main(String[] args)throws Exception
{

HttpClient client = new HttpClient();
PostMethod post = new PostMethod("http://18dx.cn/API/Services.aspx"); 
post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");//在头文件中设置转码
NameValuePair[] data ={ new NameValuePair("action", "msgsend"),new NameValuePair("user", "本站用户名"),new NameValuePair("mobile", "手机号码"),new NameValuePair("content","短信内容"),new NameValuePair("time","发送时间"),new NameValuePair("msgid","批次ID"),new NameValuePair("hashcode","校验码")};
post.setRequestBody(data);

client.executeMethod(post);
Header[] headers = post.getResponseHeaders();
int statusCode = post.getStatusCode();
System.out.println("statusCode:"+statusCode);
for(Header h : headers)
{
System.out.println(h.toString());
}
String result = new String(post.getResponseBodyAsString().getBytes("UTF-8")); 
System.out.println(result);


post.releaseConnection();

}

}
        

PHP程序示例

$url='http://18dx.cn/API/Services.aspx?action=msgsend&user=本站用户名&mobile=手机号码&content=短信内容&time=发送时间&msgid=批次ID&hashcode=校验码';
echo Get($url);
function Get($url)
{
if(function_exists('file_get_contents'))
{
$file_contents = file_get_contents($url);
}
else
{
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
}
return $file_contents;
}
        

VB.NET程序实例

'调用发送短信,NoList接收号码.多个之间用,分开,Memo内容67字
Public Function SendSMS(ByVal NoList As String, ByVal Memo As String) As String 
Dim Url As String = "http://18dx.cn/API/Services.aspx?action=msgsend&user=本站用户名&mobile=手机号码&content=短信内容&time=发送时间&msgid=批次ID&hashcode=校验码"
Dim webClient As New Net.WebClient()
Try
'Dim responseData As Byte() = 
Dim srcString As String = webClient.DownloadString(Url)
Return srcString
Catch
Return "-444"
End Try
End Function