语音验证码接口文档

  • API接口文档
  • 状态码参考
  • demo示例参考
  • 常见问题

http://api.voice.veesing.com/webservice/voice.php?method=Submit&account=用户名&password=密码&mobile=手机号码
&content=4位数字
POST短信提交接口:
http:// api.voice.veesing.com/webservice/voice.php?method=Submit

参数说明

参数 method Submit
参数 account 账户名
参数 password 1. APIKEY(可以登用户心心查看)
2. 签名方式(生成签名方式请看文档最后的说明)(安全性较高)
参数 mobile 接收号码,只能提交1个号码
参数 content 验证码(4位数字)
参数 time Unix时间戳(当密码为签名方式时为必填)

返回值说明

Code int 返回值为2时,表示提交成功(更多请看返回值Code枚举)
Voiceid string 仅当提交成功后,此字段值才有意义(消息ID)
Msg string 提交结果描述

返回值枚举

code msg
0 提交失败
2 提交成功
400 非法ip访问
401 帐号不能为空
402 密码不能为空
403 手机号码不能为空
404 短信内容不能为空
4040 签名格式不正确
405 用户名或密码不正确
405 用户名或密码不正确
4050 账号被冻结
4051 剩余条数不足
406 产品id不能为空
4060 产品id不正确
407 短信内容长度超出了限制
407 短信内容长度超出了限制
4070 短信内容含有敏感字符
409 手机号码没有一个是格式正确的,或者手机号码被列入黑名单

注意:如果实际的返回值和上述的值不相同,说明接口程序有做新的调整

<?php
session_start
();

header("Content-type:text/html; charset=UTF-8");

function 
Post($curlPost,$url){
        
$curl curl_init();
        
curl_setopt($curlCURLOPT_URL$url);
        
curl_setopt($curlCURLOPT_HEADERfalse);
        
curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
        
curl_setopt($curlCURLOPT_NOBODYtrue);
        
curl_setopt($curlCURLOPT_POSTtrue);
        
curl_setopt($curlCURLOPT_POSTFIELDS$curlPost);
        
$return_str curl_exec($curl);
        
curl_close($curl);
        return 
$return_str;
}
function 
xml_to_array($xml){
    
$reg "/<(\w+)[^>]*>([\\x00-\\xFF]*)<\\/\\1>/";
    if(
preg_match_all($reg$xml$matches)){
        
$count count($matches[0]);
        for(
$i 0$i $count$i++){
        
$subxml$matches[2][$i];
        
$key $matches[1][$i];
            if(
preg_match$reg$subxml )){
                
$arr[$key] = xml_to_array$subxml );
            }else{
                
$arr[$key] = $subxml;
            }
        }
    }
    return 
$arr;
}
function 
random($length $numeric 0) {
    
PHP_VERSION '4.2.0' && mt_srand((double)microtime() * 1000000);
    if(
$numeric) {
        
$hash sprintf('%0'.$length.'d'mt_rand(0pow(10$length) - 1));
    } else {
        
$hash '';
        
$chars 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789abcdefghjkmnpqrstuvwxyz';
        
$max strlen($chars) - 1;
        for(
$i 0$i $length$i++) {
            
$hash .= $chars[mt_rand(0$max)];
        }
    }
    return 
$hash;
}
$target "http://api.voice.ihuyi.com/webservice/voice.php?method=Submit";

$mobile $_POST['mobile'];
$send_code $_POST['send_code'];

$mobile_code random(4,1);
if(empty(
$mobile)){
    exit(
'手机号码不能为空');
}

if(empty(
$_SESSION['send_code']) or $send_code!=$_SESSION['send_code']){
    
//防用户恶意请求
    
exit('请求超时,请刷新页面后重试');
}

$post_data "account=用户名&password=密码&mobile=".$mobile."&content=".$mobile_code;
//密码可以使用明文密码或使用32位MD5加密
$gets =  xml_to_array(Post($post_data$target));
if(
$gets['SubmitResult']['code']==2){
    
$_SESSION['mobile'] = $mobile;
    
$_SESSION['mobile_code'] = $mobile_code;
}
echo 
$gets['SubmitResult']['msg'];
?>
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%

Response.Charset = "gb2312"

'<meta http-equiv="Content-Type" content="text/html; charset=gbk" />

