經過通道測試,目前支援大多數國家和地區,下面提供C#和Java兩種程式設計語言的Demo示例。
一、國際短信SDK:
http://sdk2.entinfo.cn:8060/gjWebService.asmx/mdSmsSend_g? sn=string&pwd=string&mobile=string
&content=string&ext=string&stime=string&rrid=string
sn即您注冊時的序列号,pwd需要MD5(SN+pwd)加密,取32位大寫。
示例:
http://sdk2.entinfo.cn:8060/gjWebService.asmx/mdSmsSend_g?sn=SDK-SSD-010-xxxxx&pwd=F561FBB2B012D611B0028EA96272D8B7&mobile=008615321858155&content=test message&ext=&stime=&rrid=
參數名稱 | 說明 | 是否必須 | 備注 |
sn | 軟體序列号 | 是 | 格式XXX-XXX-XXX-XXXXX |
pwd | 密碼 | 是 | md5(sn+password) 32位大寫密文 |
mobile | 手機号 | 是 | 必填(支援1000個手機号,建議<=800)多個英文逗号隔開 |
Content | 内容 | 是 | 支援長短信(詳細請看長短信扣費說明) |
Ext | 擴充碼 | 否 | 例如:123(預設置空) |
stime | 定時時間 | 否 | 例如:2010-12-29 16:27:03(非定時短信置空) |
Rrid | 唯一辨別 | 否 | 最長18位 |
函數傳回值:String(唯一辨別,即目前發送短信批次的唯一辨別,和rrid對應,如為空則傳回系統生成的rrid)
以下是 HTTP POST 請求和響應示例。所顯示的占位符需替換為實際值。
POST /gjWebService.asmx/mdSmsSend_g HTTP/1.1
Host: sdk2.entinfo.cn
Content-Type: application/x-www-form-urlencoded
Content-Length: length
sn=string&pwd=string&mobile=string&content=string&ext=string&stime=string&rrid=string
--------------------------------------
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">string</string>
二、PHP國際短信示例代碼
<?PHP
//改demo的功能是群發短信和發單條短信。(傳一個手機号就是發單條,多個手機号既是群發)
//您把序列号和密碼還有手機号,填上,直接運作就可以了
//如果您的系統是utf-8,請轉成GB2312 後,再送出、
//請參考 'content'=>iconv( "UTF-8", "gb2312//IGNORE" ,$content),//短信内容
$flag = 0;
//要post的資料
$argv = array(
'sn'=>'SDK-SSD-010-XXXXX', 替換成您自己的序列号
'pwd'=>strtoupper(md5('SDK-SSD-010-XXXXX'.'11111111')), //此處密碼需要加密 加密方式為 md5(sn+password) 32位大寫
'mobile'=>'008613718331021',//手機号 多個用英文的逗号隔開 post理論沒有長度限制.推薦群發一次小于等于10000個手機号
'content'=>'您好測試國際短信[簽名]',//短信内容
'ext'=>'',
'rrid'=>'',//預設空 如果空傳回系統生成的辨別串 如果傳值保證值唯一 成功則傳回傳入的值
'stime'=>''//定時時間 格式為2011-6-29 11:09:21
);
//構造要post的字元串
foreach ($argv as $key=>$value) {
if ($flag!=0) {
$params .= "&";
$flag = 1;
}
$params.= $key."="; $params.= urlencode($value);
$flag = 1;
}
$length = strlen($params);
//建立socket連接配接
$fp = fsockopen("sdk2.entinfo.cn",8060,$errno,$errstr,10) or exit($errstr."--->".$errno);
//構造post請求的頭
$header = "POST /gjwebservice.asmx/mdSmsSend_g HTTP/1.1\r\n";
$header .= "Host:sdk2.entinfo.cn\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: ".$length."\r\n";
$header .= "Connection: Close\r\n\r\n";
//添加post的字元串
$header .= $params."\r\n";
//發送post的資料
fputs($fp,$header);
$inheader = 1;
while (!feof($fp)) {
$line = fgets($fp,1024); //去除請求包的頭隻顯示頁面的傳回資料
if ($inheader && ($line == "\n" || $line == "\r\n")) {
$inheader = 0;
}
if ($inheader == 0) {
// echo $line;
}
}
//<string xmlns="http://tempuri.org/">-5</string>
$line=str_replace("<string xmlns=\"http://tempuri.org/\">","",$line);
$line=str_replace("</string>","",$line);
$result=explode("-",$line);
if(count($result)>1)
echo '發送失敗傳回值為:'.$line;
else
echo '發送成功 傳回值為:'.$line;
?>
三、C#國際短信示例代碼
1.配置檔案app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="國際短信.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<國際短信.Properties.Settings>
<setting name="國際短信_GlobalMessage_gjWebService" serializeAs="String">
<value>http://sdk2.entinfo.cn:8060/gjWebService.asmx</value>
</setting>
</國際短信.Properties.Settings>
</applicationSettings>
</configuration>
2.GlobalMessage
//------------------------------------------------------------------------------
// <auto-generated>
// 此代碼由工具生成。
// 運作時版本:4.0.30319.1
//
// 對此檔案的更改可能會導緻不正确的行為,并且如果
// 重新生成代碼,這些更改将會丢失。
// </auto-generated>
//------------------------------------------------------------------------------
//
// 此源代碼是由 Microsoft.VSDesigner 4.0.30319.1 版自動生成。
//
#pragma warning disable 1591
namespace 國際短信.GlobalMessage {
using System;
using System.Web.Services;
using System.Diagnostics;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Xml.Serialization;
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "4.0.30319.1")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="gjWebServiceSoap", Namespace="http://tempuri.org/")]
public partial class gjWebService : System.Web.Services.Protocols.SoapHttpClientProtocol {
private System.Threading.SendOrPostCallback mdSmsSend_gOperationCompleted;
private bool useDefaultCredentialsSetExplicitly;
/// <remarks/>
public gjWebService() {
this.Url = global::國際短信.Properties.Settings.Default.國際短信_GlobalMessage_gjWebService;
if ((this.IsLocalFileSystemWebService(this.Url) == true)) {
this.UseDefaultCredentials = true;
this.useDefaultCredentialsSetExplicitly = false;
}
else {
this.useDefaultCredentialsSetExplicitly = true;
}
}
public new string Url {
get {
return base.Url;
}
set {
if ((((this.IsLocalFileSystemWebService(base.Url) == true)
&& (this.useDefaultCredentialsSetExplicitly == false))
&& (this.IsLocalFileSystemWebService(value) == false))) {
base.UseDefaultCredentials = false;
}
base.Url = value;
}
}
public new bool UseDefaultCredentials {
get {
return base.UseDefaultCredentials;
}
set {
base.UseDefaultCredentials = value;
this.useDefaultCredentialsSetExplicitly = true;
}
}
/// <remarks/>
public event mdSmsSend_gCompletedEventHandler mdSmsSend_gCompleted;
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/mdSmsSend_g", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public string mdSmsSend_g(string sn, string pwd, string mobile, string content, string ext, string stime, string rrid) {
object[] results = this.Invoke("mdSmsSend_g", new object[] {
sn,
pwd,
mobile,
content,
ext,
stime,
rrid});
return ((string)(results[0]));
}
/// <remarks/>
public void mdSmsSend_gAsync(string sn, string pwd, string mobile, string content, string ext, string stime, string rrid) {
this.mdSmsSend_gAsync(sn, pwd, mobile, content, ext, stime, rrid, null);
}
/// <remarks/>
public void mdSmsSend_gAsync(string sn, string pwd, string mobile, string content, string ext, string stime, string rrid, object userState) {
if ((this.mdSmsSend_gOperationCompleted == null)) {
this.mdSmsSend_gOperationCompleted = new System.Threading.SendOrPostCallback(this.OnmdSmsSend_gOperationCompleted);
}
this.InvokeAsync("mdSmsSend_g", new object[] {
sn,
pwd,
mobile,
content,
ext,
stime,
rrid}, this.mdSmsSend_gOperationCompleted, userState);
}
private void OnmdSmsSend_gOperationCompleted(object arg) {
if ((this.mdSmsSend_gCompleted != null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.mdSmsSend_gCompleted(this, new mdSmsSend_gCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
}
}
/// <remarks/>
public new void CancelAsync(object userState) {
base.CancelAsync(userState);
}
private bool IsLocalFileSystemWebService(string url) {
if (((url == null)
|| (url == string.Empty))) {
return false;
}
System.Uri wsUri = new System.Uri(url);
if (((wsUri.Port >= 1024)
&& (string.Compare(wsUri.Host, "localHost", System.StringComparison.OrdinalIgnoreCase) == 0))) {
return true;
}
return false;
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "4.0.30319.1")]
public delegate void mdSmsSend_gCompletedEventHandler(object sender, mdSmsSend_gCompletedEventArgs e);
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Web.Services", "4.0.30319.1")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class mdSmsSend_gCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
private object[] results;
internal mdSmsSend_gCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}
/// <remarks/>
public string Result {
get {
this.RaiseExceptionIfNecessary();
return ((string)(this.results[0]));
}
}
}
}
#pragma warning restore 1591
3.調用GlobalMessage.gjWebService
using System;
using System.Text;
using System.Windows.Forms;
using System.Web.Security;
namespace 國際短信
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox3_Enter(object sender, EventArgs e)
{
if ( Phone.Text == "多個手機号用英文逗号隔開")
{
Phone.Text = "";
}
}
private void Phone_Leave(object sender, EventArgs e)
{
if (Phone.Text == "")
{
Phone.Text = "多個手機号,用英文的逗号隔開";
}
}
private void button1_Click(object sender, EventArgs e)
{
string sn = SN.Text.Trim();
if(sn.Length==0)
{
MessageBox.Show("請填序列号!");
return;
}
string pwd = PWD.Text.Trim();
if (pwd.Length == 0)
{
return;
}
string phone = Phone.Text;
if (phone.Length == 0 || phone == "多個手機号用英文逗号隔開")
{
MessageBox.Show("請填手機号!");
return;
}
GlobalMessage.gjWebService sms = new GlobalMessage.gjWebService();
pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(sn + pwd, "md5");
string result = sms.mdSmsSend_g(sn, pwd, phone, Content.Text, "", "", "");
Content.AppendText("\n發送完畢,傳回值為:" + result);
}
}
}
四、Java國際短信示例代碼
1.Client.java類
package com;
import java.io.*;
import java.net.*;
import java.security.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import java.io.UnsupportedEncodingException;
public class Client {
/*
* webservice伺服器定義
*/
private String serviceURL = "http://sdk2.entinfo.cn:8060/gjWebService.asmx";
private String sn = "";// 序列号
private String password = "";
private String pwd = "";// 密碼
Document document = null;
NodeList allNode = null;
/*
* 構造函數
*/
public Client(String sn, String password)
throws UnsupportedEncodingException {
this.sn = sn;
this.password = password;
this.pwd = this.getMD5(sn + password);
}
/*
* 方法名稱:getMD5 功 能:字元串MD5加密 參 數:待轉換字元串 返 回 值:加密之後字元串
*/
public String getMD5(String sourceStr) throws UnsupportedEncodingException {
String resultStr = "";
try {
byte[] temp = sourceStr.getBytes();
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(temp);
// resultStr = new String(md5.digest());
byte[] b = md5.digest();
for (int i = 0; i < b.length; i++) {
char[] digit = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
'9', 'A', 'B', 'C', 'D', 'E', 'F' };
char[] ob = new char[2];
ob[0] = digit[(b[i] >>> 4) & 0X0F];
ob[1] = digit[b[i] & 0X0F];
resultStr += new String(ob);
}
return resultStr;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
}
/*
* 方法名稱:mdSmsSend_g 功 能:發送短信 參
* 數:mobile,content,ext,stime,rrid(手機号,内容,擴充碼,定時時間,唯一辨別) 返 回
* 值:唯一辨別,如果不填寫rrid将傳回系統生成的
*/
public String mdSmsSend_g(String mobile, String content, String ext, String stime,
String rrid) {
String result = "";
String soapAction = "http://tempuri.org/mdSmsSend_g";
String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
xml += "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">";
xml += "<soap:Body>";
xml += "<mdSmsSend_g xmlns=\"http://tempuri.org/\">";
xml += "<sn>" + sn + "</sn>";
xml += "<pwd>" + pwd + "</pwd>";
xml += "<mobile>" + mobile + "</mobile>";
xml += "<content>" + content + "</content>";
xml += "<ext>" + ext + "</ext>";
xml += "<stime>" + stime + "</stime>";
xml += "<rrid>" + rrid + "</rrid>";
xml += "</mdSmsSend_g>";
xml += "</soap:Body>";
xml += "</soap:Envelope>";
URL url;
try {
url = new URL(serviceURL);
URLConnection connection = url.openConnection();
HttpURLConnection httpconn = (HttpURLConnection) connection;
ByteArrayOutputStream bout = new ByteArrayOutputStream();
bout.write(xml.getBytes());
byte[] b = bout.toByteArray();
httpconn.setRequestProperty("Content-Length", String
.valueOf(b.length));
httpconn.setRequestProperty("Content-Type",
"text/xml; charset=gb2312");
httpconn.setRequestProperty("SOAPAction", soapAction);
httpconn.setRequestMethod("POST");
httpconn.setDoInput(true);
httpconn.setDoOutput(true);
OutputStream out = httpconn.getOutputStream();
out.write(b);
out.close();
InputStreamReader isr = new InputStreamReader(httpconn
.getInputStream());
BufferedReader in = new BufferedReader(isr);
String inputLine;
while (null != (inputLine = in.readLine())) {
Pattern pattern = Pattern
.compile("<mdSmsSend_gResult>(.*)</mdSmsSend_gResult>");
Matcher matcher = pattern.matcher(inputLine);
while (matcher.find()) {
result = matcher.group(1);
}
}
return result;
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
}
2.發送調用
package com;
public class Demo_Client {
public static void main(String[] args) throws Exception {
String sn = "SDK-SSD-010-";// 請替換為自己的序列号和密碼
String pwd = "XXXXX";// 替換自己的密碼
Client client = new Client(sn, pwd);
String result_send = client.mdSmsSend_g("0010XXXXXXX", "您的信件已經寄出[雷雨科技]", "",
"", "");
if (!result_send.startsWith("-") && !result_send.equals("")) {
System.out.println("發送成功,傳回值為:" + result_send);
} else {
System.out.println("發送失敗,傳回值為:" + result_send);
}
}
}
五、webservice傳回值(XML格式的字元串)
傳回值 | 傳回值說明 | 問題描述 |
-1 | 重複注冊 | 多次點選“注冊”按鈕或注冊方法(Register)的“調用”按鈕 |
-2 | 帳号/密碼不正确 | 1.序列号未注冊2.密碼加密不正确3.密碼已被修改4.序列号已登出 |
-4 | 餘額不足支援本次發送 | 直接調用查詢看是否餘額為0或不足 |
-5 | 資料格式錯誤 | 隻能自行調試了。或與技術支援聯系 |
-6 | 參數有誤 | 看參數傳的是否均正常,請調試程式檢視各參數 |
-9 | 擴充碼權限錯誤 | 該序列号是否已經開通了擴充子号的權限,把ext這個參數置空。 |
-10 | 内容長度長 | 短信内容過長,純單位元組不能超過1000個,雙位元組不能超過500個字元2.彩信不得超過50KB |
-12 | 序列号狀态錯誤 | 序列号是否被禁用 |
-14 | 伺服器寫檔案失敗 | |
-18 | 上次送出沒有等待傳回不能繼續送出 | 預設不支援多線程 |
-19 | 禁止同時使用多個接口位址 | 每個序列号送出隻能使用一個接口位址 |
-20 | 相同手機号,相同内容重複送出 | |
-22 | Ip鑒權失敗 | 送出的IP不是所綁定的IP |
注:以上傳回值針對個别方法.請具體參看每個用到方法的詳細說明。
六、附加說明:
1. 禁止相同的内容多個手機号連續一條一條送出. 否則禁用帳号,由此帶來損失由客戶自行負責.我們推薦客戶能群發就群發
2.所有帳号送出短信,必須等上一批送出傳回後再送出下一批(預設不支援多線程并發)
3.一次送出内容建議不要超過140字元,超過70個字元此時出現長短信的概念.
如果一次送出小于等于70字元 系統會預設為一條短信發出 扣費12條
如果大于70字元 系統會預設為長短信處理 此時根據長短信前邊會加(1/2) 或者(2/2)的标志 此時扣費按67字元扣12條。純單位元組是160字元以内12條,超過160個字元後,按普通長短信收費,即67個字元每12條收費。
4. 請客戶提供外網伺服器IP以便于綁定IP發送,提高賬号的安全性!
5.各個發短信的方法,都沒有資料合法性的驗證。請您在送出之前,做好此項工作,以避免不必要的扣費。
6.同一批次裡,相同的手機号,隻會收到一條短信
7.,請填寫完整的手機資訊:“國際區碼+城市地區代号+手機号碼” 填寫國際手機号碼的時候,手機号碼前必須填寫“00”
如:以德國手機舉例:國際區碼:49,地區區碼:0179,手機号碼:1234567
填寫的正确格式為:00491791234567
8.給大陸手機号發短信,建議走普通接口
位址:http://sdk2.entinfo.cn:8060/gjWebService.asmx
這些位址都是标準的webservice位址,C#,Java客戶可以按照自己熟悉的方式去解析
或者
位址:http://sdk2.entinfo.cn:8060/gjWebService.asmx?wsdl
七、示例Demo源代碼下載下傳:
DEMO(PHP版本) DEMO(C#版本) DEMO(Java版本) SDK通用版接口文檔 所有下載下傳