请求地址
URL地址为:http://apis.xntdx.com/SMS/Send
请求参数定义
序号 | 参数 | 说明 |
---|---|---|
1 | account | 必填参数, 接口Account值。 |
2 | token | 必填参数,接口Token值 。 |
3 | mobile | 必填参数,手机号码,多个用英文逗号(,)分割,一次最多支持2500个号码。 |
4 | content | 必填参数,短信内容,使用URL方式编码为UTF-8格式,短信内容不能超过450个字。 |
5 | responseType | 可选参数,需要返回的数据格式,默认为xml。0返回json格式,1返回xml格式 |
示例
http://apis.xntdx.com/SMS/Send?account=test&token=test&mobile=13800000000,13800000000&content=【宸诺通】您的验证码为:65544,如非本人操作,请忽略。&responseType=1
返回参数说明
序号 | 参数 | 说明 |
---|---|---|
1 | code | 状态值 |
2 | Message | 描述 |
3 | TaskId | 任务id,数据提交后返回的批次id |
返回结果示例
JSON格式
{"Code":"0","Message":"提交成功","TaskId":"11"}
XML数据格式
<?xml version="1.0" encoding="utf-8"?>
<Response>
<Code>0</Code>
<Message>提交成功</Message>
<TaskId >11</TaskId >
</Response>
下载开发文档,并配置。
开发文档下载地址(JAVA/ASP.NET(C#)/ASP/PHP:去下载
示例
- Java
- ASP.NET(C#)
- ASP
- PHP
/*
* 功能:发送示例
* 版本:1.3
* 说明:
* 以下代码只是为了方便客户测试而提供的样例代码,客户可以根据自己网站的需要,按照技术文档自行编写,并非一定要使用该代码。
* 该代码仅供学习和研究使用,只是提供一个参考。
*/
package com.kxtsms;
import java.net.URLEncoder;
import java.util.HashMap;
import com.kxtsms.sdk.*;
public class SMSSendDemo {
public static void main(String[] args) {
String address = "apis.xntdx.com";//远程地址:不带http://
int port = 80;//远程端口
String account = "";//账户
String token = "";//token
String mobile = "";//发送手机号
String body = "【宸诺通】您的验证码为:88888,如非本人操作,请忽略。";//短信内容
short rType = 0;//响应类型 0 json类型,1 xml类型
String extno = "";//扩展号 可选
KXTSmsSDK kxtsms = new KXTSmsSDK();
kxtsms.init(address, port, account, token);
try
{
body = URLEncoder.encode(body,"UTF-8");//URL编码 UTF-8方式
}
catch (Exception e) {
}
String result = kxtsms.send(mobile,body,rType,extno);
HashMap
/*
* 功能:核心文件
* 版本:1.3
* 说明:
* 以下代码只是为了方便客户测试而提供的样例代码,客户可以根据自己网站的需要,按照技术文档自行编写,并非一定要使用该代码。
* 该代码仅供学习和研究使用,只是提供一个参考。
*/
using System;
using System.IO;
using System.Net;
using System.Text;
namespace KXTSDK
{
/// <summary>
///
/// </summary>
public class KXTSms
{
private string address = null;
private int port = 0;
private string account = null;
private string token = null;
/// <summary>
///
/// </summary>
/// <param name="address">远程地址:域名或者IP,不带http://</param>
/// <param name="port">端口</param>
/// <param name="account">账户</param>
/// <param name="token">api接口密码</param>
public KXTSms(string address, int port, string account, string token)
{
this.address = address;
this.port = port;
this.account = account;
this.token = token;
}
/// <summary>
/// 发送短信
/// </summary>
/// <param name="mobile">号码</param>
/// <param name="body">短信内容</param>
/// <param name="rType">返回数据类型 0 json类型,1 xml类型</param>
/// <returns></returns>
public string Send(string mobile, string body, short rType,string extno)
{
string uriStr = string.Format("http://{0}:{1}/SMS/Send", address, port);
return GetResponse(uriStr, string.Format("account={0}&token={1}&mobile={2}&content={3}&responseType={4}&extno={5}", account, token, mobile, body, rType, extno), Encoding.UTF8, 50000);
}
/// <summary>
/// 获取剩余可发短信条数
/// </summary>
/// <param name="rType">返回数据类型 0 json类型,1 xml类型</param>
/// <returns></returns>
public string QueryBalance(short rType)
{
string uriStr = string.Format("http://{0}:{1}/SMS/QueryBalance", address, port);
return GetResponse(uriStr, string.Format("account={0}&token={1}&responseType={2}", account, token, rType), Encoding.UTF8, 50000);
}
/// <summary>
/// 获得短信发送状态
/// </summary>
/// <param name="rType">返回数据类型 0 json类型,1 xml类型
/// <returns></returns>
public string QueryReport(short rType)
{
string uriStr = string.Format("http://{0}:{1}/SMS/QueryReport", address, port);
return GetResponse(uriStr, string.Format("account={0}&token={1}&responseType={2}", account, token, rType), Encoding.UTF8, 50000);
}
/// <summary>
/// 获得短信回复数据
/// </summary>
/// <param name="rType">返回数据类型 0 json类型,1 xml类型</param>
/// <returns></returns>
public string QueryMo()
{
string uriStr = string.Format("http://{0}:{1}/SMS/QueryMo", address, port);
return GetResponse(uriStr, string.Format("account={0}&token={1}", account, token), Encoding.UTF8, 50000);
}
/// <summary>
/// 获得网页请求
/// </summary>
/// <param name="postUrl"></param>
/// <param name="paramData">参数</param>
/// <returns></returns>
private string GetResponse(string postUrl, string paramData, Encoding encoding, int timeOut = 50000)
{
string result = string.Empty;
WebResponse wResponse = null;
Stream stream = null;
StreamReader reader = null;
try
{
Uri uri = new Uri(postUrl);
byte[] byteArray = encoding.GetBytes(paramData); //转化
HttpWebRequest wRequest = (HttpWebRequest)WebRequest.Create(uri);
wRequest.Method = "POST";
wRequest.ContentType = "application/x-www-form-urlencoded";
wRequest.ContentLength = byteArray.Length;
wRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36";
wRequest.Timeout = timeOut;
stream = wRequest.GetRequestStream();
stream.Write(byteArray, 0, byteArray.Length);//写入参数
wResponse = (HttpWebResponse)wRequest.GetResponse();
reader = new StreamReader(wResponse.GetResponseStream(), encoding);
result = reader.ReadToEnd();
}
catch (Exception e)
{
}
finally
{
if (wResponse != null)
{
wResponse.Close();
}
if (stream != null)
{
stream.Close();
}
if (reader != null)
{
reader.Close();
}
}
return result;
}
}
}
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Function Post(url,data)
dim Https
set Https=server.createobject("MSXML2.XMLHTTP")
Https.open "POST",url,false
Https.setRequestHeader "Content-Type","application/x-www-form-urlencoded"
Https.send data
if Https.readystate=4 then
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write Https.responseBody
objstream.Position = 0
objstream.Type = 2
objstream.Charset = "utf-8"
Post = objstream.ReadText
objstream.Close
set objstream = nothing
set https=nothing
end if
End Function
dim target,post_data
target = "http://apis.xntdx.com/SMS/Send"
post_data = "account=对应的Account&token=对应的Token&mobile=手机号码&content="&Server.URLEncode("【宸诺通】您的验证码为:88888,如非本人操作,请忽略。")
response.Write(Post(target,post_data))
''//请自己解析Post(target,post_data)返回的字符串并实现自己的逻辑
''参数及返回值说明请参考“短信接口文档(HTTP).doc”文档
%>
<?php
/*
* 功能:短信发送示例
* 版本:1.3
* 说明:
* 以下代码只是为了方便客户测试而提供的样例代码,客户可以根据自己网站的需要,按照技术文档自行编写,并非一定要使用该代码。
* 该代码仅供学习和研究使用,只是提供一个参考。
*/
include_once("./KXTSmsSDK.php");
$Address = "apis.xntdx.com";//IP地址 不加http://
$Port = "80";//端口
$Account = "";//账户
$Token = "";//token
/**
* 发送短信
* 发送合法的手机号
* 短信内容
* 响应类型 0 json类型,1 xml类型
* $extno ="";//扩展号 可选
*/
function sendSMS($mobile,$body,$rType,$extno)
{
global $Address,$Port,$Account,$Token;
//初始化SDK
$rest = new KXTSmsSDK($Address,$Port,$Account,$Token);
// 发送短信
$result = $rest->send($mobile, $body, $rType,$extno);
if($result == NULL ) {
echo "result error!";
break;
}
//自己代码业务逻辑
echo $result;
}
//调用
sendSMS("13800000000","【宸诺通】您的验证码为:88888,如非本人操作,请忽略。",1,"");
?>
注意事项
提交短信的模板必须通过审核后才能使用,短信的内容必须与模板定义的规则一致才能提交到网关进行短信实际发送。提交的短信内容必须使用URL方式编码为UTF-8格式,否则会出现提交失败或无法请求的情况。