接口简介
互亿无线语音通知 API 提供标准的 HTTPS 接口,开发者可以通过调用接口向指定手机号发送语音通知。系统会自动将文本内容转换为语音,并通过电话呼叫的方式送达用户。
接口地址:https://api.ihuyi.com/voice/vm,请求方式:POST/GET,数据格式:JSON
主要特性
- TTS 文本转语音:输入文本自动转换为自然语音,无需录制音频
- 按成功计费:只有用户成功接听才计费,失败不计费
- 失败自动补呼:用户未接时自动补呼,确保通知送达
- 通话时长回传:每通电话的状态和时长实时回传
- 模板报备制:约2小时审核通过,无需报备签名
快速接入
只需 3 步即可完成语音通知 API 的接入:
注册即送 10 条免费调试额度,可用于接口测试和模板调试。
第一步:注册账户
访问互亿无线官网注册账户,完成企业认证后,在控制台获取 API ID 和 API Key。
第二步:报备模板
在控制台提交语音模板,约 2 小时审核通过。模板内容 1-500 字,支持变量替换。
第三步:调用接口
参考下方代码示例,调用发送接口即可发送语音通知。
认证方式
API 使用 API ID + API Key 进行身份认证,通过请求参数传递:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
account | string | 是 | API ID,控制台获取 |
password | string | 是 | API Key,控制台获取 |
请妥善保管 API Key,不要在客户端代码中暴露。建议在服务端调用接口。
发送语音通知
调用此接口向指定手机号发送语音通知。
请求 URL
POST https://api.ihuyi.com/voice/vm
请求参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
account | string | 是 | API ID |
password | string | 是 | API Key |
mobile | string | 是 | 接收手机号,仅支持国内号码 |
content | string | 是 | 语音内容,1-500字,需与报备模板一致 |
format | string | 否 | 返回格式,json 或 xml,默认 json |
代码示例
import requests url = "https://api.ihuyi.com/voice/vm" payload = { "account": "your_api_id", "password": "your_api_key", "mobile": "138****8888", "content": "【告警】服务器CPU使用率超过90%,请及时处理" } response = requests.post(url, json=payload) print(response.json())
<?php $url = 'https://api.ihuyi.com/voice/vm'; $data = [ 'account' => 'your_api_id', 'password' => 'your_api_key', 'mobile' => '138****8888', 'content' => '【告警】服务器CPU使用率超过90%' ]; $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); curl_close($ch); echo $result;
import okhttp3.*; public class VoiceNotify { public static void main(String[] args) { OkHttpClient client = new OkHttpClient(); MediaType JSON = MediaType.parse("application/json"); String body = "{\"account\":\"your_api_id\"," + "\"password\":\"your_api_key\"," + "\"mobile\":\"138****8888\"," + "\"content\":\"【告警】CPU超过90%\"}"; Request request = new Request.Builder() .url("https://api.ihuyi.com/voice/vm") .post(RequestBody.create(JSON, body)) .build(); Response response = client.newCall(request).execute(); System.out.println(response.body().string()); } }
const axios = require('axios'); async function sendVoiceNotify() { const url = 'https://api.ihuyi.com/voice/vm'; const payload = { account: 'your_api_id', password: 'your_api_key', mobile: '138****8888', content: '【告警】服务器CPU使用率超过90%' }; const response = await axios.post(url, payload); console.log(response.data); } sendVoiceNotify();
package main import ( "bytes" "encoding/json" "fmt" "net/http" ) func main() { url := "https://api.ihuyi.com/voice/vm" payload := map[string]string{ "account": "your_api_id", "password": "your_api_key", "mobile": "138****8888", "content": "【告警】CPU超过90%", } jsonData, _ := json.Marshal(payload) resp, _ := http.Post(url, "application/json", bytes.NewBuffer(jsonData)) defer resp.Body.Close() fmt.Println(resp.Status) }
using System; using System.Net.Http; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; class VoiceNotify { static async Task Main() { using var client = new HttpClient(); var payload = new { account = "your_api_id", password = "your_api_key", mobile = "138****8888", content = "【告警】CPU超过90%" }; var json = JsonConvert.SerializeObject(payload); var content = new StringContent(json, Encoding.UTF8, "application/json"); var response = await client.PostAsync("https://api.ihuyi.com/voice/vm", content); Console.WriteLine(await response.Content.ReadAsStringAsync()); } }
响应示例
JSON 响应
{
"code": 2,
"msg": "提交成功",
"smsid": "168439201712345678",
"count": 1
}
状态查询
查询指定语音通知的发送状态和通话时长。
POST https://api.ihuyi.com/voice/status
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
account | string | 是 | API ID |
password | string | 是 | API Key |
smsid | string | 是 | 发送接口返回的 smsid |
余额查询
查询账户当前剩余语音通知条数。
POST https://api.ihuyi.com/voice/balance
响应参数
| 参数名 | 类型 | 说明 |
|---|---|---|
code | int | 状态码,2 表示成功 |
msg | string | 状态描述 |
smsid | string | 消息唯一标识,用于状态查询 |
count | int | 计费条数 |
状态码说明
| 状态码 | 说明 | 处理建议 |
|---|---|---|
2 | 提交成功 | 正常发送 |
400 | 参数错误 | 检查请求参数是否完整 |
401 | 认证失败 | 检查 API ID 和 API Key |
402 | 余额不足 | 请充值后再发送 |
403 | 内容未审核 | 请先报备语音模板 |
404 | 号码格式错误 | 检查手机号格式 |
500 | 服务器内部错误 | 稍后重试或联系技术支持 |
模板报备
语音通知内容需要先报备模板,审核通过后才能发送。
- 报备入口:控制台 → 语音通知 → 模板管理
- 审核时间:约 2 小时,受理时间 9:00-20:00(含节假日)
- 模板长度:1-500 字,支持变量替换
- 签名要求:无需报备签名,只需报备模板内容
模板中可使用【变量】标记,发送时动态替换为实际内容。例如:【告警】服务器【变量】CPU使用率超过【变量】%,请及时处理。
常见问题
语音通知怎么计费?
按成功计费,只有用户成功接听才计费,失败不计费。按70字/条计费(约20秒播报),套餐包无有效期。最低1500元起购。
支持哪些编程语言?
提供 Java、PHP、Python、C/C++、C#、Go、Shell、Ruby、Node.js、Objective-C 等 11 种语言代码示例。标准 HTTPS 接口,任何支持 HTTP 请求的语言都可以调用。
单线路并发量是多少?
单线路支持 20 并发,约 2000 通/小时。如需更高并发,可申请多条独享线路。