小程序检测用户是否授权过

isLogin() {
      uni.login({
        provider: "weixin",
        success: (res) => {
          this.$require({
            url: "xxxxxxx",
            data: {
              code: res.code,
            },
          }).then((res) => {
            
            if (res.code == 2 || res.code == 0) {
              getApp().globalData.isLogin = false;
              uni.setStorageSync("isLogin", "false"); //appid
            } else {
              getApp().globalData.isLogin = true;
              uni.setStorageSync("userId", res.data.userId); //appid
              uni.setStorageSync("username", res.data.nickName); //appid
              uni.setStorageSync("userImg", res.data.avatarUrl); //appid
              uni.setStorageSync("isLogin", "true"); //appid
            }
          });
        },
      });
    },

  

posted @ 2022-04-08 09:19  小万子呀  阅读(275)  评论(0编辑  收藏  举报