import { Request, Response } from 'express' import resFormatter from '../utils/responseFormatter' import hookRequest from '../api/hookRequest' import hookInitialize from '../api/hookInitialize' import servicesSendMsg from '../services/sendMsg' const delay = (ms: number): Promise => new Promise((resolve) => setTimeout(resolve, ms)) const module = { checkLogin: async (_req: Request, res: Response): Promise => { let accInfo try { const accInfoRes = await hookRequest.fetchGetAccInfo() accInfo = accInfoRes resFormatter.format(res, accInfo) } catch (error) { // resFormatter.error(res, error) console.log('连接6666失败,尝试注入--') } if (!accInfo) { try { await hookInitialize.initHook() await delay(1500) const data = await hookRequest.fetchGetAccInfo() if (data) { resFormatter.format(res, data) } } catch (error) { resFormatter.error(res, error) } } }, // 发送消息(文本) sendContent: async (_req: Request, res: Response): Promise => { try { if (_req.body && _req.body.wxRoomId && _req.body.content) { const responseData = await servicesSendMsg.sendMsgToWx({ msgType: 'txt', wxRoomId: _req.body.wxRoomId, msgContent: _req.body.content, taskInfo: { sceneType: 'send' } }) resFormatter.format(res, responseData) } else { resFormatter.error(res, '参数错误') } } catch (error) { resFormatter.error(res, error) } } } export default module