安全验证码| 图片验证码| 短信验证码| 语音验证码| 上行语音验证码
接口说明

接口API以REST方式设计,为保证安全性,所有消息交互均以HTTPS方式交互。

所有文档中接口有相同的Base URL,当前为: http://www.iamyun.net:8080/api

业务URL格式:Base URL与业务URL相拼接为完整请求URL,消息参数及返回内容目前只接受json格式。

HTTP消息头:

Accept:application/json;charset=utf-8;

Content-Type:application/json;charset=utf-8;

必须在用户页面编辑好验证码模板,模板参数大允许8个字符,同时填入参数后,

全部语音拼接后大时长不应超过30秒。验证码内容将以语音呼叫形式发送到用户手机。

语音验证码发送URL: http://www.iamyun.net:8080/api/validate/voiceout

HTTP方法:POST

公共参数说明

用户注册后登录页面,可以在用户中心看到自己的UID和access token,在所有HTTP请求头中,必须带上此token,如:

Token : xxxxxxxxxxxxxxxxx

用户可以在后续使用中,从页面选择刷新此token,刷新token后,API 调用中的token必须使用新token,原有token自动失效。

为了进一步提高请求安全性,用户可以选择在帐户IP白名单中增加指定IP,只有在白名单中的IP允许访问API。

请求参数说明
参数名 类型 必选 说明 示例
to string 接收手机号,仅允许单个手机号 13012345678
template_id string 验证码模板号 23
arg string 对应模板中参数 1234
report_url string 状态报告发送地址 http://www.example.com/report/
响应参数说明
字段名 类型 说明 示例
status string 调用状态 0
desc string 状态说明 成功
msg_id string 验证码消息ID abcdefghijklmn
call_num string 呼出号码,应用应在页面上提示用户呼叫此号码 0571-87654321
示例

POST /validate/voiceout

{“to”: “13012345678”, “template_id”: “23”, “arg”: “1234” }

HTTP/1.1 200 OK

{“status”: “0”, “desc”: “成功”, “msg_id”: “abcd1234efgh” , “call_num”: “0571-87654321”}

代码示例

package com.test;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.util.HashMap;

import java.util.Iterator;

import java.util.Map;

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.entity.StringEntity;

import org.apache.http.impl.client.HttpClientBuilder;

import org.apache.http.protocol.HTTP;

import com.fasterxml.jackson.databind.ObjectMapper;

public class Test {

private static final int HTTP_STATUS_200 = 200;

private static final int HTTP_STATUS_201 = 201;

public static void main(String[] args) throws Exception{

String to = "15xxxxxxxx";

String template_id = "23";

String arg = "1233";

String json ="{\"to\":\""+to+"\",\"template_id\":\""+template_id+"\",\"arg\":\""+arg+"\"}";

ObjectMapper objectMapper = new ObjectMapper();

Map headMap = new HashMap ();

headMap.put("Token", "xxxxxxxxxxx");

httpPostHeadWithJSON("http://www.iamyun.net:8080/api/validate/voiceout", json,headMap);

}

public static String httpPostHeadWithJSON(String url, String json,Map headMap) throws Exception {

/* 创建HttpClient实例 */

HttpClient httpClient = HttpClientBuilder.create().build();

HttpPost httpPost = new HttpPost(url);

httpPost.addHeader(HTTP.CONTENT_TYPE, "application/json");

StringEntity se = new StringEntity(json,"UTF-8");

httpPost.setEntity(se);

if (headMap != null) {

for (Iterator it = headMap.keySet().iterator(); it.hasNext();) {

String key = it.next();

String value = headMap.get(key);

httpPost.addHeader(key, value);

}

}

String result = null;

try {

HttpResponse response = httpClient.execute(httpPost);

boolean success = response.getStatusLine().getStatusCode() == HTTP_STATUS_200 ||

response.getStatusLine().getStatusCode() == HTTP_STATUS_201;

HttpEntity entity = response.getEntity();

if (entity != null) {

InputStream instreams = entity.getContent();

result = convertStreamToString(instreams);

}

} catch (Exception e) {

e.printStackTrace();

} finally {

httpPost.releaseConnection();

}

return result;

}

public static String convertStreamToString(InputStream is) {

StringBuilder sb = new StringBuilder();

String line = null;

try {

BufferedReader reader = new BufferedReader(new InputStreamReader(

is, "UTF-8"));

while ((line = reader.readLine()) != null) {

if (sb.length() == 0) {

sb.append(line);

} else {

sb.append("\n" + line);

}

}

} catch (IOException e) {

e.printStackTrace();

} finally {

try {

is.close();

} catch (IOException e) {

e.printStackTrace();

}

}

return sb.toString();

}

}

