0.2.0 • Published 10 years ago

wechat-koa v0.2.0

Weekly downloads
5
License
ISC
Repository
github
Last release
10 years ago

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

0.2.0

10 years ago

0.1.9

10 years ago

0.1.8

10 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.10

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago