zoukankan      html  css  js  c++  java
  • 微信小程序授权方法全能,当用户拒绝或者首次进来的,都可以弹起授权提示,主要是用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)   }   });
  • 相关阅读:
    Linux下安装LoadRunner LoadGenerator
    Pytorch中的model.named_parameters()和model.parameters()
    Pytorch取最小或最大的张量索引
    Pytorch之permute函数
    softmax上溢和下溢
    Explainable ML
    ML对抗攻击
    Typora快捷键记录
    ubuntu查看目录大小
    在服务器之间传输文件
  • 原文地址:https://www.cnblogs.com/PinkYun/p/10548570.html
Copyright © 2011-2022 走看看