'asp UTFתGB2312   UTF8תΪGBֵasp
function UTF2GB(UTFStr)
for Dig=1 to len(UTFStr)
   'UTF8%ͷת
   if mid(UTFStr,Dig,1)="%" then
      'UTF8ִ8תΪ
     if len(UTFStr) >= Dig+8 then
        GBStr=GBStr & ConvChinese(mid(UTFStr,Dig,9))
        Dig=Dig+8
     else
       GBStr=GBStr & mid(UTFStr,Dig,1)
     end if
   else
      GBStr=GBStr & mid(UTFStr,Dig,1)
   end if
next
UTF2GB=GBStr
end function

'GB2312תUTF8asp  GBתΪUTF8
Function toUTF8(szInput)
     Dim wch, uch, szRet
     Dim x
     Dim nAsc, nAsc2, nAsc3
     'Ϊգ˳
     If szInput = "" Then
         toUTF8 = szInput
         Exit Function
     End If
     'ʼת
      For x = 1 To Len(szInput)
         'midֲGB
         wch = Mid(szInput, x, 1)
         'ascWÿһGBֵUnicodeַ
         'עascصANSI ַ룬ע
         nAsc = AscW(wch)
         If nAsc < 0 Then nAsc = nAsc + 65536
    
         If (nAsc And &HFF80) = 0 Then
             szRet = szRet & wch
         Else
             If (nAsc And &HF000) = 0 Then
                 uch = "%" & Hex(((nAsc \ 2 ^ 6)) Or &HC0) & Hex(nAsc And &H3F Or &H80)
                 szRet = szRet & uch
             Else
                'GBֵUnicodeַ0800 - FFFFֽ֮ģ
                 uch = "%" & Hex((nAsc \ 2 ^ 12) Or &HE0) & "%" & _
                             Hex((nAsc \ 2 ^ 6) And &H3F Or &H80) & "%" & _
                             Hex(nAsc And &H3F Or &H80)
                 szRet = szRet & uch
             End If
         End If
     Next         
     toUTF8 = szRet
End Function

'תΪʮƵasp
function c2to16(x)
    i=1
    for i=1 to len(x) step 4
       c2to16=c2to16 & hex(c2to10(mid(x,i,4)))
    next
end function

'תΪʮƵasp
function c2to10(x)
    c2to10=0
    if x="0" then exit function
      i=0
    for i= 0 to len(x) -1
       if mid(x,len(x)-i,1)="1" then c2to10=c2to10+2^(i)
    next
end function

'ʮתΪƵasp
function c16to2(x)
     i=0
     for i=1 to len(trim(x))
       tempstr= c10to2(cint(int("&h" & mid(x,i,1))))
       do while len(tempstr)<4
          tempstr="0" & tempstr
       loop
       c16to2=c16to2 & tempstr
    next
end function

function c10to2(x)
    mysign=sgn(x)
    x=abs(x)
    DigS=1
    do
       if x<2^DigS then
         exit do
       else
         DigS=DigS+1
       end if
    loop
    tempnum=x
    i=0
    for i=DigS to 1 step-1
       if tempnum>=2^(i-1) then
          tempnum=tempnum-2^(i-1)
          c10to2=c10to2 & "1"
       else
          c10to2=c10to2 & "0"
       end if
    next
    if mysign=-1 then c10to2="-" & c10to2
end function

'UTF8ֽתΪ
function ConvChinese(x)
    A=split(mid(x,2),"%")
    i=0
    j=0
   for i=0 to ubound(A)
      A(i)=c16to2(A(i))
   next
   for i=0 to ubound(A)-1
     DigS=instr(A(i),"0")
     Unicode=""
     for j=1 to DigS-1
       if j=1 then
         A(i)=right(A(i),len(A(i))-DigS)
         Unicode=Unicode & A(i)
       else
          i=i+1
          A(i)=right(A(i),len(A(i))-2)
          Unicode=Unicode & A(i)
       end if
     next
     if len(c2to16(Unicode))=4 then
        ConvChinese=ConvChinese & chrw(int("&H" & c2to16(Unicode)))
     else
        ConvChinese=ConvChinese & chr(int("&H" & c2to16(Unicode)))
     end if
   next
end function

'GB2312תunicode(&#)asp  GBתΪunicode
function chinese2unicode(Str)
   dim i
   dim Str_one
   dim Str_unicode
   if(isnull(Str)) then
      exit function
   end if
   for i=1 to len(Str)
     Str_one=Mid(Str,i,1)
     Str_unicode=Str_unicode&chr(38)
     Str_unicode=Str_unicode&chr(35)
     Str_unicode=Str_unicode&chr(120)
     Str_unicode=Str_unicode& Hex(ascw(Str_one))
     Str_unicode=Str_unicode&chr(59)
   next
   chinese2unicode=Str_unicode
