위 챗 애플 릿 token 만 료 후 다시 가 져 오기
                                            
 3207 단어  애플 릿
                    
class Config{
  constructor() {
  }
}
Config.restUrl = 'https://wx.knowdao.com';
export { Config };
또 다른 봉 인 된 공용 토 큰 의 js 에서 이 모듈 로 들 어 옵 니 다.
import { Config } from 'config.js';
class Token {
  constructor() {
    console.log(this)
    this.verifyUrl = Config.restUrl + '/api/validate/token';
    this.tokenUrl = Config.restUrl + '/api/login/get_openid';
  }
  verify() {
    var token = wx.getStorageSync('token');
    console.log(token)
    if(!token) {
      this.getTokenFromServer(token);
    }else{
      this._verifyFromServer(token);
    }
  }
  //             
  _verifyFromServer(token) { 
    console.log(11212)
    var that = this;
    const account = wx.getStorageSync("account")
    // console.log(token)
    // console.log(wx.getStorageSync("token"))
    // console.log(account)
    const tokenn = wx.getStorageSync("token")
    wx.request({
      url: that.verifyUrl,
      method: 'POST',
      data: {
        token: tokenn,
        account:account
      },
      success: function (res) {
        console.log(res)
        return false
        var valid = res.data.isValid;
      
        if (!valid) {
          that.getTokenFromServer();
        }
      }
    })
  }
  //       token
  getTokenFromServer(callback) {
    var that = this;
    wx.login({
      success: function(res) {
        let code = res.code
        wx.getUserInfo({
          lang: "zh_CN",
          success: res => {
            let userInfo = res.userInfo
            wx.request({
              url: that.tokenUrl,
              method: 'POST',
              data: {
                code: code,
                nickname: userInfo.nickName,
                gender: userInfo.gender,
                avatarUrl: userInfo.avatarUrl,
                city: userInfo.city
              },
              header: {
                "content-type": "application/x-www-form-urlencoded",
                'content-type': 'application/json'
              },
              success: function (res) {
                console.log(res)
                wx.setStorageSync('token', res.data.data.token);
                wx.setStorageSync('account', res.data.data.account);
                wx.setStorageSync('userid', res.data.data.user_id);
              }
            })
          }
        })
        
      }
    })
  }
  
}
export { Token };
마지막 으로 app. js 에서 호출
import { Token } from 'utils/token-model.js';
var scence = 0;
App({
  onLaunch: function () {
    var token = new Token();
    token.verify();
    // token.changlink("wss://wx.knowdao.com/system");
  },
 
  onShow: function () {
  },
  onHide: function () {
    this.globalData.scence = 1
    wx.setStorageSync('scence', this.globalData.scence)
  },
  globalData: {
    account: '',
    stroge: 0,
    openid: 0,
    userInfo: null,
    times: null,
    urls: 'https://wx.knowdao.com',
    urlst: 'http://test.knowdao.com',
    token: ''
  }
})
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
애플 릿 이미지 새로 고침, nginx 재 작성 url 제거 인자이전에 nginx 로 이미지 서버 를 만 들 었 는데 전단 에 작은 프로그램 을 사 용 했 습 니 다. 작은 프로그램 이 출시 된 후에 그림 이 새로 고침 되 지 않 는 것 을 발 견 했 습 니 다. 조사 한 결과 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.