.updateUserInfo(注意更新)

从微信获取用户信息(昵称、头像等)

此接口调用了微信官方wx.getUserInfo获取用户。由于官方登录、获取用户信息将使用新接口,在2021年4月13日后发布的小游戏(小程序)若依然使用wx.getUserInfo将无法获取用户信息。建议下载2021年3月7日发布的新版天幕微信天幕SDK,并调用.updataUserProfile接口获取用户信息

关于微信小程序登录、用户信息相关接口调整说明:https://developers.weixin.qq.com/community/develop/doc/000cacfa20ce88df04cb468bc52801?blockType=1

概述

用于从微信获取用户的昵称头像信息。

获取到的用户信息,SDK会自动上传到天幕服务器,通过.login获取。

关于用户信息的更新策略,开发者可点击此处

  1. 接入此接口时,注意兼容性问题

  2. 若使用了无登录版天幕SDK,无法使用该接口获取用户信息。

调用方法

wx.tmSDK.updateUserInfo({encryptedData,iv,signature}).then(res=>{})

参数说明

字段

字段类型

小程序

小游戏

encryptedData

string

在点击事件e中获取

UserInfoButton 回调中获取

iv

string

在点击事件e中获取

UserInfoButton 回调中获取

signature

string

在点击事件e中获取

UserInfoButton 回调中获取

示例

小游戏

let button = wx.createUserInfoButton({
    ...
})
button.onTap(res = > {
    tm_sdk.updateUserInfo({
        encryptedData: res.encryptedData,
        iv: res.iv,
        signature: res.signature
    })
    .then(res=>{
        console.log(res)
    })
})

小程序

<!-- wxml -->
<button open-type="getUserInfo" bindlogin="bindUserLogin">登录</button>
//js
bindUserLogin: function(e) {
    if( e.detail.encryptedData ){
       wx.tmSDK.updateUserInfo({
            encryptedData: e.detail.encryptedData,
            iv: e.detail.iv,
            signature: e.detail.signature
        })
        .then(res=>{
            console.log(res)
        })
    }
}

返回值说明

返回值示例

{
    "pid": "",
    "app_id": "wxa73fd8e544880e89",
    "open_id": "oc7L942AwAqIiBabNYb_cLl7mRsQ",
    "union_id": "",
    "nick_name": "",
    "avatar_url": "",
    "gender": 0,
    "city": "广州",
    "province": "广东省",
    "country": "中国",
    "language": "zh_CN",
    "gold": 0,
    "diamond": 0,
    "share_new": 0,
    "share_times": 0,
    "online_days": 0,
    "online_duration": 0,
    "last_login_time": 1551690740,
    "login_times": 1,
    "from_scene": "1044",
    "from_code": "ball-resurrection-1",
    "is_new": false,
    "ofp": "",
    "jwt": "",
    "login_province": "广东省",
    "login_city": "广州市",
    "login_district": "海珠区"
}

返回值详解

字段

字段类型

字段说明

pid

string

用户在天幕的统一索引,但可能变化,已废弃

app_id

string

应用的appid

open_id

string

用户在该应用下的openid

union_id

string

用户的unionid,默认为空字符串。union_id获取方法

nick_name

string

用户的微信昵称,为空时需要调用 updateUserinfo 获取

avatar_url

string

用户的微信头像,为空时需要调用 updateUserinfo 获取

gender

number

用户在微信中填写的性别,男:1 / 女:0

language

string

用户微信中设置的语言

city

string

用户微信中设置的城市

province

string

用户微信中设置的省份

country

string

用户微信中设置的国家

gold、diamond

string

游戏内金币、钻石,已废弃

share_new

number

用户在当前游戏的分享引入新用户的数量

share_times

number

用户在当前游戏的分享次数

online_days

number

用户在当前游戏在线的天数

online_duration

number

累计在线时长(单位:秒)

last_login_time

number

最近一次访问的时间戳

login_times

number

用户在当前游戏的累计登录访问次数

from_scene

string

来源场景值

from_code

string

来源渠道ID

is_new

bool

是否新注册的用户

login_province

string

根据用户ip判断用户所在的省份(注意:返回的省份名称与行政划分的名称一致,如西藏,返回的是西藏自治区。若要实现地区屏蔽功能,建议根据返回值前两位进行地区匹配)

login_city

string

根据用户ip判断用户所在的城市

login_district

string

根据用户ip判断用户所在的区县

最后更新于