微信小程序判断如何是否授权

2024-11-02 23:32:50

1、微信小程序的授权为了用户体验所以如果用户一直拒绝,到后面授权框都不出现了,所以必须的自己想办法解决。当然啦,这里也是提醒大家要做好用户体验,可是在企业有时候小程序就是需要用户的信息时,就需要一直显示授权并友好引导用户允许授权。

微信小程序判断如何是否授权

3、if (result.authSetting['scope.' + scopeType]) {_this.globalData.authType[scopeType] = true;fun();} else {wx.authorize({scope: 'scope.' + scopeType,success(res) {_this.globalData.authType[scopeType] = true;fun();},fail() {wx.showModal({title: '提示',content: '请允许授权以便为你提供更好的服务',showCancel:false,success:function(){wx.openSetting({success: (res) => {if (res.authSetting['scope.' + scopeType]) {_this.globalData.authType[scopeType] = true;fun();} else {_this.globalData.authType[scopeType] = false;_this.validateAuthorize(scopeType, fun);}},fail() {_this.globalData.authType[scopeType] = false;_this.validateAuthorize(scopeType, fun);}});}})}});}}})}

微信小程序判断如何是否授权

5、用法:var _this = this;if (!app.globalData.authType.userInfo) {app.validateAuthorize('userInfo', function () {app.wxCheckLogin(function () {_this.onLoad();_this.onShow();});});} else {app.wxCheckLogin(function () {_this.onLoad();_this.onShow();});}以上代码就是先判断用户是否授权,如果授权了就检查登录,如果没有授权则需要先授权,然后在检查登录的情况,回调函数里面就是刷新当前页面的数据信息。

微信小程序判断如何是否授权
猜你喜欢