该 API 使用方法为 wx.login(Object object)
属性 | 类型 | 默认值 | 必填 | 说明 |
success | function | - | 否 | 接口调用成功的回调函数 |
fail | function | - | 否 | 接口调用失败的回调函数 |
complete | function | - | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
wx.login({success(res) {console.log(res ,"---------------info, host app return");}})
该 API 使用方法为 wx.checkSession(Object object)
属性 | 类型 | 默认值 | 必填 | 说明 |
success | function | - | 否 | 接口调用成功的回调函数 |
fail | function | - | 否 | 接口调用失败的回调函数 |
complete | function | - | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
wx.checkSession({success () {//session_key 未过期,并且在本生命周期一直有效},fail () {// session_key 已经失效,需要重新执行登录流程wx.login() //重新登录}})
该 API 使用方法为 Object wx.getAccountInfoSync()
属性 | 类型 | 说明 |
miniProgram | Object | 小游戏账号信息 |
结构属性 | 类型 | 说明 |
appId | string | 小游戏 appid |
envVersion | string | 小游戏版本,合法值为: develop:开发版 trial:体验版 release:正式版 |
version | string | 线上小游戏版本号 |
该 API 使用方法为 wx.getUserInfo(Object object)
属性 | 类型 | 默认值 | 必填 | 说明 |
lang | string | en | 否 | 显示用户信息的语言,合法值为: en:英文 zh_CN:简体中文 zh_TW:繁体中文 |
success | function | - | 否 | 接口调用成功的回调函数 |
fail | function | - | 否 | 接口调用失败的回调函数 |
complete | function | - | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
属性 | 类型 | 说明 |
userInfo | UserInfo | 用户信息对象 |
// 必须是在用户已经授权的情况下调用wx.getUserInfo({success: function(res) {var userInfo = res.userInfovar nickName = userInfo.nickNamevar avatarUrl = userInfo.avatarUrl}})
属性 | 类型 | 说明 |
nickName | string | 用户昵称 |
avatarUrl | string | 用户头像图片的 URL。URL 最后一个数值代表正方形头像大小(有 0、46、64、96、132 数值可选,0 代表 640x640 的正方形头像,46 表示 46x46 的正方形头像,剩余数值以此类推。默认132),用户没有头像时该项为空。若用户更换头像,原有头像 URL 将失效 |
gender | number | 用户性别。不再返回,合法值为: 0:未知 1:男性 2:女性 |
country | string | 用户所在国家。不再返回 |
province | string | 用户所在省份。不再返回 |
city | string | 用户所在城市。不再返回 |
language | string | 显示 country,province,city 所用的语言。强制返回 “zh_CN”,合法值为: en:英文 zh_CN:简体中文 zh_TW:繁体中文 |
属性 | 说明 |
boolean scope.userInfo | 是否授权用户信息,对应接口 wx.getUserInfo |
boolean scope.writePhotosAlbum | 是否授权保存到相册 wx.saveImageToPhotosAlbum |
boolean scope.userLocation | 是否授权精确地理位置,对应接口 wx.getLocation |
boolean scope.userFuzzyLocation | 是否授权模糊地理位置,对应接口 wx.getFuzzyLocation |
该 API 使用方法为 wx.getSetting(Object object)
属性 | 类型 | 默认值 | 必填 | 说明 |
success | function | - | 否 | 接口调用成功的回调函数 |
fail | function | - | 否 | 接口调用失败的回调函数 |
complete | function | - | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
属性 | 类型 | 说明 |
authSetting | 用户授权结果 |
wx.getSetting({success(res) {console.log(res.authSetting)// res.authSetting = {// "scope.userInfo": true,// "scope.userLocation": true// }}})
该 API 使用方法为 wx.openSetting(Object object)
属性 | 类型 | 默认值 | 必填 | 说明 |
success | function | - | 否 | 接口调用成功的回调函数 |
fail | function | - | 否 | 接口调用失败的回调函数 |
complete | function | - | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
属性 | 类型 | 说明 |
authSetting | AuthSetting | 用户授权结果 |
wx.openSetting({success(res) {console.log(res.authSetting)// res.authSetting = {// "scope.userInfo": true,// "scope.userLocation": true// }}})
该 API 使用方法为 wx.authorize(Object object)
属性 | 类型 | 默认值 | 必填 | 说明 |
scope | string | - | 是 | |
success | function | - | 否 | 接口调用成功的回调函数 |
fail | function | - | 否 | 接口调用失败的回调函数 |
complete | function | - | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
// 可以通过 wx.getSetting 先查询一下用户是否授权了 "scope.userLocation" 这个 scopewx.getSetting({success(res) {if (!res.authSetting['scope.userLocation']) {wx.authorize({scope: 'scope.userLocation',success() {wx.getLocation()}})}}})
该 API 使用方法为 wx.requirePrivacyAuthorize(Object object)
属性 | 类型 | 默认值 | 必填 | 说明 |
success | function | - | 否 | 接口调用成功的回调函数 |
fail | function | - | 否 | 接口调用失败的回调函数 |
complete | function | - | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
wx.requirePrivacyAuthorize({success: () => {// 用户同意授权// runGame() 继续游戏逻辑},fail: () => {}, // 用户拒绝授权complete: () => {}})
该 API 使用方法为 wx.onNeedPrivacyAuthorization(function listener)
属性 | 类型 | 说明 |
referrer | string | 触发本次 onNeedPrivacyAuthorization 事件的接口或组件名(例如:"getUserInfo") |
属性 | 类型 | 说明 |
event | string | 用户操作类型 |
event | 说明 |
exposureAuthorization | 自定义隐私弹窗曝光 |
agree | 用户同意隐私授权 |
disagree | 用户拒绝隐私授权 |
wx.onNeedPrivacyAuthorization((resolve, eventInfo) => {console.log('触发本次事件的接口是:' + eventInfo.referrer)// ------ 自定义弹窗逻辑 ------ //showCustomPopup()// -------弹窗后根据用户操作,进行以下逻辑逻辑 ------- //// 开发者弹出自定义的隐私弹窗,并调用 resolve 告知 superapp 已经弹窗resolve({ event: 'exposureAuthorization' })// 用户点击同意后,开发者调用 resolve 告知 superapp 用户已经同意resolve({ event: 'agree' })// 用户点击拒绝后,开发者调用 resolve 告知 superapp 用户已经拒绝resolve({ event: 'disagree' })})
该 API 使用方法为 wx.requestSubscribeMessage(Object object)
属性 | 类型 | 必填 | 说明 |
tmplIds | Array<string> | 是 | |
success | function | 否 | 接口调用成功的回调函数 |
fail | function | 否 | 接口调用失败的回调函数 |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
属性 | 类型 | 说明 |
errMsg | string | 接口调用成功时 errMsg 值为 "requestSubscribeMessage:ok" |
[TEMPLATE_ID: string] | string | [TEMPLATE_ID] 是动态的键,即模板 id,值包括 'accept'、'reject'、'ban'、'filter'。 'accept' 表示用户同意订阅该条 id 对应的模板消息。 'reject' 表示用户拒绝订阅该条 id 对应的模板消息。 'ban' 表示已被 SAS 封禁。 'filter' 表示该模板因为模板标题同名被 SAS 过滤。 例如 { errMsg: "requestSubscribeMessage:ok", zun-LzcQyW-edafCVvzPkK4de2Rllr1fFpw2A_x0oXE: "accept"} 表示用户同意订阅 zun-LzcQyW-edafCVvzPkK4de2Rllr1fFpw2A_x0oXE 这条消息 |
属性 | 类型 | 说明 |
errMsg | string | 接口调用失败错误信息 |
errno | Number | 接口调用失败错误码 |
errCode | errMsg | 说明 |
10001 | TmplIds can't be empty | 参数传空了 |
10002 | Request list fail | 网络问题,请求消息列表失败 |
10003 | Request subscribe fail | 网络问题,订阅请求发送失败 |
20001 | No template data return, verify the template id exist | 没有模板数据,一般是模板 ID 不存在或者和模板类型不对应导致的 |
20002 | Templates type must be same | 模板消息类型 既有一次性的又有永久的 |
20003 | Templates count out of max bounds | 模板消息数量超过上限 |
20004 | The main switch is switched off | 用户关闭了主开关,无法进行订阅 |
20005 | This mini program was banned from subscribing messages | 小程序被禁封 |
20013 | Reject DeviceMsg Template | 不允许通过该接口订阅设备消息 |
wx.requestSubscribeMessage({tmplIds: [''],success: (res) => {console.log('requestSubscribeMessage===success', res)res === {errMsg: "requestSubscribeMessage:ok","zun-LzcQyW-edafCVvzPkK4de2Rllr1fFpw2A_x0oXE": "accept"}}})
文档反馈