-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
38 lines (28 loc) · 833 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict';
const debug = require('debug')('koa-weixin-token');
const Weixin = require('./weixin');
exports = module.exports = (opt) => {
var weixin = new Weixin(opt);
debug('options', opt);
return function* weixinToken(next){
define(this);
yield* next;
};
function define(ctx){
var context = ctx.context || ctx
var response = ctx.response
var request = ctx.request
context.__defineGetter__('weixinToken', function () {
return weixin.getToken();
})
response.__defineGetter__('weixinToken', function () {
return this.ctx.weixinToken;
})
context.__defineGetter__('weixinJsApiTicket', function () {
return weixin.getTicket();
})
response.__defineGetter__('weixinJsApiTicket', function () {
return this.ctx.weixinJsApiTicket;
})
}
};