Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    wechat-koapublic

    wechat-koa

    基于生成器开发的微信公众平台组件,用于koa框架

    Installation

    $ npm install wechat-koa
    

    Example

    初始化对象

    var WechatKoa = require('wechat-koa');
    var wechatKoa = new WechatKoa({
      store: {type: 'mongo',url:'mongodb://127.0.0.1:27017/db'},
      appId: 'your appId',
      appSecret: 'your appSecret',
      token: 'your appToken'
    });
    

    微信验证方法

    function* signature() {
        if (this.req.url) {
          var echostr = wechatKoa.checkSignature(this.req.url)
          if (echostr) {
            this.body = echostr;
          } else {
            this.status = 500;
            this.body = "Bad Token!";
          }
        }
      }
    

    消息解析回复

    function* onWechatMsg(){
        var msg = yield wechatKoa.parse(postQuery);
        var responesMsg = {
          "toUserName":msg.FromUserName,
          "fromUserName":msg.ToUserName,
          "createTime":new Date().toTimeString(),
          "msgType":"text",
          "content":"reponse text"
        };
         this.type = 'application/xml'
        this.body = wechatKoa.build(responesMsg);
    }
    

    License

    MIT

    Keywords

    install

    npm i wechat-koa

    Downloadsweekly downloads

    42

    version

    0.2.0

    license

    ISC

    repository

    githubgithub

    last publish

    collaborators

    • avatar