微信小程序授权方法全能,当用户拒绝或者首次进来的,都可以弹起授权提示,主要是用wx.getSetting,还有wx.authorize,最后的wx.openSetting...

我这里就用获取微信授权运动步数的接口做案例,简单通过,也试过使用微信保存图片授权上,

代码如下: 

wx.getSetting({ success: res => {
        if(!res.authSetting['scope.werun']){
          wx.authorize({
            scope: 'scope.werun', // 代表的是打开步数的
// 如果你是封装是用户授权也行 拒绝了也可以弹起
            success: res => {
              wx.getWeRunData({ success: res => {
                  console.log(res)
                } 
              });
            },
            fail: () => {
              // 打开设置面  用户拒绝
              if(res.authSetting['scope.writePhotosAlbum'] == undefined){
                wx.showToast({
                  title: '授权失败', //提示的内容,
                  icon: 'none', //图标,
                  duration: 2000, //延迟时间,
                });
              }else {
        //提示一下这里官方文档说必须是弹出带有确定取消的窗口才可以 官方链接 https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html wx.showModal({ title:
'提示', //提示的标题, content: '确定授权保存图片?', //提示的内容, showCancel: true, //是否显示取消按钮, cancelText: '取消', //取消按钮的文字,默认为取消,最多 4 个字符, cancelColor: '#000000', //取消按钮的文字颜色, confirmText: '确定', //确定按钮的文字,默认为取消,最多 4 个字符, confirmColor: '#3CC51F', //确定按钮的文字颜色, success: res => { if (res.confirm) { console.log('用户点击确定') wx.openSetting({ success: res => { wx.getWeRunData({ success: res => { console.log(res) } });
                 } }); }
else if (res.cancel) { console.log('用户点击取消') } } }); } }, complete: () => {} }); } } });

这是一个小小的案例

有道词典
wx.getWeRunData ...
详细 X
  wx。getWeRunData({成功:res = > {   console.log (res)   }   });

转载于:https://www.cnblogs.com/PinkYun/p/10548570.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值