回答
你可以在 Hamibot 中通过 API 推送消息功能,将收益明细发送到指定设备。以下是具体配置方法:
1. 使用 REST API 发送消息
通过调用 Hamibot 提供的 REST API,你可以从外部系统(如服务器)向指定设备推送消息,例如收益明细。
请求地址:
POST https://api.hamibot.com/v1/devices/设备_id/messages
请求头:
Authorization: 你的令牌(hmp 开头)Content-Type: application/json
请求体参数:
| 参数名 | 类型 | 描述 |
|---|---|---|
| title | string | 消息标题,最大长度 128 |
| text | string | 消息内容,最大长度 512 |
示例代码(JavaScript):
// 文档地址 https://docs.hamibot.com/
http.request('https://api.hamibot.com/v1/devices/设备_id/messages', {
method: 'POST',
contentType: 'application/json',
headers: {
authorization: 'hmp_xxxxxxxxxxxxxxxx', // 替换为你的实际令牌
},
body: JSON.stringify({
title: '收益明细通知',
text: '今日收益:¥150.50\n订单数:3\n时间:2025-12-03',
}),
});
使用 curl 示例:
curl -X POST \
-H "Authorization: hmp_xxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"title": "收益明细通知",
"text": "今日收益:¥150.50\n订单数:3\n时间:2025-12-03"
}' \
https://api.hamibot.com/v1/devices/设备_id/messages
注意:请将
设备_id和hmp_xxxxxxxxxxxxxxxx替换为你在 Hamibot 控制台获取的实际值。
2. 在脚本中直接发送通知
如果你希望在脚本运行时主动上报收益信息,可以直接使用上述 API 调用。
例如,在完成某个任务后发送收益汇总:
function sendEarnings(earnings, orders) {
var title = '收益报告';
var text = '本次收益:¥' + earnings.toFixed(2) +
'\n完成订单数:' + orders +
'\n时间:' + new Date().toLocaleString();
http.request('https://api.hamibot.com/v1/devices/你的设备_id/messages', {
method: 'POST',
contentType: 'application/json',
headers: {
authorization: 'hmp_xxxxxxxxxxxxxxxx',
},
body: JSON.stringify({ title: title, text: text })
});
}
// 示例调用
sendEarnings(85.3, 2);
获取设备 ID 和 API 令牌
- 登录 Hamibot 控制台
- 进入「设备」页面,复制目标设备的
_id - 进入「设置」→「API 令牌」,创建或复制已有的令牌
这样就可以实现定期或触发式推送收益明细了。
ℹ️ 本回答由 AI 生成,内容仅供参考