API: Voice/Template - 语音模板管理
概览
voice/template 是 SUBMAIL 的语音模板 API。
使用 voice/template 可以获取、创建、编辑或删除您的语音模板。
语音模板支持两种类型:
- 文本模板
- 音频模板
URL
https://api-v4.mysubmail.com/voice/template
支持格式
| 格式 | URL |
|---|---|
| json | https://api-v4.mysubmail.com/voice/template.json(默认) |
| xml | https://api-v4.mysubmail.com/voice/template.xml |
| yaml | https://api-v4.mysubmail.com/voice/template.yaml |
HTTP 请求方式
| 方法 | 说明 |
|---|---|
| GET | 获取全部模板列表,或获取指定的单个模板 |
| POST | 创建一个新的语音模板,并提交至 SUBMAIL 进行人工审核 |
| PUT | 编辑或更新一个语音模板,并提交至 SUBMAIL 进行人工审核 |
| DELETE | 删除一个语音模板 |
是否需要授权
是
参阅 API 授权和验证机制
GET 方法(获取模板列表)
请求参数
| 参数 | 类型 | 必需/可选 | 默认 | 描述 |
|---|---|---|---|---|
| appid | string | 必需 | 无 | 语音应用 ID |
| signature | string | 必需 | 无 | 应用密匙或数字签名 |
| template_id | string | 可选 | 无 | 模板 ID,为空则获取列表 |
| page | string | 可选 | 1 | 页码 |
| rows | string | 可选 | 30 | 每页记录数,最大 100 |
| timestamp | UNIX 时间戳 | 可选 | 无 | UNIX 时间戳 |
| sign_type | string | 可选 | normal | 授权模式 |
代码示例
curl -s "https://api-v4.mysubmail.com/voice/template.json?appid=your_appid&signature=your_appkey&page=1&rows=10"
返回示例
{
"status": "success",
"templates": [
{
"template_id": "uMnmq2",
"title": "验证码模板",
"message": "您的验证码是:123456",
"voice_type": 0,
"add_date": 1654470015,
"edit_date": 1654470015,
"template_status": 2,
"template_status_description": "审核通过"
}
],
"rows": 1,
"page": 1}
获取单个模板
curl -s "https://api-v4.mysubmail.com/voice/template.json?appid=your_appid&signature=your_appkey&template_id=uMnmq2"
{
"status": "success",
"template": {
"template_id": "uMnmq2",
"title": "验证码模板",
"message": "您的验证码是:123456",
"voice_type": 0,
"add_date": 1654470015,
"edit_date": 1654470015,
"template_status": 2,
"template_status_description": "审核通过"
}}
POST 方法(创建模板)
请求参数
| 参数 | 类型 | 必需/可选 | 默认 | 描述 |
|---|---|---|---|---|
| appid | string | 必需 | 无 | 语音应用 ID |
| signature | string | 必需 | 无 | 应用密匙或数字签名 |
| voice_type | string | 必需 | 无 | 0=文本模板,1=音频模板 |
| title | string | 可选 | 无 | 模板标题,最多32字符 |
| message | string | 必需 | 无 | 模板内容 |
| file | file | 条件必需 | 无 | 音频文件(voice_type=1时必需),WAV格式,最大8MB |
| timestamp | UNIX 时间戳 | 可选 | 无 | UNIX 时间戳 |
| sign_type | string | 可选 | normal | 授权模式 |
创建文本模板
curl -d "appid=your_appid&signature=your_appkey&voice_type=0&title=验证码模板&message=您的验证码是:@var(code)" https://api-v4.mysubmail.com/voice/template.json
{
"status": "success",
"template_id": "FsoAF3"}
创建音频模板
curl -F "appid=your_appid" \
-F "signature=your_appkey" \
-F "voice_type=1" \
-F "title=通知模板" \
-F "message=备注信息" \
-F "file=@/path/to/audio.wav" \
https://api-v4.mysubmail.com/voice/template.json
{
"status": "success",
"template_id": "XyZkL9"}
PUT 方法(更新模板)
请求参数
| 参数 | 类型 | 必需/可选 | 默认 | 描述 |
|---|---|---|---|---|
| appid | string | 必需 | 无 | 语音应用 ID |
| signature | string | 必需 | 无 | 应用密匙或数字签名 |
| template_id | string | 必需 | 无 | 需要更新的模板 ID |
| title | string | 可选 | 无 | 模板标题 |
| message | string | 条件必需 | 无 | 模板内容 |
| file | file | 可选 | 无 | 替换音频文件时提供 |
| timestamp | UNIX 时间戳 | 可选 | 无 | UNIX 时间戳 |
| sign_type | string | 可选 | normal | 授权模式 |
更新文本模板
curl --data "appid=your_appid&signature=your_appkey&template_id=FsoAF3&title=新标题&message=新内容" -X PUT https://api-v4.mysubmail.com/voice/template.json
{
"status": "success"}
DELETE 方法(删除模板)
请求参数
| 参数 | 类型 | 必需/可选 | 默认 | 描述 |
|---|---|---|---|---|
| appid | string | 必需 | 无 | 语音应用 ID |
| signature | string | 必需 | 无 | 应用密匙或数字签名 |
| template_id | string | 必需 | 无 | 需要删除的模板 ID |
| timestamp | UNIX 时间戳 | 可选 | 无 | UNIX 时间戳 |
| sign_type | string | 可选 | normal | 授权模式 |
代码示例
curl --data "appid=your_appid&signature=your_appkey&template_id=FsoAF3" -X DELETE https://api-v4.mysubmail.com/voice/template.json
{
"status": "success"}
返回值说明
| 参数 | 描述 |
|---|---|
| status | 请求状态:success 或 error |
| template_id | 模板 ID |
| template | 模板详情对象 |
| templates | 模板列表数组 |
| rows | 总记录数 |
| page | 当前页码 |
| title | 模板标题 |
| message | 模板内容 |
| voice_type | 模板类型:0=文本,1=音频 |
| voice_file | 音频文件 ID |
| add_date | 创建时间(UNIX 时间戳) |
| edit_date | 编辑时间(UNIX 时间戳) |
| template_status | 状态码 |
| template_status_description | 状态描述 |
| template_reject_reason | 驳回原因 |
模板状态码
| 状态码 | 描述 |
|---|---|
| 0 | 未提交审核 |
| 1 | 正在审核 |
| 2 | 审核通过 |
| 3 | 未通过审核 |
参阅 API 错误代码