Appearance
登录
登录
功能描述:
在未登录的情况下,进行微信登录
TIP
注意:登录前请确定 SDK 已经初始化成功
js
BrickMiniGame.login()
.then((res) => {
console.log('res');
})
.catch((err) => {
console.log('登录失败');
});
登录成功回调的数据格式如下:
登录校验
功能描述:
验证用户登录
js
BrickMiniGame.checkLogin({
user_id: '62c9***9a23',
})
.then((res) => {
console.log('成功');
})
.catch((err) => {
console.log('失败');
});
创建获取用户信息的按钮
功能描述:
个人信息是用户的敏感信息,因此首次获取用户信息需要用户同意授权。 使用会创建获取用户信息的按钮,引导用户点击后授权,详见微信官方文档 创建用户信息按钮。
TIP
注意:调用 createUserInfoBtn 需要用户同意隐私协议,具体查阅小游戏隐私合规开发指南进行配置
参数
属性 | 类型 | 必填 | 说明 |
---|---|---|---|
type | 'text'/'image' | 是 | 按钮类型 |
style | Object | 是 | 按钮类型,按钮样式,详见微信官方文档 创建用户信息按钮 |
text | string | 否 | 按钮上的文本,仅当 type 为 text 时有效 |
image | string | 否 | 按钮的背景图片,仅当 type 为 image 时有效 |
返回值
UserInfoButton
方法
UserInfoButton | 类型 | 说明 |
---|---|---|
show | function | 显示按钮 |
hide | function | 隐藏按钮 |
destroy | function | 销毁按钮 |
onTap | function(function callback) | 监听按钮点击事件 |
offTap | function(function callback) | 取消按钮点击事件 |
js
let infoButton = BrickMiniGame.createUserInfoBtn({
type: 'text',
text: '获取用户信息',
style: {
left: 10,
top: 76,
width: 200,
height: 40,
lineHeight: 40,
backgroundColor: '#ff0000',
color: '#ffffff',
textAlign: 'center',
fontSize: 16,
borderRadius: 4,
},
});
infoButton.onTap((res) => {
console.log(res);
});
获取当前用户的权限设置
功能描述
getUserSetting 获取用户的当前设置。
参数
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
withSubscriptions | Boolean | false | 否 | 是否同时获取用户订阅消息的订阅状态,默认不获取。注意:withSubscriptions 只返回用户勾选过订阅面板中的“总是保持以上选择,不再询问”的订阅消息。 |
js
BrickMiniGame.getUserSetting({
withSubscriptions: true,
})
.then((res) => {
console.log(res);
})
.catch((e) => {
console.log(e);
});