语音通知 API 开发文档

标准 HTTPS 接口,支持 POST/GET 请求,JSON 格式返回。本文档包含接口说明、参数定义、状态码查询及多语言代码示例,帮助开发者快速集成语音通知能力。

3分钟快速接入
6种语言代码示例
HTTPS 加密传输
API文档

接口简介

互亿无线语音通知 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 进行身份认证,通过请求参数传递:

参数名类型必填说明
accountstringAPI ID,控制台获取
passwordstringAPI Key,控制台获取

请妥善保管 API Key,不要在客户端代码中暴露。建议在服务端调用接口。

发送语音通知

调用此接口向指定手机号发送语音通知。

请求 URL

POST https://api.ihuyi.com/voice/vm

请求参数

参数名类型必填说明
accountstringAPI ID
passwordstringAPI Key
mobilestring接收手机号,仅支持国内号码
contentstring语音内容,1-500字,需与报备模板一致
formatstring返回格式,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

参数名类型必填说明
accountstringAPI ID
passwordstringAPI Key
smsidstring发送接口返回的 smsid

余额查询

查询账户当前剩余语音通知条数。

POST https://api.ihuyi.com/voice/balance

响应参数

参数名类型说明
codeint状态码,2 表示成功
msgstring状态描述
smsidstring消息唯一标识,用于状态查询
countint计费条数

状态码说明

状态码说明处理建议
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 通/小时。如需更高并发,可申请多条独享线路。

还有疑问?

查看完整常见问题,或联系技术支持获取帮助

查看常见问题 免费试用

立即开始使用语音通知 API

注册送10条调试额度 · 3分钟快速接入 · 免费技术支持