微信小程序授权与拒绝授权处理

微信小程序授权及拒绝授权处理

微信小程序授权种类很多,但模式都基本一致,只是参数不同,本次拒绝处理适用于各种授权

小程序授权方法不理解的可以看官网,判断是否授权,等介绍的比较详细

```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)
                
              })
            }
          })
        }
      }
    })

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值