Wechat.prototype.fetchAccessToken = function() {
var that = this;
if (this.access_token && this.expires_in) {
if (this.isValidAccessToken(this)) {
return Promise.resolve(this)
}
}
return this.getAccessToken()
.then(function(data) {
try {
data = JSON.parse(data);
} catch (e) {
return that.updateAccessToken()
}
if (that.isValidAccessToken(data)) {
return Promise.resolve(data)
} else {
return that.updateAccessToken()
}
})
.then(function(data) {
that.access_token = data.access_token;
// console.log(12312312312)
that.expires_in = data.expires_in;
that.saveAccessToken(data);
return Promise.resolve(data);
})
.catch(function(err) {
reject(err)
})
}