weixin-token for koa.
npm install koa-weixin-token
const Koa = require('koa');
const app = new Koa();
app.use(require('koa-weixin-token')({
appid: 'YOUR_WEIXIN_APPID',
secret: 'YOUR_WEIXIN_SECRET'
}));
app.use(funciton* (){
this.body = {
token: this.weixinToken,
jsapiTicket: this.weixinJsApiTicket
};
});
app.use(funciton* (){
this.body = {
token: this.weixinToken,
jsapiTicket: this.weixinJsApiTicket
};
});
const Weixin = require('koa-weixin-token/weixin');
var weixin = new Weixin({
appid: 'YOUR_WEIXIN_APPID',
secret: 'YOUR_WEIXIN_SECRET'
});
weixin.on('token', function(token, expire){
console.log('token', token, expire, this.getToken());
}).on('ticket', function(token, expire){
console.log('ticket', token, expire, this.getTicket());
});