end function  

'URLַ뺯
Function URLDecode(enStr)
dim deStr
dim c,i,v
deStr=""
for i=1 to len(enStr)
   c=Mid(enStr,i,1)
   if c="%" then
    v=eval("&h"+Mid(enStr,i+1,2))
    if v<128 then
     deStr=deStr&chr(v)
     i=i+2
    else
     if isvalidhex(mid(enstr,i,3)) then
      if isvalidhex(mid(enstr,i+3,3)) then
       v=eval("&h"+Mid(enStr,i+1,2)+Mid(enStr,i+4,2))
       deStr=deStr&chr(v)
       i=i+5
      else
       v=eval("&h"+Mid(enStr,i+1,2)+cstr(hex(asc(Mid(enStr,i+3,1)))))
       deStr=deStr&chr(v)
       i=i+3
      end if
     else
      destr=destr&c
     end if
    end if
   else
    if c="+" then
     deStr=deStr&" "
    else
     deStr=deStr&c
    end if
   end if
next
URLDecode=deStr
end function

'жǷΪЧʮƴ
function isvalidhex(str)
dim c
isvalidhex=true
str=ucase(str)
if len(str)<>3 then isvalidhex=false:exit function
if left(str,1)<>"%" then isvalidhex=false:exit function
   c=mid(str,2,1)
if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
   c=mid(str,3,1)
if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
end function



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


Function gen_key(digits)    
    'Create and define array
    dim char_array(50)
    char_array(0) = "0"
    char_array(1) = "1"
    char_array(2) = "2"
    char_array(3) = "3"
    char_array(4) = "4"
    char_array(5) = "5"
    char_array(6) = "6"
    char_array(7) = "7"
    char_array(8) = "8"
    char_array(9) = "9"
    
    'Initiate randomize method for default seeding
    randomize
    
    'Loop through and create the output based on the the variable passed to
    'the function for the length of the key.
    do while len(output) < digits
    num = char_array(Int((9 - 0 + 1) * Rnd + 0))
    output = output + num
    loop
    
    'Set return
    gen_key = output
End Function


Dim mobile
mobile = request("mobile")    '¼û


    if mobile="" then
       response.Write("ֻ벻Ϊ")
    else
        
        if request.Form("send_code") = "" or Session("send_code")<>request.Form("send_code") then
            'û
            response.Write("ʱˢҳ")
        else    
                 
            dim target,post_data,content,res,mobile_code
            mobile_code = gen_key(4)
            Session("mobile_code") = mobile_code
            'Response.Cookies("mobile_code") = mobile_code
            Session("mobile") = mobile
            'Response.Cookies("mobile") = mobile
            target = "http://api.voice.ihuyi.com/webservice/voice.php?method=Submit"
            post_data = "account=û&password=&mobile="&mobile&"&content="&mobile_code
            'response.Write(UTF2GB(Post(target,post_data)))
    
            tempstr = UTF2GB(Post(target,post_data))
            'if instr(tempstr,"ύɹ")>0 Then
                'response.Write("true") 
            'else
                'response.Write("error") 
            'end if
    
            Dim len1,len2
            len1 = instr(1,tempstr,"</code>",1)-1
            len2 = instr(1,tempstr,"<code>",1)
            'response.Write(len2)
            code=left(tempstr,len1)
            code=right(code,(len1-len2-5))
            'response.Write(code)
    
            Dim len3,len4
            len3 = instr(1,tempstr,"</msg>",1)-1
            len4 = instr(1,tempstr,"<msg>",1)
            'response.Write(len2)
            msg=left(tempstr,len3)
            msg=right(msg,(len3-len4-4))
            response.Write(msg)
            
        end if

    end If
%>
import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

import org.dom4j.Document;   
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;   
import org.dom4j.Element;   

import util.StringUtil;

public class sendsms {
    
    private static String Url = "http://api.voice.ihuyi.com/webservice/voice.php?method=Submit";
    
    
    
    public static void main(String [] args) {
        
        HttpClient client = new HttpClient(); 
        PostMethod method = new PostMethod(Url); 
            
        //client.getParams().setContentCharset("GBK");        
        client.getParams().setContentCharset("UTF-8");
        method.setRequestHeader("ContentType","application/x-www-form-urlencoded;charset=UTF-8");

        
        int mobile_code = (int)((Math.random()*9+1)*100000);

        //System.out.println(mobile);
        
        String content = new String(mobile_code); 

        NameValuePair[] data = {//ύ
                new NameValuePair("account", "û"), 
                new NameValuePair("password", ""), //ʹʹ32λMD5
                //new NameValuePair("password", util.StringUtil.MD5Encode("")),
                new NameValuePair("mobile", "ֻ"), 
                new NameValuePair("content", content),
        };
        
        method.setRequestBody(data);        
        
        
        try {
            client.executeMethod(method);    
            
            String SubmitResult =method.getResponseBodyAsString();
                    
            //System.out.println(SubmitResult);

            Document doc = DocumentHelper.parseText(SubmitResult); 
            Element root = doc.getRootElement();


            String code = root.elementText("code");    
            String msg = root.elementText("msg");    
            String smsid = root.elementText("smsid");    
            
            
            System.out.println(code);
            System.out.println(msg);
            System.out.println(smsid);
                        
             if("2".equals(code)){
                System.out.println("ύɹ");
            }
            
        } catch (HttpException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (DocumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }    
        
    }
    
}
<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import = "java.io.*" %>
<%@ page import = "java.net.*" %>
<%@ page import = "java.util.*" %>
<%@ page import = "java.lang.*" %>
<%
String postUrl = "http://api.voice.ihuyi.com/webservice/voice.php?method=Submit";

int mobile_code = (int)((Math.random()*9+1)*100000);

String account = "用户名";
String password = "密码";
String mobile = request.getParameter("mobile");
String content = new String(mobile_code);

try {

    URL url = new URL(postUrl);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setDoOutput(true);//允许连接提交信息
    connection.setRequestMethod("POST");//网页提交方式“GET”、“POST”
    connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    connection.setRequestProperty("Connection", "Keep-Alive");
    StringBuffer sb = new StringBuffer();
    sb.append("account="+account);
    sb.append("&password="+password);
    sb.append("&mobile="+mobile);
    sb.append("&content="+content);
    OutputStream os = connection.getOutputStream();
    os.write(sb.toString().getBytes());
    os.close();

    String line, result = "";
    BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));
    while ((line = in.readLine()) != null) {
        result += line + "\n";
    }
    in.close();
    out.println(result);

} catch (IOException e) {
    e.printStackTrace(System.out);
}

%>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.IO;
using System.Net;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Post : System.Web.UI.Page
{
    public static string PostUrl = ConfigurationManager.AppSettings["WebReference.Service.PostUrl"];
    protected void Page_Load(object sender, EventArgs e)
    {
        string account = "用户名";
        string password = "密码";
        string mobile = Request.QueryString["mobile"];
        Random rad = new Random();
        int mobile_code = rad.Next(1000, 10000);
        string content = mobile_code;
        
        //Session["mobile"] = mobile;
        //Session["mobile_code"] = mobile_code;
        
        string postStrTpl = "account={0}&password={1}&mobile={2}&content={3}";

        UTF8Encoding encoding = new UTF8Encoding();
        byte[] postData = encoding.GetBytes(string.Format(postStrTpl, account, password, mobile, content));

        HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(PostUrl);
        myRequest.Method = "POST";
        myRequest.ContentType = "application/x-www-form-urlencoded";
        myRequest.ContentLength = postData.Length;

        Stream newStream = myRequest.GetRequestStream();
        // Send the data.
        newStream.Write(postData, 0, postData.Length);
        newStream.Flush();
        newStream.Close();

        HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
        if (myResponse.StatusCode == HttpStatusCode.OK)
        {
            StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);

               //Response.Write(reader.ReadToEnd());

               string res = reader.ReadToEnd();
               int len1 = res.IndexOf("</code>");
               int len2 = res.IndexOf("<code>");
               string code=res.Substring((len2+6),(len1-len2-6));
               //Response.Write(code);

               int len3 = res.IndexOf("</msg>");
               int len4 = res.IndexOf("<msg>");
               string msg=res.Substring((len4+5),(len3-len4-5));
               Response.Write(msg);

               Response.End();

        }
        else
        {
            //访问失败
        }
    }
}
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   4740
   ClientLeft      =   120
   ClientTop       =   450
   ClientWidth     =   5940
   LinkTopic       =   "Form1"
   ScaleHeight     =   4740
   ScaleWidth      =   5940
   StartUpPosition =   2  'Ļ
   Begin MSWinsockLib.Winsock Winsock1 
      Left            =   4920
      Top             =   4200
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   393216
   End
   Begin VB.TextBox Text4 
      Height          =   270
      Left            =   360
      TabIndex        =   4
      Text            =   $"Form1.frx":0000
      Top             =   1200
      Width           =   5415
   End
   Begin VB.TextBox Text3 
      Height          =   270
      Left            =   360
      TabIndex        =   3
      Text            =   "ֻ"
      Top             =   840
      Width           =   3495
   End
   Begin VB.TextBox Text2 
      Height          =   270
      Left            =   360
      TabIndex        =   2
      Text            =   "ʹʹ32λMD5"
      Top             =   480
      Width           =   3495
   End
   Begin VB.TextBox Text1 
      Height          =   270
      Left            =   360
      TabIndex        =   1
      Text            =   "û"
      Top             =   120
      Width           =   3495
   End
   Begin VB.CommandButton Command1 
      Caption         =   " "
      Height          =   495
      Left            =   4440
      TabIndex        =   0
      Top             =   240
      Width           =   1215
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "Label2"
      Height          =   180
      Left            =   360
      TabIndex        =   6
      Top             =   2160
      Visible         =   0   'False
      Width           =   540
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "״̬"
      Height          =   180
      Left            =   360
      TabIndex        =   5
      Top             =   1920
      Width           =   360
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_Load()
    Winsock1.Protocol = sckTCPProtocol
    Winsock1.RemoteHost = "106.ihuyi.cn"
    Winsock1.RemotePort = 80
    Winsock1.Connect
    DoEvents
        
    If Winsock1.State <> 7 Then Label1.Caption = "״̬ӳɹ" & Chr(13)
        
    Text1.Text = "û"
    Text2.Text = "ʹʹ32λMD5"
    Text3.Text = "ֻ"
        
