文 档

短信验证码API

返回值说明

代码示例


  • Java
  • ASP
  • ASP.NET(C#)
  • C++
  • PHP

Windows用户请注意:下载的代码及说明文件都是UTF-8格式编码,且换行风格为Linux的。 用记事本或写字板直接打开显示会不正常。建议将其导入(或复制)到Eclipse等IDE, 并将项目编码格式设置为UTF-8后再打开这些文件查看。若直接查看请用Notepad++、EditPlus等编辑器。

功能说明:该接口要求提前在信诺通云通讯后台添加模板,提交短信时,系统会自动匹配审核通过的模板,匹配成功任意一个模板即可发送。系统已提供的默认模板添加签名后可以直接使用。

/* * 文件名:KXTSmsSDK.java * 功能:核心文件 * 版本:1.3 * 说明: * 以下代码只是为了方便客户测试而提供的样例代码,客户可以根据自己网站的需要,按照技术文档自行编写,并非一定要使用该代码。 * 该代码仅供学习和研究使用,只是提供一个参考。 */ package com.kxtsms.sdk; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.URL; import java.net.URLConnection; import java.text.MessageFormat; public class KXTSmsSDK { private String address = null; private int port = 0; private String account = null; private String token = null; /** * 初始化必须参数 * * @param address * 必选参数,服务器地址 不带 http:// * @param port * 必选参数,服务器点端口号 * @param token * 必选参数,API接口密码 * */ public void init(String address, int port, String account, String token) { this.address = address; this.port = port; this.account = account; this.token = token; } /** * 发送短信 * * @param mobile * 手机号码 * @param body * 短信内容 * @param rType * 响应数据类型 0 Json 类型,1 xml 类型 * @return * */ public String send(String mobile, String body, short rType,String extno) { String uriStr = MessageFormat.format("http://{0}:{1}/SMS/Send", address,String.valueOf(port)); return getResponse(uriStr,MessageFormat.format("account={0}&token={1}&mobile={2}&content={3}&responseType={4}&extno={5}",account, token, mobile, body, String.valueOf(rType),extno)); } /** * 获取剩余额度 * * @param rType * 响应数据类型 0 Json 类型,1 xml 类型 * @return * */ public String queryBalance(short rType) { String uriStr = MessageFormat.format("http://{0}:{1}/SMS/QueryBalance",address,String.valueOf(port)); return getResponse(uriStr,MessageFormat.format("account={0}&token={1}&responseType={2}",account, token, String.valueOf(rType))); } /** * 获取状态 * * @param rType * 响应数据类型 0 Json 类型,1 xml 类型 * @return * */ public String queryReport(short rType) { String uriStr = MessageFormat.format("http://{0}:{1}/SMS/QueryReport",address, String.valueOf(port)); return getResponse(uriStr,MessageFormat.format("account={0}&token={1}&responseType={2}",account, token,String.valueOf(rType))); } /** * 获取请求数据 * * @param uriStr * 请求路径 * @param param * 请求参数 * @param rType * 响应数据类型 0 Json 类型,1 xml 类型 * @return * */ private String getResponse(String uriStr, String param) { PrintWriter out = null; BufferedReader in = null; String result = ""; try { URL realUrl = new URL(uriStr); // 打开和URL之间的连接 URLConnection conn = realUrl.openConnection(); // 设置通用的请求属性 conn.setConnectTimeout(50000); conn.setRequestProperty("Accept-Charset", "UTF-8"); conn.setRequestProperty("connection","Keep-Alive"); conn.setRequestProperty("user-agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); // 发送POST请求必须设置如下两行 conn.setDoOutput(true); conn.setDoInput(true); // 获取URLConnection对象对应的输出流 out = new PrintWriter(conn.getOutputStream()); // 发送请求参数 out.print(param); // flush输出流的缓冲 out.flush(); // 定义BufferedReader输入流来读取URL的响应 in = new BufferedReader(new InputStreamReader(conn.getInputStream(),"UTF-8")); String line; while ((line = in.readLine()) != null) { result += line; } } catch (Exception e) { System.out.println("发送 POST 请求出现异常!"+e); e.printStackTrace(); } //使用finally块来关闭输出流、输入流 finally { try { if(out != null){ out.close(); } if(in != null){ in.close(); } } catch (IOException ex){ ex.printStackTrace(); } } return result; } } /* * 文件名:QueryBalanceDemo.java * 功能:获取剩余额度示例 * 版本:1.3 * 说明: * 以下代码只是为了方便客户测试而提供的样例代码,客户可以根据自己网站的需要,按照技术文档自行编写,并非一定要使用该代码。 * 该代码仅供学习和研究使用,只是提供一个参考。 */ package com.kxtsms; import java.util.HashMap; import com.kxtsms.sdk.KXTSmsSDK; public class QueryBalanceDemo { public static void main(String[] args) { String address = "apis.xntdx.com";//远程地址:不带http:// int port = 80;//远程端口 String account = "";//账户 String token = "";//token short rType = 0;//响应类型 0 json类型,1 xml类型 KXTSmsSDK kxtsms = new KXTSmsSDK(); kxtsms.init(address, port, account, token); String result = kxtsms.queryBalance(rType); HashMap hashMap = null; if(rType == 0) { //json hashMap = CommonUtils.jsonToMap(result); } if(rType == 1) { //xml hashMap = CommonUtils.xmlToMap(result); } if(hashMap != null) { //写自己的业务逻辑代码 //hashMap.get("Code"); } } } /* * QueryReportDemo.java * 功能:获取短信状态示例 * 版本:1.3 * 说明: * 以下代码只是为了方便客户测试而提供的样例代码,客户可以根据自己网站的需要,按照技术文档自行编写,并非一定要使用该代码。 * 该代码仅供学习和研究使用,只是提供一个参考。 */ package com.kxtsms; import java.util.HashMap; import com.kxtsms.sdk.KXTSmsSDK; public class QueryReportDemo { public static void main(String[] args) { String address = "apis.xntdx.com";//远程地址:不带http:// int port = 80;//远程端口 String account = "";//账户 String token = "";//token short rType = 1;//响应类型 0 json类型,1 xml类型 KXTSmsSDK kxtsms = new KXTSmsSDK(); kxtsms.init(address, port, account, token); String result = kxtsms.queryReport(rType); HashMap hashMap = null; if(rType == 0) { //json hashMap = CommonUtils.jsonToMap(result); } if(rType == 1) { //xml hashMap = CommonUtils.xmlToMap(result); } if(hashMap != null) { //写自己的业务逻辑代码 //hashMap.get("Code"); } } } /* * 文件名:SMSSendDemo.java * 功能:发送示例 * 版本: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 hashMap = null; if(rType == 0) { //json hashMap = CommonUtils.jsonToMap(result); } if(rType == 1) { //xml hashMap = CommonUtils.xmlToMap(result); } if(hashMap != null) { //写自己的业务逻辑代码 //hashMap.get("Code"); } } }

功能说明:该接口要求提前在信诺通云通讯后台添加模板 , 提交短信时,系统会自动匹配审核通过的模板,匹配成功任意一个模板即可发送。系统已提供的默认模板添加签名后可以直接使用。

<%@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”文档 %>

功能说明:该接口要求提前在信诺通云通讯后台添加模板 , 提交短信时,系统会自动匹配审核通过的模板,匹配成功任意一个模板即可发送。系统已提供的默认模板添加签名后可以直接使用。

/* * 文件名:KXTSms.cs * 功能:核心文件 * 版本: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 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 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类型</param> /// <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; } } } /* * 文件名:QueryReportPage.aspx.cs * 功能:获取短信状态示例 * 版本:1.3 * 说明: * 以下代码只是为了方便客户测试而提供的样例代码,客户可以根据自己网站的需要,按照技术文档自行编写,并非一定要使用该代码。 * 该代码仅供学习和研究使用,只是提供一个参考。 */ using System; using System.Collections.Generic; using System.Xml; namespace KXTDemo.Http { public partial class QueryReportPage : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string address = "apis.xntdx.com";//不带http:// 的域名或者IP地址 int port = 80;//远程端口 string account = "";//账户 string token = "";//token short rType = 1;//返回的数据类型 0 json类型,1 xml类型 KXTSDK.KXTSms kxtsms = new KXTSDK.KXTSms(address, port, account, token); string result = kxtsms.QueryReport(rType); QueryReportResult smsData = null; if (!result.Equals("")) { //处理接收的数据 if (rType == 0) { //Json数据处理代码 try { smsData = (QueryReportResult)Newtonsoft.Json.JsonConvert.DeserializeObject(result, typeof(QueryReportResult));//获得用户数据 } catch (Exception ex) { } } else { //xml数据处理代码 try { smsData = new QueryReportResult(); XmlDocument resultXml = new XmlDocument(); resultXml.LoadXml(result); XmlNodeList nodeList = resultXml.SelectSingleNode("Response").ChildNodes; foreach (XmlNode item in nodeList) { if (item.Name == "Code") { smsData.Code = item.InnerText; } else if (item.Name == "DataList") { smsData.DataList = new List<ReportModel>(); XmlNodeList pnList = item.ChildNodes; foreach (XmlNode cnItem in pnList) { smsData.DataList.Add(new ReportModel { Data = cnItem.InnerText }); } } } } catch (Exception ex) { } } } if (smsData != null) { //写自己的业务逻辑代码 } } } /// <summary> /// 返回结果数据模型 /// </summary> public class QueryReportResult { /// <summary> /// 状态码 /// </summary> public string Code { get; set; } /// <summary> /// 数据列表 /// </summary> public List<ReportModel> DataList { get; set; } } public class ReportModel { /// <summary> /// 数据 /// </summary> public string Data { get; set; } } } /* * 文件名:QueryBalancePage.aspx.cs * 功能:获取剩余条数示例 * 版本:1.3 * 说明: * 以下代码只是为了方便客户测试而提供的样例代码,客户可以根据自己网站的需要,按照技术文档自行编写,并非一定要使用该代码。 * 该代码仅供学习和研究使用,只是提供一个参考。 */ using System; using System.Xml; namespace KXTDemo.Http { public partial class QueryBalancePage : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string address = "apis.xntdx.com";//不带http:// 的域名或者IP地址 int port = 80;//远程端口 string account = "";//账户 string token = "";//token short rType = 0;//返回的数据类型 0 json类型,1 xml类型 KXTSDK.KXTSms kxtsms = new KXTSDK.KXTSms(address, port, account, token); string result = kxtsms.QueryBalance(rType); QueryBalanceResult smsData = null; if (!result.Equals("")) { //处理接收的数据 if (rType == 0) { //Json数据处理代码 try { smsData = (QueryBalanceResult)Newtonsoft.Json.JsonConvert.DeserializeObject(result, typeof(QueryBalanceResult));//获得用户数据 } catch (Exception ex) { } } else { //xml数据处理代码 try { smsData = new QueryBalanceResult(); XmlDocument resultXml = new XmlDocument(); resultXml.LoadXml(result); XmlNodeList nodeList = resultXml.SelectSingleNode("Response").ChildNodes; foreach (XmlNode item in nodeList) { if (item.Name == "Code") { smsData.Code = item.InnerText; } else if (item.Name == "Count") { smsData.Count = int.Parse(item.InnerText); } } } catch (Exception ex) { } } } if (smsData != null) { //写自己的业务逻辑代码 } } /// <summary> /// 返回结果数据模型 /// </summary> public class QueryBalanceResult { public string Code { get; set; } public int Count { get; set; } } } } /* * 文件名:SMSSendPage.aspx.cs * 功能:核心文件 * 版本: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; } } }

功能说明:该接口要求提前在信诺通云通讯后台添加模板 , 提交短信时,系统会自动匹配审核通过的模板,匹配成功任意一个模板即可发送。系统已提供的默认模板添加签名后可以直接使用。

//头文件 #include <iostream> #include <string> #include <Winsock2.h> using namespace std; //函数声明 int request(char* hostname, char* api, char* parameters); //方法调用 int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; // initialize MFC and print and error on failure if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // TODO: change error code to suit your needs _tprintf(_T("Fatal Error: MFC initialization failed\n")); return 1; } request("apis.xntdx.com", "http://apis.xntdx.com/SMS/Send", "account=&token=&mobile=&content=【宸诺通】您的验证码为:5748851,如非本人操作,请忽略。"); return nRetCode; } //函数实现 int request(char* hostname, char* api, char* parameters) { WSADATA WsaData; WSAStartup(0x0101, &WsaData); //初始化socket struct hostent* host_addr = gethostbyname(hostname); if (host_addr == NULL) { cout<<"Unable to locate host"<<endl; return -103; } sockaddr_in sin; sin.sin_family = AF_INET; sin.sin_port = htons((unsigned short)80); sin.sin_addr.s_addr = *((int*)*host_addr->h_addr_list); int sock = socket(AF_INET, SOCK_STREAM, 0); if (sock == -1) { return -100; } //建立连接 if (connect(sock, (const struct sockaddr *)&sin, sizeof(sockaddr_in) ) == -1) { cout<<"connect failed"<<endl; return -101; } //初始化发送信息 char send_str[2048] = {0}; //头信息 strcat(send_str, "POST "); strcat(send_str, api); strcat(send_str, " HTTP/1.1\r\n"); strcat(send_str, "Host: "); strcat(send_str, hostname); strcat(send_str, "\r\n"); strcat(send_str, "Connection: keep-alive\r\n"); char content_header[100]; sprintf(content_header,"Content-Length: %d\r\n", strlen(parameters)); strcat(send_str, content_header); strcat(send_str, "Cache-Control: max-age=0\r\n"); strcat(send_str, "Origin: http://www.hao123.com\r\n"); strcat(send_str, "User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/15.0.849.0 Safari/535.1\r\n"); strcat(send_str, "Content-Type: application/x-www-form-urlencoded\r\n"); strcat(send_str, "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"); strcat(send_str, "Referer: http://www.hao123.com/\r\n"); strcat(send_str, "Accept-Encoding: gzip,deflate,sdch\r\n"); strcat(send_str, "Accept-Language: zh-CN,zh;q=0.8\r\n"); //内容信息 strcat(send_str, "\r\n"); strcat(send_str, parameters); if (send(sock, send_str, strlen(send_str),0) == -1) { cout<<"send failed"<<endl; return -101; } //获取返回信息 char recv_str[4096] = {0}; if (recv(sock, recv_str, sizeof(recv_str), 0) == -1) { cout<<"recv failed"<<endl; return -101; } cout<<recv_str<<endl; WSACleanup( ); return 0; }

功能说明:该接口要求提前在信诺通云通讯后台添加模板 , 提交短信时,系统会自动匹配审核通过的模板,匹配成功任意一个模板即可发送。系统已提供的默认模板添加签名后可以直接使用。

<?php /* * 文件名: KXTSmsSDK.php * 功能:SDK核心文件 * 版本:1.3 * 说明: * 以下代码只是为了方便客户测试而提供的样例代码,客户可以根据自己网站的需要,按照技术文档自行编写,并非一定要使用该代码。 * 该代码仅供学习和研究使用,只是提供一个参考。 */ class KXTSmsSDK{ private $Address; private $Port; private $Account; private $Token; function __construct($Address,$Port,$Account,$Token){ $this->Address = $Address; $this->Port = $Port; $this->Account = $Account; $this->Token = $Token; } /** * 发起HTTP请求 */ function curl_post($url,$data,$header,$post=1) { //初始化curl $ch = curl_init(); //参数设置 $res= curl_setopt($ch, CURLOPT_URL,$url);//请求地址 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);//不验证host curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);//不验证证书 curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 50); curl_setopt($ch, CURLOPT_POST, $post);//请求方式 if($post){ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//post数据 } curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch,CURLOPT_HTTPHEADER,$header);//设置头信息 $result = curl_exec ($ch); //连接失败 if($result == FALSE){ $result = ""; } curl_close($ch); return $result; } /** * 发送短信 * @param mobile 手机号码 * @param body 内容 * @param rType 响应数据类型 0 Json 类型,1 xml 类型 */ function send($mobile, $body,$rType,$extno) { // 生成请求 $body = urlencode($body);//url编码 $url = "http://$this->Address:$this->Port/SMS/Send"; $data = "account=$this->Account&token=$this->Token&mobile=$mobile&content=$body&responseType=$rType&extno=$extno"; // 生成包头 $header = array("charset=utf-8"); // 发送请求 return $this->curl_post($url,$data,$header,1); } /** * 获取短信状态 * @param rType 响应数据类型 0 Json 类型,1 xml 类型 */ function queryReport($rType) { // 生成请求 $url = "http://$this->Address:$this->Port/SMS/QueryReport"; $data = "account=$this->Account&token=$this->Token&responseType=$rType"; // 生成包头 $header = array("charset=utf-8"); // 发送请求 return $this->curl_post($url,$data,$header,1); } /** * 获取剩余可发短信条数 * @param rType 响应数据类型 0 Json 类型,1 xml 类型 */ function queryBalance($rType) { // 生成请求 $url = "http://$this->Address:$this->Port/SMS/QueryBalance"; $data = "account=$this->Account&token=$this->Token&responseType=$rType"; // 生成包头 $header = array("charset=utf-8"); // 发送请求 return $this->curl_post($url,$data,$header,1); } } ?> <?php /* * 文件名: QueryBalanceDemo.php * 功能:获取剩余条数示例 * 版本:1.3 * 说明: * 以下代码只是为了方便客户测试而提供的样例代码,客户可以根据自己网站的需要,按照技术文档自行编写,并非一定要使用该代码。 * 该代码仅供学习和研究使用,只是提供一个参考。 */ include_once("./KXTSmsSDK.php"); $Address = "apis.xntdx.com";//IP地址 不加http:// $Port = "80";//端口 $Account = "";//账户 $Token = "";//API接口密码 /** * 获取剩余可发短信条数 * 响应类型 0 json类型,1 xml类型 */ function queryBalance($rType) { global $Address,$Port,$Account,$Token; //初始化SDK $rest = new KXTSmsSDK($Address,$Port,$Account,$Token); // 发送短信 $result = $rest->queryBalance($rType); if($result == NULL ) { echo "result error!"; break; } //自己代码业务逻辑 } //调用 queryBalance(1); ?> <?php /* * 文件名: QueryReportDemo.php * 功能:获取短信状态示例 * 版本:1.3 * 说明: * 以下代码只是为了方便客户测试而提供的样例代码,客户可以根据自己网站的需要,按照技术文档自行编写,并非一定要使用该代码。 * 该代码仅供学习和研究使用,只是提供一个参考。 */ include_once("./KXTSmsSDK.php"); $Address = "apis.xntdx.com";//IP地址 不加http:// $Port = "80";//端口 $Account = "";//账户 $Token = "";//API接口密码 /** * 获取短信发送状态 * 响应类型 0 json类型,1 xml类型 */ function queryReport($rType) { global $Address,$Port,$Account,$Token; //初始化SDK $rest = new KXTSmsSDK($Address,$Port,$Account,$Token); $result = $rest->queryReport($rType); if($result == NULL ) { echo "result error!"; break; } //自己代码业务逻辑 } //调用 queryReport(1); ?> <?php /* * 文件名:SMSSendDemo.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,""); ?>

我要贡献代码

为方便广大开发者更快、更好的使用信诺通云通讯的短信服务,信诺通云通讯推出开发者激励计划,鼓励开发者贡献信诺通云通讯API的接入代码,同时自己也能获得优惠。

一、代码贡献原则:

1、正确运行

2、包含测试CASE

3、不与官方和其他开发者提交的代码雷同

二、代码贡献的流程:

1、联系信诺通云通讯客服/技术人员。

2、等待信诺通云通讯技术人员审核。

三、激励计划:(根据您的贡献大小我们可提供以下三种不同等级的奖励)

1、一次获得信诺通云通讯赠送的短信1000条

2、价格优惠,按你的发送量申请定制价格

3、收入分成,如果你的代码被多次使用,可以申请收入分成