自 2022 年 10 月 25 日 24 时后(以下统称 “生效期” ),用户头像昵称获取规则将进行如下调整:
自生效期起,小程序 wx.getUserProfile 接口将被收回
头像授权
微信开放能力
<button
open-type="chooseAvatar"
@chooseavatar="onChooseAvatar"
@click="onAuthAvatar"
class="avatar-btn"
><button>
// 授权头像
onChooseAvatar(e) {
wx.getFileSystemManager().readFile({
filePath: e.detail.avatarUrl, //选择图片返回的相对路径
encoding: "base64", //编码格式
success: (res) => {
//成功的回调
console.log("data:image/png;base64," + res.data);
const avatarUrl = "data:image/png;base64," + res.data,
params = {
isSelect:this.userAuthInfo.isSelect,
nickName: this.userAuthInfo.nickName,
avatarUrl,
};
this.authAvatar(params,'avatar');
},
});
},
昵称授权
微信开放能力
<input
type="nickname"
class="weui-input"
placeholder="请输入"
@input="onInput"
@blur="onBlur"
placeholder-class="placeholder-style"
maxlength="10"
/>
// 获取输入内容长度
onInput(e) {
this.nameLength = e.detail.value.length;
this.nickName = e.detail.value;
this.isSelect = e.detail.cursor?false:true
},
``