该 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 | 小程序账号信息 |
plugin | Object | 插件账号信息(仅在插件中调用时包含这一项) |
结构属性 | 类型 | 说明 |
appId | string | 小程序 appId |
envVersion | string | 小程序版本,合法值为: develop:开发版 trial:体验版 release:正式版 |
version | string | 线上小程序版本号 |
结构属性 | 类型 | 说明 |
appId | string | 插件 appId |
version | string | 插件版本号 |
该 API 使用方法为 wx.getUserProfile(Object object)
属性 | 类型 | 默认值 | 必填 | 说明 |
lang | string | en | 否 | 显示用户信息的语言,合法值为: en:英文 zh_CN:简体中文 zh_TW:繁体中文 |
desc | string | - | 是 | 声明获取用户个人信息后的用途,不超过30个字符 |
success | function | - | 否 | 接口调用成功的回调函数 |
fail | function | - | 否 | 接口调用失败的回调函数 |
complete | function | - | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
该 API 使用方法为 wx.getUserInfo(Object object)
属性 | 类型 | 默认值 | 必填 | 说明 |
withCredentials | boolean | | 否 | 是否带上登录态信息。当 withCredentials 为 true 时,要求此前有调用过 wx.login 且登录态尚未过期,此时返回的数据会包含 encryptedData,iv 等敏感信息;当 withCredentials 为 false 时,不要求有登录态,返回的数据不包含 encryptedData,iv 等敏感信息 |
lang | string | en | 否 | 显示用户信息的语言,合法值为: en:英文 zh_CN:简体中文 zh_TW:繁体中文 |
success | function | - | 否 | 接口调用成功的回调函数 |
fail | function | - | 否 | 接口调用失败的回调函数 |
complete | function | - | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
属性 | 类型 | 说明 |
userInfo | UserInfo | 用户信息对象,不包含 openid 等敏感信息 |
rawData | string | 不包括敏感信息的原始数据字符串,用于计算签名 |
signature | string | 使用 sha1( rawData + sessionkey ) 得到字符串,用于校验用户信息 |
encryptedData | string | 包括敏感数据在内的完整用户信息的加密数据 |
iv | string | 加密算法的初始向量 |
cloudID | string | 敏感数据对应的云 ID,开通云开发的小程序才会返回,可通过云调用直接获取开放数据,详细见云调用直接获取开放数据 |
// 必须是在用户已经授权的情况下调用wx.getUserInfo({success: function(res) {var userInfo = res.userInfovar nickName = userInfo.nickNamevar avatarUrl = userInfo.avatarUrlvar gender = userInfo.gender //性别 0:未知、1:男、2:女var province = userInfo.provincevar city = userInfo.cityvar country = userInfo.country}})
{"openId": "OPENID","nickName": "NICKNAME","gender": GENDER,"city": "CITY","province": "PROVINCE","country": "COUNTRY","avatarUrl": "AVATARURL","unionId": "UNIONID","watermark": {"appid":"APPID","timestamp":TIMESTAMP}}
<!-- 如果只是展示用户头像昵称,可以使用 <open-data /> 组件 --><open-data type="userAvatarUrl"></open-data><open-data type="userNickName"></open-data><!-- 需要使用 button 来授权登录 --><button wx:if="{{canIUse}}" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">授权登录</button><view wx:else>请升级宿主客户端版本</view>
Page({data: {canIUse: wx.canIUse('button.open-type.getUserInfo')},onLoad: function() {// 查看是否授权wx.getSetting({success (res){if (res.authSetting['scope.userInfo']) {// 已经授权,可以直接调用 getUserInfo 获取头像昵称wx.getUserInfo({success: function(res) {console.log(res.userInfo)}})}}})},bindGetUserInfo (e) {console.log(e.detail.userInfo)}})
属性 | 类型 | 说明 |
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.userLocation | 是否授权地理位置,对应接口 wx.getLocation
是否授权地理位置,对应接口 wx.chooseLocation |
boolean scope.writePhotosAlbum | 是否授权保存到相册 wx.saveImageToPhotosAlbum |
boolean scope.camera | 是否授权摄像头,对应 <camera /> 组件 |
boolean scope.addFriend |
该 API 使用方法为 wx.getSetting(Object object)
属性 | 类型 | 默认值 | 必填 | 说明 |
withSubscriptions | Boolean | false | 否 | 是否同时获取用户订阅消息的订阅状态,默认不获取 |
success | function | - | 否 | 接口调用成功的回调函数 |
fail | function | - | 否 | 接口调用失败的回调函数 |
complete | function | - | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
属性 | 类型 | 说明 |
authSetting | 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// }}})
wx.openSetting({success (res) {console.log(res.authSetting)// res.authSetting = {// "scope.userInfo": true,// "scope.userLocation": true// }}})
该 API 使用方法为 wx.checkIsSoterEnrolledInDevice(Object object)
属性 | 类型 | 默认值 | 必填 | 说明 |
success | function | - | 否 | 接口调用成功的回调函数 |
fail | function | - | 否 | 接口调用失败的回调函数 |
complete | function | - | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
属性 | 类型 | 说明 |
isEnrolled | boolean | 是否已录入信息 |
errMsg | string | 错误信息 |
wx.checkIsSoterEnrolledInDevice({success(res) {console.log(res.isEnrolled)}})
该 API 使用方法为 wx.checkIsSupportSoterAuthentication(Object object)
属性 | 类型 | 默认值 | 必填 | 说明 |
success | function | - | 否 | 接口调用成功的回调函数 |
fail | function | - | 否 | 接口调用失败的回调函数 |
complete | function | - | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
wx.checkIsSupportSoterAuthentication({success() {// 支持生物认证}})
该 API 使用方法为 wx.startSoterAuthentication(Object object)
属性 | 类型 | 默认值 | 必填 | 说明 |
authContent | string | '' | 否 | 验证描述,即识别过程中显示在界面上的对话框提示内容 |
success | function | - | 否 | 接口调用成功的回调函数 |
fail | function | - | 否 | 接口调用失败的回调函数 |
complete | function | - | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
wx.startSoterAuthentication({authContent: '生物认证解锁',success() {// 认证成功}})
该 API 使用方法为 wx.authorize(Object object)
属性 | 类型 | 默认值 | 必填 | 说明 |
scope | string | - | 是 | 需要获取权限的 scope |
success | function | - | 否 | 接口调用成功的回调函数 |
fail | function | - | 否 | 接口调用失败的回调函数 |
complete | function | - | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
// 可以通过 wx.getSetting 先查询一下用户是否授权了 "scope.record" 这个 scopewx.getSetting({success(res) {if (!res.authSetting['scope.record']) {wx.authorize({scope: 'scope.record',success() {// 用户已经同意小程序使用录音功能,后续调用 wx.startRecord 接口不会弹窗询问wx.startRecord()}})}}})
本页内容是否解决了您的问题?