当前位置:   article > 正文

微信小程序token失效刷新token_微信小程序本地token丢失

微信小程序本地token丢失

微信小程序token失效刷新token

app.js

//换取新token
    var tokentime = wx.getStorageSync('tokentime');//过期时间
    let newTime = Date.parse(new Date());// 当前时间
    var token = wx.getStorageSync('token');
    if (!token)
    {
      return;
    }
    if (newTime > tokentime) {
      var newTokenTime = 24 * 3600 * 10;//过期时间10天
      wx.request({
        url: this.globalData.userUrl + 'api/auth/refresh?token='+token+'',
        method: "GET",
        success: function (res) {
          if (!res.data.message)
          {
            wx.setStorageSync('token', res.data.data.token);
            wx.setStorageSync('tokentime', Date.parse(new Date() + newTokenTime));
          }

          var token2 = wx.getStorageSync('token');

          console.log('新token', token2); 


        }
      });
    }
  • 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

有什么问题欢迎评论留言,我会及时回复你的

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/473933
推荐阅读
相关标签
  

闽ICP备14008679号