End Sub
Private Sub Command1_Click()

    On Error Resume Next

    Dim PostData As String
    Dim Str As String
     
    Dim strWebPage As String
    Dim strCommand As String
        
    PostData = "account=" + Text1.Text + "&password=" + Text2.Text + "&mobile=" + Text3.Text + "&content=" + Text4.Text
    
    Dim Ai() As Byte
    Ai = StrConv(strWebPage, vbFromUnicode)
    CLength = UBound(Ai) + 1
    Str = "POST /webservice/sms.php?method=Submit HTTP/1.1" + vbCrLf
    Str = Str + "Accept: */*" + vbCrLf
    Str = Str + "Content-Type: application/x-www-form-urlencoded" + vbCrLf
    Str = Str + "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; Maxthon; .NET CLR 1.1.4322)" & vbCrLf
    Str = Str + "Language: zh-CN, zh, *" + vbCrLf
    Str = Str + "Connection: Keep-Alive" + vbCrLf
    Str = Str + "Host: 106.ihuyi.cn" + vbCrLf
    Str = Str + "Accept-Language: zh-CN, zh, *" + vbCrLf
    Str = Str + "Accept-Encoding: gzip, deflate" & vbCrLf
    Str = Str & "Content-Length: " & Len(PostData) & vbCrLf & vbCrLf
    Str = Str & PostData & vbCrLf
    'MsgBox str

    
    strWebPage = "http://api.voice.ihuyi.com/webservice/voice.php?method=Submit&account=" + Text1.Text + "&password=" + Text2.Text + "&mobile=" + Text3.Text + "&content=" + Text4.Text
    strCommand = "GET " + strWebPage + " HTTP/1.0" + vbCrLf
    strCommand = strCommand + vbCrLf
    
    
    If Winsock1.State <> 7 Then
        Winsock1.Protocol = sckTCPProtocol
        Winsock1.RemoteHost = "106.ihuyi.cn"
        Winsock1.RemotePort = 80
        Winsock1.Connect
        DoEvents
        Winsock1.SendData Str
    Else
        Winsock1.SendData strCommand
    End If
    


    'Label1.Caption = "״̬" & strState & Chr(13) & strCommand & Chr(13)
    
End Sub


Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim rec() As Byte
Winsock1.GetData rec, vbString
'MsgBox Utf8ToUnicode(Right(rec, 150))

Label2.Visible = True
Label2.Caption = Utf8ToUnicode(rec)

Winsock1.Close
End Sub

  • 在没有呼出成功的情况下系统会自动扣除费用吗? 阅读原文