微信小程序授权及拒绝授权处理
微信小程序授权种类很多,但模式都基本一致,只是参数不同,本次拒绝处理适用于各种授权
小程序授权方法不理解的可以看官网,判断是否授权,等介绍的比较详细
```javascript
var _this = this
wx.getSetting({
success(res) {
if (!res.authSetting['scope.writePhotosAlbum']) {
wx.authorize({
scope: 'scope.writePhotosAlbum',
success() {
// 用户已经同意小程序使用录音功能,后续调用 wx.startRecord 接口不会弹窗询问
// wx.startRecord()
wx.saveImageToPhotosAlbum({ // 下载成功后再保存到本地
filePath: _this.data.popImg, //返回的临时文件路径,下载后的文件会存储到一个临时文件
success() {
// _this.sharePop = !_this.sharePop
_this.setData({
baocun: 1
})
console.log(api.FORWARPYQ)
wx.showToast({
title: '图片保存成功',
icon: 'none',
duration: 2000
})
api.Cpic_Ajax({
url: api.FORWARPYQ,
showLoading: false,
param: {
openId: wx.getStorageSync("useropenid"),
}
}).then(function (e) {
console.log(e);
// if (e.errorResult.code == 1) {
setTimeout(function () {
_this.getupmoney(false);
}, 3000)
})
}
})
},
fail(err) {
console.log(err)
// 这边微信做过调整,必须要在按钮中触发,因此需要在弹框回调中进行调用
wx.showModal({
title: '提示',
content: '需要您授权保存相册',
showCancel: true,
success: modalSuccess => {
console.log(modalSuccess)
if (modalSuccess.confirm) {
wx.openSetting({
success(settingdata) {
console.log("settingdata", settingdata)
if (settingdata.authSetting['scope.writePhotosAlbum']) {
wx.showModal({
title: '提示',
content: '获取权限成功,再次点击图片即可保存',
showCancel: false,
})
} else {
wx.showModal({
title: '提示',
content: '获取权限失败,将无法保存到相册哦~',
showCancel: false,
})
}
// }
},
fail(failData) {
console.log("failData", failData)
},
complete(finishData) {
console.log("finishData", finishData)
}
})
}
}
})
}
// }
})
} else {
wx.saveImageToPhotosAlbum({ // 下载成功后再保存到本地
filePath: _this.data.popImg, //返回的临时文件路径,下载后的文件会存储到一个临时文件
success() {
// _this.sharePop = !_this.sharePop
_this.setData({
baocun: 1
})
console.log(api.FORWARPYQ)
wx.showToast({
title: '图片保存成功',
icon: 'none',
duration: 2000
})
api.Cpic_Ajax({
url: api.FORWARPYQ,
showLoading: false,
param: {
openId: wx.getStorageSync("useropenid"),
}
}).then(function (e) {
console.log(e);
setTimeout(function () {
_this.getupmoney(false);
}, 3000)
})
}
})
}
}
})