随笔 - 2649  文章 - 2452  评论 - 0  阅读 - 80424

wx.getSetting

wx.getSetting(Object object)

基础库 1.2.0 开始支持,低版本需做兼容处理

Promise 风格 调用:支持

小程序插件:支持,需要小程序基础库版本不低于 2.6.3

在小程序插件中使用时,接口有以下不同:

  • withSubscriptions 无效(插件暂无订阅消息)
  • 返回值中的 authSetting 字段中是插件的权限(如用户信息功能页授权)
  • 2.14.0 起返回值中有 miniprogramAuthSetting 字段,内容等于当前小程序 getSetting 的结果(不含订阅状态)

微信 Windows 版:支持

微信 Mac 版:支持

微信 鸿蒙 OS 版:支持

相关文档: 授权接口调用频率规范

功能描述

获取用户的当前设置。返回值中只会出现小程序已经向用户请求过的权限

参数

Object object

属性 类型 默认值 必填 说明 最低版本
withSubscriptions Boolean false 是否同时获取用户订阅消息的订阅状态,默认不获取。注意:withSubscriptions 只返回用户勾选过订阅面板中的“总是保持以上选择,不再询问”的订阅消息。 2.10.1
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数
complete function 接口调用结束的回调函数(调用成功、失败都会执行)

object.success 回调函数

参数
Object res
属性 类型 说明 最低版本
authSetting AuthSetting 用户授权结果
subscriptionsSetting SubscriptionsSetting 用户订阅消息设置,接口参数withSubscriptions值为true时才会返回。 2.10.1
miniprogramAuthSetting AuthSetting 在插件中调用时,当前宿主小程序的用户授权结果

示例代码

wx.getSetting({
  success (res) {
    console.log(res.authSetting)
    // res.authSetting = {
    //   "scope.userInfo": true,
    //   "scope.userLocation": true
    // }
  }
})
wx.getSetting({
  withSubscriptions: true,
  success (res) {
    console.log(res.authSetting)
    // res.authSetting = {
    //   "scope.userInfo": true,
    //   "scope.userLocation": true
    // }
    console.log(res.subscriptionsSetting)
    // res.subscriptionsSetting = {
    //   mainSwitch: true, // 订阅消息总开关
    //   itemSettings: {   // 每一项开关
    //     SYS_MSG_TYPE_INTERACTIVE: 'accept', // 小游戏系统订阅消息
    //     SYS_MSG_TYPE_RANK: 'accept'
    //     zun-LzcQyW-edafCVvzPkK4de2Rllr1fFpw2A_x0oXE: 'reject', // 普通一次性订阅消息
    //     ke_OZC_66gZxALLcsuI7ilCJSP2OJ2vWo2ooUPpkWrw: 'ban',
    //   }
    // }
  }
})
posted on   AtlasLapetos  阅读(29)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示