uni.getUserInfo({
provider: 'weixin',
success: function(result) {
let userinfo= result.userInfo
console.log(userinfo)
}
});
uni.downloadFile({
url: userInfo.avatarUrl,
success: function(res) {
uni.hideLoading();
self.avatarPath = res.tempFilePath;
},
fail: function(e) {
console.log(e);
uni.hideLoading();
uni.showModal({
title: '图片加载超时',
content: "网络异常,请稍后重试",
success(res) {
if (res.confirm) {
self.downloadAvatarAndPaintAll(imageUrl);
} else if (res.cancel) {
console.log('用户点击取消');
}
}
})
}
})
例如:
userInfo.avatarUrl = result.detail.avatarUrl.replace("132", "0").replace('https://thirdwx.qlogo.cn', 'https://wx.qlogo.cn');
进入微信小程序管理后台,选择“开发管理——》开发设置“在开发设置下的服务器域名中设置downloadFile合法域名
设置为合法域名后,重新发布小程序就可以了