Skip to content

Commit

Permalink
fix(wechat): fix unparsed body for xml
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jan 22, 2025
1 parent d93003a commit 5b21e61
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion adapters/wechat-official/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@satorijs/adapter-wechat-official",
"description": "Wechat Official Adapter for Satorijs",
"version": "2.4.2",
"version": "2.5.0",
"type": "module",
"main": "lib/index.cjs",
"typings": "lib/index.d.ts",
Expand Down
6 changes: 3 additions & 3 deletions adapters/wechat-official/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ export class HttpServer<C extends Context = Context> extends Adapter<C, WechatOf

bot.ctx.server.post('/wechat-official', async (ctx) => {
const { timestamp, nonce, msg_signature } = ctx.request.query
bot.logger.debug('%c', ctx.request.body)
let { xml: data }: {
xml: Message
} = await xml2js.parseStringPromise(ctx.request.body[Symbol.for('unparsedBody')], {
} = await xml2js.parseStringPromise(ctx.request.body, {
explicitArray: false,
})
const botId = data.ToUserName
const localBot = this.bots.find((bot) => bot.selfId === botId)
if (!localBot) return ctx.status = 403

if (data.Encrypt) {
const localSign = getSignature(localBot.config.token, timestamp?.toString(), nonce?.toString(), data.Encrypt)
Expand All @@ -52,8 +54,6 @@ export class HttpServer<C extends Context = Context> extends Adapter<C, WechatOf
data = data2
}

bot.logger.debug('%c', ctx.request.body[Symbol.for('unparsedBody')])

const session = await decodeMessage(localBot, data)

let resolveFunction: (text: string) => void
Expand Down
2 changes: 1 addition & 1 deletion adapters/wecom/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@satorijs/adapter-wecom",
"description": "Wecom Adapter for Satorijs",
"version": "2.4.3-alpha.0",
"version": "2.5.0",
"type": "module",
"main": "lib/index.cjs",
"typings": "lib/index.d.ts",
Expand Down
6 changes: 3 additions & 3 deletions adapters/wecom/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ export class HttpServer<C extends Context = Context> extends Adapter<C, WecomBot

bot.ctx.server.post('/wecom', async (ctx) => {
const { timestamp, nonce, msg_signature } = ctx.request.query
bot.logger.debug(ctx.request.body)
let { xml: data }: {
xml: Message
} = await xml2js.parseStringPromise(ctx.request.body[Symbol.for('unparsedBody')], {
} = await xml2js.parseStringPromise(ctx.request.body, {
explicitArray: false,
})
const botId = data.AgentID
const localBot = this.bots.find((bot) => bot.selfId === botId)
if (!localBot) return ctx.status = 403

if (data.Encrypt) {
const localSign = getSignature(localBot.config.token, timestamp?.toString(), nonce?.toString(), data.Encrypt)
Expand All @@ -52,8 +54,6 @@ export class HttpServer<C extends Context = Context> extends Adapter<C, WecomBot
data = data2
}

bot.logger.debug('%c', ctx.request.body[Symbol.for('unparsedBody')])

const session = await decodeMessage(localBot, data)
if (session) {
localBot.dispatch(session)
Expand Down

0 comments on commit 5b21e61

Please sign in to comment.