猿问

获取微信token时终端中报错ReferenceError: fasle is not defined

import request from 'request-promise'

const base = 'https://api.weixin.qq.com/cgi-bin/'

const api = {

accessToken: base + 'token?grant_type=client_credential'

}

export default class Wechat {

constructor(opts){

this.opts = Object.assign({}, opts)

this.appID = opts.appID

this.getAccessToken = opts.getAccessToken

this.saveAccessToken = opts.saveAccessToken

this.fetchAccessToken()

}

async request (options){

options = Object.assign({}, options, {json:true})

try {

const response = await request(options)

    console.log(response)

    return response

} catch (error) {

console.error(error)

}

}

async fetchAccessToken () {

let data = await this.getAccessToken()

if(!this.isValidAccessToken(data)){

data = await this.updateAccessToken()

}

await this.saveAccessToken(data)

return data

}

async updateAccessToken () {

 

  const url = api.accessToken + '&appid=' + this.appID + '&secret=' + this.appSecret

       const data = await this.request({url: url})

       const now = (new Date().getTime())

       const expiresIn = now + (data.expires_in - 20) * 1000

       data.expires_in = expiresIn

       return data

    }

     isValidAccessToken (data) {

if (!data || !data.access_token || !data.expires_in) {

return fasle

}

const expiresIn = data.expires_in

const now = (new Data().getTime())

if (now < expiresIn) {

return true

} else {

return fasle

}

  }

}   


慕仙3125880
浏览 1837回答 1
1回答

QQ_随意

if (now < expiresIn) {return true} else {return fasle}return falsefalse 拼错了
随时随地看视频慕课网APP
我要回答