高速触发接口模板语音验证码
模板语音验证码
发送一段语音验证码到手机,与“语音验证码”的区别是此接口可以选择一个模板生成语音。
接口描述
发送语音验证码
方法名
SendVoiceCodeWithTemplate
承载协议
HTTP Get/Post
调用地址
http://120.55.197.77:1210/Services/MsgSend.asmx
请求参数
参数名 数据类型 说明
userCode string 登录名称
userPass string 登录密码
DesNo string 手机号码每次只能提交1个号码
VoiceCode string 验证码(只能是数字,长度1-6位)。
Amount string 播放次数(1-3)
TemplateID string

模板语音发送(1-6):

男声版“您的校验码”

女声版“您的校验码”

男声版“您的验证码”

女声版“您的验证码”

男声版“您的注册码”

女声版“您的注册码”

任选其中一种版本即可

返回值类型
string
成功返回值
返回本次提交的批次号(如:2114355899380234221),(或叫序列号、流水号等,提交一次返回一个)
失败返回值

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

失败状态码 状态码说明
-1 应用程序异常
-3 用户名密码错误或者用户无效
-4 短信内容和备案的模板不一样
-5 签名不正确(格式为:XXX【签名内容】), 注意:短信内容最后一个字符必须是】
-7 余额不足
-8 通道错误
-9 无效号码
-10 签名内容不符合长度
-11 用户有效期过期
-12 黑名单
-13 语音验证码的Amount参数必须是整形字符串
-14 语音验证码的内容只能为数字
-15 语音验证码的内容最长为6位
-16 余额请求过于频繁,5秒才能取余额一次
-17 非法IP
-18 Msg格式错误
-19 短信数量错误,小于1或者大于50
-20 号码错误或者黑名单
-21 没有找到对应的SubmitID设置
-23 解密失败
C#代码示例
http请求

    
          string url="http://120.55.197.77:1210/Services/MsgSend.asmx";

        protected string sendvoicewithtemplateByPost() //POST方式请求
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("userCode=用户名&");
            sb.Append("userPass=密码&");
            sb.Append("DesNo=手机号&");
            sb.Append("VoiceCode=验证码&");
            sb.Append("Amount=播放次数&");
            sb.Append("TemplateID=模板ID");
            string result = httpPost(url + "/SendVoiceCodeWithTemplate", sb.ToString());
            return result;
        }

        protected string sendvoicewithtemplateByGet() //Get方式请求
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("userCode=用户名&");
            sb.Append("userPass=密码&");
            sb.Append("DesNo=手机号&");
            sb.Append("VoiceCode=验证码&");
            sb.Append("Amount=播放次数&");
            sb.Append("TemplateID=模板ID");
            string result = httpGet(url + "/SendVoiceCodeWithTemplate", sb.ToString());
            return result;
        }

        protected string httpGet(string url, string data) //http get请求
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url + "?" + data);
                request.Method = "GET";
                request.ContentType = "text/html;charset=UTF-8";
                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;
            }
        }
        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;
            }
        }
		
                                    
webservice请求

       private void sendvoicewithtemplate()
        {
            TopenServiceReference.MsgSendSoapClient topen = new TopenServiceReference.MsgSendSoapClient();
            string userName = "用户名";
            string passWord = "密码";
            string desNo = "手机号码";
            string voiceCode = "验证码";
            string amount = "播放次数";
            string templateID = "模板ID";

            string sendResult = topen.SendVoiceCodeWithTemplate(userName, passWord,desNo,voiceCode,amount,templateID); 

            //然后,根据返回的sendResult作相应处理
        }
		
                                    
PHP代码示例
http请求

<?php

$urlsend="http://120.55.197.77:1210/Services/MsgSend.asmx/SendVoiceCodeWithTemplate";

$token=array("userCode"=>"用户名","userPass"=>"密码","DesNo"=>"手机号码","VoiceCode"=>"验证码","amount"=>"播放次数","templateID"=>"模板ID");

echo http($urlsend,$token,"GET"); //get请求

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;
}

?>
                                    
webservice请求

<?php
	//此处仅示例发送短信,其他可类推
	header("Content-type: text/html; charset=utf-8");
	$client = new SoapClient("http://120.55.197.77:1210/Services/MsgSend.asmx?WSDL");
	$param = array("userCode"=>"用户名","userPass"=>"密码","DesNo"=>"手机号码","VoiceCode"=>"验证码","amount"=>"播放次数","templateID"=>"模板ID");
	$p = $client->SendVoiceCodeWithTemplate($param);
	print_r($p);
	?>
		
		
                                    
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://120.55.197.77:1210/Services/MsgSend.asmx/SendVoiceCodeWithTemplate";

            List<NameValuePair> nvps = new ArrayList<NameValuePair>();
            nvps.add(new BasicNameValuePair("userCode", "用户名"));
            nvps.add(new BasicNameValuePair("userPass", "密码"));
            nvps.add(new BasicNameValuePair("DesNo", "手机号"));
            nvps.add(new BasicNameValuePair("VoiceCode", "验证码"));
            nvps.add(new BasicNameValuePair("amount", "播放次数"));
            nvps.add(new BasicNameValuePair("templateID", "模板ID"));
            String post=httpPost(url,nvps);  //post请求

            String getparam="userCode=用户名&userPass=密码&DesNo=手机号&VoiceCode=验证码&amount=播放次数&templateID=模板ID";
            String result=httpGet(url,getparam); //get请求
        }

    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 httpGet(String url,String params){
        String result="";        
        try{
            HttpClient client=new DefaultHttpClient();            
            if(params!=""){
                url=url+"?"+params;
            }            
            HttpGet httpget=new HttpGet(url);
            HttpResponse response=client.execute(httpget);            
            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();      
    }
               
           
                                    
webservice请求

       public static void main(String[] args) {
            org.tempuri.MsgSend service = new org.tempuri.MsgSend();
            org.tempuri.MsgSendSoap port = service.getMsgSendSoap();
            String result= port.SendVoiceCodeWithTemplate("用户名", "密码","手机号","验证码","播放次数","模板ID");
            System.out.println(result);
        }
             
                                    
asp代码示例
http请求

<%
dim sendurl,senddata
sendurl="http://120.55.197.77:1210/Services/MsgSend.asmx/SendVoiceCodeWithTemplate"
senddata="userCode=用户名&userPass=密码&DesNo=手机号&VoiceCode=验证码&amount=播放次数&templateID=模板ID"

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

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

%>