danni-cool/wechatbot-webhook

日志中一直报错 `[ERROR] - uncaughtException SyntaxError: Unexpected end of JSON input`

Closed this issue · 5 comments

完整的报错堆栈如下:

wxBotWebhook  | [2024-01-09T03:16:42.295] [ERROR] - uncaughtException SyntaxError: Unexpected end of JSON input
wxBotWebhook  |     at JSON.parse (<anonymous>)
wxBotWebhook  |     at Response.json (/app/node_modules/.pnpm/node-fetch-commonjs@3.3.2/node_modules/node-fetch-commonjs/index.js:707:15)
wxBotWebhook  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
wxBotWebhook  |     at async handleResSendMsg (/app/src/service/msgSender.js:546:20)

收消息api返回的json是不是有问题

收消息api返回的json是不是有问题

是的,群聊消息的 source 还好,但是单人聊天的消息好像都不是 json:

{"room":"","to":{"_events":{},"_eventsCount":0,"id":"@6052a464bcbc260467b1a0c94a66c9ab123fc96b0284ab3249b06bc6a81d5de7","payload":{"alias":"","avatar":"/cgi-bin/mmwebwx-bin/webwxgeticon?seq=1607669353&username=@60a464bcbc260467b1a0c94a66c9ab123fc96b0284ab3249b06bc6a81d5de7&skey=@crypt_9b7c5b22_8d5c756b29b2b4308072f7e2d43a6fa6","friend":false,"gender":1,"id":"@6052a464bcbc260467b1a0c94a66c9ab123fc96b0284ab3249b06bc6a81d5de7","name":"莨上指","phone":[],"signature":"头顶怎么绿油油的。。。","star":false,"type":1}},"from","_eventsCount":0,"id":"@5375678211d37207b7149a322f5a85ea","payload":{"address":"","alias":"","avatar":"/cgi-bin/mmwebwx-bin/webwxgeticon?seq=718060045&username=@5375678211d37207b7149a322f5a85ea&skey=","city":"","friend":true,"gender":1,"id":"@5375678211d37207b7149a322f5a85ea","name":"ʚDayday🥱ɞ","phone":[],"province":"Colima","signature":"一起学习吗?我老婆萝莉音","star":false,"weixin":"","type":1}}}
{"room":"","to":{"_events":{},"_eventsCount":0,"id":"@6052a464bcbc260467b1a0c94a66c9ab123fc96b0284ab3249b06bc6a81d5de7","payload":{"alias":"","avatar":"/cgi-bin/mmwebwx-bin/webwxgeticon?seq=1607669353&username=@6052a464bcbc260467b1a0c94a66c9ab123fc96b0284ab3249b06bc6a81d5de7&skey=@crypt_9b7c5b22_8d5c756b29b2b4308072f7e2d43a6fa6","friend":false,"gender":1,"id":"@6052a464bcbc260467b1a0c94a66c9ab123fc96b0284ab3249b06bc6a81d5de7","name":"莨上指","phone":[],"signature":"头顶怎么绿油油的。。。","star":false,"type":1}},"fr:{},"_eventsCount":0,"id":"@5375678211d37207b7149a322f5a85ea","payload":{"address":"","alias":"","avatar":"/cgi-bin/mmwebwx-bin/webwxgeticon?seq=718060045&username=@5375678211d37207b7149a322f5a85ea&skey=","city":"","friend":true,"gender":1,"id":"@5375678211d37207b7149a322f5a85ea","name":"ʚDayday🥱ɞ","phone":[],"province":"Colima","signature":"一起学习吗?我老婆萝莉音","star":false,"weixin":"","type":1}}}

看上去是从 from 那里开始有问题,我发 “你好”,from 那里 少了 {,我发 “nihao”,from 直接变成了 fr

收消息api返回的json是不是有问题

我明白你的说的意思了,要返回 json 串给收消息的 api 的请求

可以返回或者不返回,但是返回的话必须是json

明白了!多谢!