跳转到主要内容

连接

生成二维码

与 API 通信的起点是生成二维码。一旦生成二维码,您可以使用移动设备扫描它,以启用 API 与您的系统之间的消息交换。

命令generate_qrcode.aspx
方法POST
主体
{ 
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)..."
}

user_agent 根据您的浏览器提供完整的 UserAgent 字符串。

响应

成功 → 返回 SVG base64 格式的二维码图像:

{
"qr": "data:image/svg+xml;base64,PD94b...",
"status":1,
"error":"",
"ttl":20
}

错误 → 返回描述的错误:

{
"status": 0,
"error": "Connection already established",
"ttl": 0
}

一旦设备扫描二维码,将通过 PostBack URL 返回一系列事件:

连接状态

命令status.aspx
方法GET
响应

连接信息:

{
"status": 10, // 状态码
"statusString": "WhatsAppAuthenticated", // 连接状态的文本描述
"connected": true, // 是否已连接 (true) 或未连接 (false)
"ConnectionInfo": {
"lg": "en",
"lc": "US",
"phone": {
"device_model": "iPhone 4S",
"wa_version": "2.21.10.25",
"mcc": "724",
"os_version": "9.3.5",
"os_build_number": "undefined",
"device_manufacturer": "Apple",
"mnc": "031"
},
"battery": 83,
"tos": 0,
"pushname": "Atendimento Maria",
"protoVersion": [
0,
17
],
"plugged": false,
"platform": "iphone",
"wid": "5511987654321@s.whatsapp.net",
"connected": true,
"isResponse": "false",
"binVersion": 10,
"locales": "en-US,pt-BR"
},
"WebID": "6D6307C3-2973-4468-85FA-D047CB8E1F2E",
"Webhook": "http://my-erp.com.br&wid=6D6307C3-2973-4468-85FA-D047CB8E1F2E",
"UserAgent": "Chrome",
"CanRestoreConnection": true, // 如果可以恢复连接则为 true(无需二维码)
"stats": {
"Contacts": 72,
"Chats": 32,
"SentBytes": 0,
"ReceveidBytes": 0
},
"storage": {
"Name": "6D6307C3-2973-4468-85FA-D047CB8E1F2E",
"Bytes": 15544238,
"Files": 107,
"Subs": [
{
"Name": "media",
"Bytes": 11817360,
"Files": 27,
"Subs": null
},
{
"Name": "profile",
"Bytes": 1843594,
"Files": 52,
"Subs": null
},
{
"Name": "thumb",
"Bytes": 224238,
"Files": 27,
"Subs": null
}
]
}
}

状态码及其字符串等价物:

IntString
0noConnection
1webSocketOpenining
2webSocketOpen
3waitForQRAuthentication
4Starting
10WhatsAppAuthenticated
11WhatsAppAuthenticatedConnectionClosed
13WhatsAppNotAuthenticated

断开连接

完全断开与 WhatsApp 的连接(必须重新生成二维码)。

命令disconnect.aspx
方法GET
响应

成功 → 连接信息:

    {
"status": 0,
"statusString": "noConnection",
"connected": false,
...
}

结束会话

部分断开与 WhatsApp 的连接(可以使用 restore_session.aspx 命令重新连接)。

命令close_session.aspx
方法GET
响应

成功 → 连接信息:

{
"sucesso": true,
"Status": "{\"status\":0,\"statusString\":\"noConnection\"..."
}

保存会话

保存当前连接状态并允许重新连接。这在扫描二维码后会自动执行。

命令save_session.aspx
方法GET
响应

成功:

{
"sucesso": true
}

恢复会话

恢复之前结束的会话(使用 close_session.aspx 命令)。

命令restore_session.aspx
方法GET
响应

成功 → 连接信息:

{
"sucesso": true,
"Status": "{\"status\":10,\"statusString\":\"WhatsAppAuthenticated\"..."
}

清除实例

完全清除保存的实例数据。重置存储的文件和缓存。(不影响 WhatsApp 数据)

命令clear.aspx
方法GET
响应
{
"status": true,
"message": "clear ok"
}

更新设置

更新连接设置。

重要!

如果您使用 set_config.aspx 命令更改 WebHook,通过浏览器使用系统将停止工作

如果您想同时使用两种方法(浏览器和 API),请考虑通过系统管理界面更改 WebHook(访问管理区域 > 编辑实例 > API > PostBack URL)。

命令set_config.aspx
方法POST
主体
{ 
"webhook": "https://my-system.com/newWebHook", // 事件返回 URL
"user_agent" : "Opera", // 设置使用的浏览器
"APIVersionCanBulk": false, // 启用 BULK 返回
"APIVersion": "1.0" // 设置 API 版本
}
响应

成功 → 返回连接数据:

{
"status": 10,
"statusString": "WhatsAppAuthenticated",
"connected": true,
"Webhook": "https://my-system.com/newWebHook",
"UserAgent": "Opera",
...
}