Skip to content

断线重连微信实例 ​

手机端微信在线,但平台显示离线时,调用本接口尝试恢复连接。

接口地址: POST /reconnectWx

网络波动、代理 IP 不稳定导致下线时,也可以先调用本接口。只传 wcId;重连成功后 wId 不变,接着用原来的。仍未恢复时,再带原 wcId 重新扫码登录。

使用场景

适合处理“手机在线、平台离线”的短暂连接异常。它不是登录接口,不能替代重新扫码登录。

前置条件 ​

  • 当前请求已携带有效 Authorization。
  • 已保存需要恢复的微信 ID(wcId)。
  • 如使用代理 IP,先确认代理网络可用。

请求参数 ​

参数名必选类型说明
wcId是string需要重新连接的微信 ID

请求示例 ​

http
POST {BASE_URL}/reconnectWx
Authorization: Bearer <你的调用凭证>
Content-Type: application/json

{
  "wcId": "wxid_mdf1ha1xqpvs12"
}
bash
curl -X POST '{BASE_URL}/reconnectWx' \
  -H 'Authorization: Bearer <你的调用凭证>' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "wcId": "wxid_mdf1ha1xqpvs12"
}'
python
import requests

url = "{BASE_URL}/reconnectWx"
headers = {"Authorization": "Bearer <你的调用凭证>", "Content-Type": "application/json"}
body = """{
  "wcId": "wxid_mdf1ha1xqpvs12"
}"""

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}/reconnectWx";
String body = "{\n" +
    "  \"wcId\": \"wxid_mdf1ha1xqpvs12\"\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}/reconnectWx';
$body = <<<'JSON'
{
  "wcId": "wxid_mdf1ha1xqpvs12"
}
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;

响应参数 ​

参数名类型说明
codestring1000 成功;其他值都是失败,通常是 1001
messagestring反馈信息
dataobject / null返回数据,具体以接口实际响应为准

成功响应 ​

json
{
  "code": "1000",
  "message": "重连成功",
  "data": null
}

错误响应 ​

json
{
  "code": "1001",
  "message": "重连失败",
  "data": null
}

使用建议 ​

按以下顺序处理离线:

  1. 先调用 查询实例登录状态 确认平台侧状态。
  2. 手机在线、平台离线时,调用本接口恢复。
  3. 网络或代理不稳定时,先修复网络或代理,再调用本接口。
  4. 仍未恢复时,带原 wcId 重新扫码登录。

注意

不要在短时间内频繁重复调用本接口。若多次重连失败,应优先检查网络、代理 IP、微信实例状态和登录环境。