Appearance
下载消息中的语音
按语音消息回调里的字段下载语音,返回的地址通常是 silk 文件。
接口地址: POST /getMsgVoice
说明与注意
- silk 文件要播放通常得先转码,转 MP3 等格式可用 silk-v3-decoder。
请求参数
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
| wId | 是 | string | 登录实例标识 |
| msgId | 是 | number | 消息 ID |
| length | 是 | int | 语音长度,对应 XML 中的 length 字段 |
| bufId | 是 | string | XML 中返回的 bufId 字段 |
| fromUser | 是 | string | 发送者 |
请求示例
http
POST {BASE_URL}/getMsgVoice
Authorization: Bearer <你的调用凭证>
Content-Type: application/json
{
"wId": "{{wId}}",
"msgId": 1114311129,
"fromUser": "wxid_6tn88z16x6ou12",
"bufId": "289139440622895483",
"length": 3227
}1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
bash
curl -X POST '{BASE_URL}/getMsgVoice' \
-H 'Authorization: Bearer <你的调用凭证>' \
-H 'Content-Type: application/json' \
--data-raw '{
"wId": "{{wId}}",
"msgId": 1114311129,
"fromUser": "wxid_6tn88z16x6ou12",
"bufId": "289139440622895483",
"length": 3227
}'1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
python
import requests
url = "{BASE_URL}/getMsgVoice"
headers = {"Authorization": "Bearer <你的调用凭证>", "Content-Type": "application/json"}
body = """{
"wId": "{{wId}}",
"msgId": 1114311129,
"fromUser": "wxid_6tn88z16x6ou12",
"bufId": "289139440622895483",
"length": 3227
}"""
resp = requests.post(url, headers=headers, data=body.encode("utf-8"))
print(resp.text)1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
String url = "{BASE_URL}/getMsgVoice";
String body = "{\n" +
" \"wId\": \"{{wId}}\",\n" +
" \"msgId\": 1114311129,\n" +
" \"fromUser\": \"wxid_6tn88z16x6ou12\",\n" +
" \"bufId\": \"289139440622895483\",\n" +
" \"length\": 3227\n" +
"}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
.header("Authorization", "Bearer <你的调用凭证>")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
php
<?php
$url = '{BASE_URL}/getMsgVoice';
$body = <<<'JSON'
{
"wId": "{{wId}}",
"msgId": 1114311129,
"fromUser": "wxid_6tn88z16x6ou12",
"bufId": "289139440622895483",
"length": 3227
}
JSON;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer <你的调用凭证>',
'Content-Type: application/json',
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
成功响应
json
{
"code": "1000",
"message": "成功",
"data": {
"url": "https://cdn.e-yun.example/msgVoice/e2045467-b1ac-4b3c-89f8-62ab2b3a2284.silk"
}
}1
2
3
4
5
6
7
2
3
4
5
6
7
错误响应
json
{
"code": "1001",
"message": "失败",
"data": null
}1
2
3
4
5
2
3
4
5
响应参数
| 参数名 | 类型 | 说明 |
|---|---|---|
| code | string | 1000 成功;其他值都是失败,通常是 1001 |
| message | string | 反馈信息 |
| data | object | 下载结果 |
| data.url | string | 语音文件地址,通常为 silk 文件 |