今天做小程序关于发票那一块的接口,发现用户拒绝授权后,再次发起后wx.authorize 不生效,说白了就是没有授权页面了。解决思路:wx.authorize 不生效的话我们可以考虑自己弄个弹出层,提醒用户手动授权wx.openSetting,逻辑判断:1.如果用户“允许”,则调用微信发票接口wx.chooseInvoiceTitle。2.如果用户“拒绝”,则跳出弹出框用户手动设置权限: 2.1用户“授权”:则跳转设置页面,调用wx.openSetting,当用户勾选“发票抬头”,则调用wx.chooseInvoiceTitle 2.2用户“不授权”:则显示一段提示:下面上代码//调用发票功能bindCountryChange: function(e) { var that = this; //获取用户授权 wx.getSetting({ success(res) { //用户是否授权发票 if (!res.authSetting[‘scope.invoiceTitle’]) { //发起用户授权 wx.authorize({ scope: ‘scope.invoiceTitle’, success() { //授权成功,调用微信发票接口 that.toInvoiceTitle(); }, fail(){ //用户拒绝授权 自定义弹窗 wx.showModal({ title: ‘温馨提示’, content: ‘发票功能需要您的微信授权才能使用’, cancelText: “不授权”, confirmText: “授权”, confirmColor: “#a08250”, success: function (res) { if (res.confirm) { // 这个 API 是基础库 1.1.0 才有的,所以需要做兼容处理: if (wx.openSetting) { wx.openSetting({ //进入授权设置页面手动授权 success: function (res) { that.toInvoiceTitle(); } }) } //低版本兼容 做提示操作 else { wx.showModal({ title: ‘授权提示’, content: ‘发票功能需要您的微信授权才能使用,错过授权页面的处理方法:删除小程序->重新搜索进入->点击授权按钮’ }) } } //用户继续拒绝授权。 else if (res.cancel) { wx.showModal({ title: ‘温馨提示’, content: ‘发票获取失败,错过授权页面的处理方法:删除小程序->重新搜索进入->点击授权按钮’, showCancel: false, confirmColor: “#21C5B4”, success: function (res) { } }) } } }) console.log(res); } }) } else { //用户已授权 that.toInvoiceTitle(); } }, fail: function(res) { console.log(res) } }) }, //微信发票功能调用 toInvoiceTitle: function(){ wx.chooseInvoiceTitle({ success: res => { //将发票选中值绑定自己的初始对象 this.setData({ “invoiceInfo”: res, “countryIndex”: res.type }) //异步存入本地缓存 wx.setStorageSync(“invoiceType”, this.data.countryIndex); wx.setStorageSync(“invoiceInfo”, res); }, fail: function (res) { console.log(res) } }) },以上只是作为小程序刚入门的一点心得,如果有更好的处理方法,希望大家留言告知,小弟不胜感激小程序
微信小程序用户拒绝授权后处理方式
未经允许不得转载:E企盈小程序开发-热线:4006-838-530 » 微信小程序用户拒绝授权后处理方式
最新评论
不错的小程序案例
优秀的团队,不错的服务!
讲的很好
主播长的帅气
好系统好服务
优秀的团队
好服务,值得信赖
不错的服务