", json,headMap);

}

public static String httpPostHeadWithJSON(String url, String json,Map headMap) throws Exception {

/* 创建HttpClient实例 */

HttpClient httpClient = HttpClientBuilder.create().build();

HttpPost httpPost = new HttpPost(url);

httpPost.addHeader(HTTP.CONTENT_TYPE, "application/json");

StringEntity se = new StringEntity(json,"UTF-8");

httpPost.setEntity(se);

if (headMap != null) {

for (Iterator it = headMap.keySet().iterator(); it.hasNext();) {

String key = it.next();

String value = headMap.get(key);

httpPost.addHeader(key, value);

}

}

String result = null;

try {

HttpResponse response = httpClient.execute(httpPost);

boolean success = response.getStatusLine().getStatusCode() == HTTP_STATUS_200 ||

response.getStatusLine().getStatusCode() == HTTP_STATUS_201;

HttpEntity entity = response.getEntity();

if (entity != null) {

InputStream instreams = entity.getContent();

result = convertStreamToString(instreams);

}

} catch (Exception e) {

e.printStackTrace();

} finally {

httpPost.releaseConnection();

}

return result;

}

public static String convertStreamToString(InputStream is) {

StringBuilder sb = new StringBuilder();

String line = null;

try {

BufferedReader reader = new BufferedReader(new InputStreamReader(

is, "UTF-8"));

while ((line = reader.readLine()) != null) {

if (sb.length() == 0) {

sb.append(line);

} else {

sb.append("\n" + line);

}

}

} catch (IOException e) {

e.printStackTrace();

} finally {

try {

is.close();

} catch (IOException e) {

e.printStackTrace();

}

}

return sb.toString();

}

}

正在维护更新中...
正在维护更新中...

# coding: utf-8

import requests

# 基地址

base_url = "http://www.iamyun.net:8080/api"

# API接口

req_url = base_url + "/validate/voiceout"

# HTTP头, 接收JSON格式

headers = {"Content-Type": "application/json;charset=UTF-8"}

# HTTP头中添加访问Token

headers["Token"] = "123456"

# 构造API参数

post_data = {"to": "13018956677", "template_id": "1", "arg": "123456"}

# 以json格式POST到服务器

result = requests.post(req_url, json=post_data, headers=headers)

# 得到结果

print result.content

#!/usr/bin/env bash

curl -X POST 'www.iamyun.net:8080/api/validate/voiceout'\

--header "Content-Type:application/json;charset=utf-8;"\

--header "Token: 12345y6"\

-d '{"to": "13588701622", "template_id": "1", "arg": "1234"}'

using System;

using System.IO;

using System.Net;

using System.Text;

static class Program

{static void Main()

{

// 基地址

string base_url = "www.iamyun.net:8080/api";

// 短信API地址

string req_url = base_url + "/validate/voiceout";

// 创建请求

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(req_url);

// 请求方法为POST

request.Method = "POST";

// ContentType必须为json

request.ContentType = "application/json;charset=UTF-8";

// 添加Token

request.Headers.Add("Token", "123456");

// 得到请求数据流并添加json格式的post数据,必须是UTF-8编码

Stream myRequestStream = request.GetRequestStream();

StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("utf-8"));

string postDataStr = "{\"to\": \"13018956697\", \"template_id\": \"1\", \"arg\": \"1234\"}";

myStreamWriter.Write(postDataStr);

myStreamWriter.Close();

// 得到返回内容

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();

Console.Write(response.Headers);

Console.Write(retString);

}

}

正在维护更新中...
错误码解释
“做通信,我们是认真的” 云上·通信,十余年通信行业专业团队,为客户提供优质、优惠、简单的互联网新通信服务
立即接入使用