微信小游戏 小程序与小游戏获取用户信息接口调整 wx.createUserInfoButton

一、小程序与小游戏获取用户信息接口调整

 现在使用wx.getUserInfo接口会出现提示

查看文档

wx.getUserInfo 接口后续将不再出现授权弹窗,请注意升级

二、什么是授权弹框?

三、原来是怎么样的?现在是怎么样的?

原来直接调用wx.login => wx.getUserInfo 会直接弹出授权弹框,然后可以直接获取用户信息

    private async runGame() {
        await this.loadResource()
        this.createGameScene();
        const result = await RES.getResAsync("description_json")
        await platform.login();
        const userInfo = await platform.getUserInfo();
        console.log("用户数据:",userInfo);

    }

  

现在我还是这么做,微信开发者工具还是真机实测,基础库2.1.0,并且体验版都是和原来一样可以出授权弹框和获取用户信息。

那么wx.createUserInfoButton有什么用???

 四、wx.createUserInfoButton怎么用?

 我现在仍然不知道wx.createUserInfoButton有什么用。。。

不过先把代码里放着先吧。万一有用了呢。

首先在wx_mini_game.d.ts里增加接口。wx_mini_game.d.ts是什么?官方提供的wx接口文件啊。官方Demo

/**
     * 在无须用户授权的情况下,批量获取用户信息。该接口只在开放数据域下可用
     */
    createUserInfoButton(object: { type: string, text?: string, image?: string, style: any }): UserInfoButton;
/**
 * 按钮
 */
declare interface UserInfoButton {
    destroy(): void;
    hide(): void;
    onTap(callback: (res) => void): void;
    offTap(callback: () => void): void;
    show(): void;
}

  

在代码里使用

		let button = wx.createUserInfoButton({
			type: 'text',
			text: '获取用户信息',
			style: {
				left: 10,
				top: 76,
				width: 200,
				height: 40,
				lineHeight: 40,
				backgroundColor: '#ff0000',
				color: '#ffffff',
				textAlign: 'center',
				fontSize: 16,
				borderRadius: 4
			}
		});

		button.onTap((res) => {
			console.log(res)
		})

  

然后会出现一坨按钮

 点击这个按钮,会获取用户数据

 到此结束。。。

猜你喜欢

转载自www.cnblogs.com/gamedaybyday/p/9208174.html