This commit is contained in:
2025-11-30 21:32:01 +08:00
parent b7f1095e4a
commit d4ff2862bd
11 changed files with 413 additions and 34 deletions

View File

@@ -4,8 +4,9 @@ import xml2js from 'xml2js';
import { useContextKey } from '@kevisual/context';
import { Redis } from 'ioredis';
import http from 'node:http';
import { Wx, parseWxMessage } from './wx/index.ts';
import { Wx, WxMsgEvent, parseWxMessage } from './wx/index.ts';
import { config } from './modules/config.ts';
import { loginByTicket } from './wx/login-by-ticket.ts';
export const simpleRouter: SimpleRouter = await useContextKey('router');
export const redis: Redis = await useContextKey('redis');
@@ -74,7 +75,13 @@ simpleRouter.post('/api/wxmsg', async (req: http.IncomingMessage, res: http.Serv
const { fromusername, msgtype } = msg;
res.end('')
if (msgtype === 'event') {
console.log('Received event message');
const wxMsgEvent = msg as WxMsgEvent;
if (wxMsgEvent.eventkey?.includes?.('login')) {
await loginByTicket({
ticket: wxMsgEvent.ticket!,
openid: wxMsgEvent.fromusername,
});
}
return
}
if (fromusername) {