个性化短信发送
个性化短信发送
批量提交个性化短信
接口描述
批量提交个性化短信请用post提交
方法名
直接调用
承载协议
HTTP Post
调用地址
http://112.124.24.5/api/IndividualSm.aspx
请求参数
参数名 数据类型 说明
account string 账号
pwd string 密码
Channel string 通道号。获取方式 账号开通后由云信提供问http://yes.itissm.com登录云信平台,进入“发短信”页面,在选择“发送通道”操作中点击下拉列表,可看到您拥有的通道。通道名称前面的阿拉伯数字即为通道号,如下图:

(本示例图所示通道号即为37,仅仅是示例请根据方法查看并使用自己的Channel)

Msg string 短信内容为utf-8编码每条个性化短信以英文|^|分割,号码与短信内容以英文|!|分割
请求示例
例如,需发送如下短信
13800000000 王某某,明天记得要开会【123】
13800000000 张某某,明天记得要开会【123】
13800000000 李某某,明天记得要开会【123】
最终拼接url如下:
http://112.124.24.5/api/IndividualSm.aspx?account=admin1&pwd=123&channel=37&msg=13800000000|!|王某某,明天记得要开会【123】|^|13900000000|!|张某某,明天记得要开会【123】|^|18600000000|!|李某某,明天记得要开会【123】
                                        
返回值类型
string
成功返回值
返回本次提交的批次号(如:2114355899380234221),(或叫序列号、流水号等,提交一次返回一个)
失败返回值

返回带负号的失败代码,代码说明如下

失败状态码 状态码说明
-1 应用程序异常
-3 用户名密码错误或者用户无效
-5 签名不正确(格式为:XXX【签名内容】), 注意:短信内容最后一个字符必须是】
-6:keyWords 含有关键字keyWords(keyWords为敏感内容,如:-6:促销)
-7 余额不足
-8 没有可用的通道,或不在时间范围内
-9 发送号码一次不能超过1000个
-10 号码数量大于允许上限(不设置上限时,不可超过1000)
-11 号码数量小于允许下限
C#代码示例
http请求

        string url="http://112.124.24.5/api/IndividualSm.aspx";

        protected string individualsmByPost() //POST方式请求
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("account=用户名&");
            sb.Append("pwd=密码&");
            sb.Append("Channel=通道号&");
            sb.Append("Msg=手机号|!|短信内容【签名】|^|手机号|!|短信内容【签名】|^|");

            string result = httpPost(url,sb.ToString());

            return result;
        }
        protected string httpPost(string url, string data) //http post请求
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.Method = "POST";
                request.ContentType = "application/x-www-form-urlencoded";
                byte[] info = Encoding.UTF8.GetBytes(data);
                using (Stream stream = request.GetRequestStream())
                {
                    stream.Write(info, 0, info.Length);
                }
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                Stream myResponseStream = response.GetResponseStream();
                StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
                string retString = myStreamReader.ReadToEnd();
                myStreamReader.Close();
                myResponseStream.Close();
                return retString;
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
	                                       


                                    
PHP代码示例
http请求


<?php

$urlsend="http://112.124.24.5/api/IndividualSm.aspx";

$token=array("account"=>"用户名","pwd"=>"密码","channel"="通道号","Msg"="手机号|!|短信内容【签名】|^|手机号|!|短信内容【签名】|^|");

echo http($urlsend,$token,"POST"); //post请求

function http($url,$param,$action="GET"){
	$ch=curl_init();
	$config=array(CURLOPT_RETURNTRANSFER=>true,CURLOPT_URL=>$url);	
	if($action=="POST"){
		$config[CURLOPT_POST]=true;		
	}
	$config[CURLOPT_POSTFIELDS]=http_build_query($param);
	curl_setopt_array($ch,$config);	
	$result=curl_exec($ch);	
	curl_close($ch);
	return $result;
}
?>

                                    
java代码示例
http请求

                                //说明:此处需引用httpclient、httpcore、commons-logging三个jar包

        import java.io.BufferedReader;
        import java.io.IOException;
        import java.io.InputStream;
        import java.io.InputStreamReader;
        import java.util.*;
        import java.security.MessageDigest;
        import org.apache.http.HttpEntity;
        import org.apache.http.HttpResponse;
        import org.apache.http.client.HttpClient;
        import org.apache.http.client.methods.HttpPost;
        import org.apache.http.client.methods.HttpGet;
        import org.apache.http.client.entity.UrlEncodedFormEntity;
        import org.apache.http.impl.client.DefaultHttpClient;
        import org.apache.http.message.BasicNameValuePair;
        import org.apache.http.*;
        import javax.crypto.SecretKey;
        import javax.crypto.spec.DESKeySpec;
        import javax.crypto.spec.IvParameterSpec;
        import javax.crypto.SecretKeyFactory;
        import javax.crypto.Cipher;

        public static void main(String[] args) {
            String url="http://112.124.24.5/api/IndividualSm.aspx";

            List<NameValuePair> nvps = new ArrayList<NameValuePair>();
            nvps.add(new BasicNameValuePair("account", "用户名"));
            nvps.add(new BasicNameValuePair("pwd", "密码"));
            nvps.add(new BasicNameValuePair("Channel", "通道号"));
            nvps.add(new BasicNameValuePair("Msg", "手机号|!|短信内容【签名】|^|手机号|!|短信内容【签名】|^|"));

            String post=httpPost(url,nvps);  //post请求


        }

    public static String httpPost(String url,List<NameValuePair> params) {
            String result = "";
        try {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);            
            httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
            HttpResponse response = httpclient.execute(httpPost);
            HttpEntity entity = response.getEntity();
            if (entity != null) {    
            	 InputStream instreams = entity.getContent();
            	 result = convertStreamToString(instreams);
                 System.out.println(result);
             }
        } catch (Exception e) {
        }
        return result;
    }
    
    public static String convertStreamToString(InputStream is) {      
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));      
        StringBuilder sb = new StringBuilder();      
       
        String line = null;
        try {      
            while ((line = reader.readLine()) != null) {  
                sb.append(line + "\n");      
            }      
        } catch (IOException e) {      
            e.printStackTrace();      
        } finally {
            try {
                is.close();
            } catch (IOException e) {
               e.printStackTrace();
            }
        }
        return sb.toString();
    }                                  

           
                                    
asp代码示例
http请求


<%
dim sendurl,senddata
sendurl="http://112.124.24.5/api/IndividualSm.aspx"
senddata="account=用户名&pwd=密码&Channel=通道号&Msg=手机号|!|短信内容【签名】|^|手机号|!|短信内容【签名】|^|"

Response.Write(HTTPRequest(sendurl,senddata,"POST")) <!-- post请求 -->


function HTTPRequest(url,data,method)
	dim http
	set http=server.createobject("MSXML2.SERVERXMLHTTP.3.0")

	if method = "GET" then
	Http.open "GET",url+"?"+data,false
	elseif method = "POST" then
	Http.open "POST",url,false
	end if

	Http.setRequestHeader "CONTENT-TYPE","application/x-www-form-urlencoded"
	Http.send(data)
	if Http.readystate<>4 then
	exit function
	End if

	HTTPRequest=BytesToStr(Http.responseBody,"utf-8")
	set http=nothing
	if err.number<>0 then err.Clear
End function

Function BytesToStr(body, charset)
    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 = charset
    BytesToStr = objStream.ReadText 
    objStream.Close
    Set objStream = Nothing
End Function

%>