diff --git a/adapters/wecom/src/bot.ts b/adapters/wecom/src/bot.ts index 378b0236..1db41b52 100644 --- a/adapters/wecom/src/bot.ts +++ b/adapters/wecom/src/bot.ts @@ -8,16 +8,18 @@ export class WecomBot extends Bot { // internal: Internal refreshTokenTimer: NodeJS.Timeout logger = new Logger('wecom') + constructor(ctx: Context, config: WecomBot.Config) { super(ctx, config) + this.selfId = config.agentId + this.platform = 'wecom' this.http = ctx.http.extend(config) // this.internal = new Internal(this.http, this) ctx.plugin(HttpServer, this) } - // @ts-ignore - stop(): Promise { + async stop() { clearTimeout(this.refreshTokenTimer) } @@ -129,5 +131,3 @@ export namespace WecomBot { Quester.createConfig('https://qyapi.weixin.qq.com/'), ]) } - -WecomBot.prototype.platform = 'wecom' diff --git a/adapters/wecom/src/http.ts b/adapters/wecom/src/http.ts index abc9ac5e..0959e0ee 100644 --- a/adapters/wecom/src/http.ts +++ b/adapters/wecom/src/http.ts @@ -11,9 +11,6 @@ export class HttpServer extends Adapter.Server { } async start(bot: WecomBot) { - bot.selfId = bot.config.agentId - bot.platform = 'wecom' - await bot.refreshToken() const self = await bot.getSelf() bot.avatar = self.avatar @@ -48,7 +45,7 @@ export class HttpServer extends Adapter.Server { if (data.Encrypt) { const localSign = getSignature(localBot.config.token, timestamp?.toString(), nonce?.toString(), data.Encrypt) if (localSign !== msg_signature) return ctx.status = 403 - const { message, id } = decrypt(bot.config.aesKey, data.Encrypt) + const { message } = decrypt(bot.config.aesKey, data.Encrypt) // if (id !== localBot.config.appid) return ctx.status = 403 const { xml: data2 } = await xml2js.parseStringPromise(message, { explicitArray: false, diff --git a/adapters/wecom/src/utils.ts b/adapters/wecom/src/utils.ts index 681d1b08..96dfa939 100644 --- a/adapters/wecom/src/utils.ts +++ b/adapters/wecom/src/utils.ts @@ -1,6 +1,7 @@ import { Message } from './types' import { WecomBot } from './bot' import { h } from '@satorijs/satori' + export async function decodeMessage(bot: WecomBot, message: Message) { const session = bot.session() session.timestamp = message.CreateTime * 1000