1.3.3 • Published 2 years ago

@use-services/wechatsub v1.3.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

WechatPub

// in services.ts
import * as WechatSub from "@use-services/wechatpub";

const options = {
  wechatsub: {
    init: WechatSub.init,
    args: {
        token: "",
        appId: "",
        encodingAESKey: "",
    },
  } as WechatSub.Option<WechatSub.Service>,
}

// in handlersManage.ts
export const wxpubNotifyGet: Handler<apiInner.WxpubNotifyGetReq> = async (req, ctx) => {
  const { wechatsub } = srvs;
  if (!wechatsub.checkSignature(ctx.query)) {
    ctx.body = "";
    return;
  }
  ctx.body(ctx.query.echostr);
};

export const wxpubNotifyPost: Handler<apiInner.WxpubNotifyPostReq> = async (req, ctx) => {
  const { wechatsub, logger, sql, redis, wxpub } = srvs;
  let msg: IncomeMsg;
  if (!wechatsub.checkSignature(ctx.query)) {
    ctx.body = "";
    return;
  }
  try {
    msg = await wechatsub.parse(ctx.request.body, ctx.query);
  } catch (err) {
    ctx.body = "";
    return;
  }
  if (msg.MsgType === "event") {
    const msg_ = msg as IncomeMsgEvent;
    if (msg_.Event === "subscribe") {
        // TODO
    }
  }
  ctx.body = "success";
};
1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago