Appearance
发送文本
发送文本消息。首次联调建议把 wcId 设为 filehelper,手机微信能直接看到结果。
接口地址: POST /sendText
前置条件
- 微信实例已登录,并已获得可用
wId。 - 发送目标是好友、文件传输助手或当前微信所在群聊。
- 同一
wId建议进入队列,避免并发直发。
请求参数
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
| wId | 是 | string | 登录实例标识 |
| wcId | 是 | string | 接收方微信 ID、filehelper 或群 ID,如 24187765053@chatroom |
| content | 是 | string | 文本消息内容 |
响应参数
| 参数名 | 类型 | 说明 |
|---|---|---|
| code | string | 1000 成功;其他值都是失败,通常是 1001 |
| message | string | 反馈信息 |
| data.type | int | 消息类型 |
| data.msgId | long | 消息 ID |
| data.newMsgId | long | 新消息 ID |
| data.createTime | long | 发送时间戳(秒) |
| data.wcId | string | 接收方 ID |
| data.respRet | int | 发送失败时才有:微信侧错误码,含义见发送错误码 |
| data.respMsg | string | 发送失败时可能有:微信侧的错误说明 |
请求示例
http
POST {BASE_URL}/sendText
Authorization: Bearer <你的调用凭证>
Content-Type: application/json
{
"wId": "0000016e-63eb-f319-0001-ed01076abf1f",
"wcId": "filehelper",
"content": "Hello from Eyun"
}bash
curl -X POST '{BASE_URL}/sendText' \
-H 'Authorization: Bearer <你的调用凭证>' \
-H 'Content-Type: application/json' \
--data-raw '{
"wId": "0000016e-63eb-f319-0001-ed01076abf1f",
"wcId": "filehelper",
"content": "Hello from Eyun"
}'python
import requests
url = "{BASE_URL}/sendText"
headers = {"Authorization": "Bearer <你的调用凭证>", "Content-Type": "application/json"}
body = """{
"wId": "0000016e-63eb-f319-0001-ed01076abf1f",
"wcId": "filehelper",
"content": "Hello from Eyun"
}"""
resp = requests.post(url, headers=headers, data=body.encode("utf-8"))
print(resp.text)java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
String url = "{BASE_URL}/sendText";
String body = "{\n" +
" \"wId\": \"0000016e-63eb-f319-0001-ed01076abf1f\",\n" +
" \"wcId\": \"filehelper\",\n" +
" \"content\": \"Hello from Eyun\"\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());php
<?php
$url = '{BASE_URL}/sendText';
$body = <<<'JSON'
{
"wId": "0000016e-63eb-f319-0001-ed01076abf1f",
"wcId": "filehelper",
"content": "Hello from Eyun"
}
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;成功响应
json
{
"code": "1000",
"message": "处理成功",
"data": {
"type": 1,
"msgId": 2562652205,
"newMsgId": 4482117376572170921,
"createTime": 1641457769,
"wcId": "filehelper"
}
}错误响应
json
{
"code": "1001",
"message": "发送文本消息失败",
"data": {
"respRet": -24
}
}使用建议
- 首次接入先发到
filehelper,确认wId、调用凭证和网络正常。 - 文本适合通知、客服回复和简单指令;图片、文件、链接请用对应接口。
- 高频发送时按
wId做队列和限速。
验证与排查
| 场景 | 处理方式 |
|---|---|
| 首次联调 | 发到 filehelper,手机微信能看到消息即链路正常 |
| 返回成功但目标没收到 | 检查 wId 是否在线,目标 wcId 是否正确 |
message 是「wId已注销或二维码失效,请重新登录」 | wId 填错了,或这个账号已掉线,重新登录后用新的 wId |
| 返回失败 | 看 data.respRet,按 发送错误码 处理 |
| 高频发送 | 参考 API 使用与安全 配置队列和限速 |