'use strict'
var Promise = require('bluebird')
var request = Promise.promisify(require('request'))
var util = require('./util')
var prefix = 'https://api.weixin.qq.com/cgi-bin/'
var api = {
accessToken: prefix + 'token?grant_type=client_credential'
}
function Wechat(opts) {
var that = this
this.appID = opts.appID
this.appSecret = opts.appSecret
this.getAccessToken = opts.getAccessToken
this.saveAccessToken = opts.saveAccessToken
this.getAccessToken()
.then(function(data) {
try {
data = JSON.parse(data)
}
catch(e) {
return that.updataAccessToken()
}
if (that.isValidAccessToken(data)) {
Promise.resolve(data)
}
})
.then(function(data) {
that.access_token = data.access_token
that.expires_in = data.expires_in
that.saveAccessToken(data)
})
}
this.appID中的this是指哪个= =?
相关分类