现在获取不到用户头像,可以做数据对比来解决吗?

你好,我有个同城小程序,现在获取不到用户头像,你可以做数据对比来解决吗?

根据您描述的问题,希望通过数据对比来恢复用户的头像,那之前您有主动将用户的头像数据保存在指定位置吗,如果有的话肯定没有问题,如果没有的话,那你可以尝试找到tencent”文件夹。然后在“tencent”文件夹内找到“MicroMsg”文件夹,并点击。接着在“MicroMsg”文件夹内找到“WeXin”文件夹,所有的微信图片都在里面,但是要获取到指定用户的头像,还需要去解析这个目录下的图片,找到对应关系。这会比较困难。建议您还是看下现在为何获取不到用户头像,微信头像获取不到,可能是由于用户没有点击授权等导致的。往这个思路会更好一点。

你说是对比用户的数据来恢复用户头像吗?
恢复要看小程序的架构和数据存储方式。
比较数据可以找到,但是总有一些用户头像会有缺失,不能说100%能成功,数据对比比还要看备份数据完不完整。

微信已经在去年更新了获取用户昵称和头像的策略。
现在后台已经无法主动获取用户的昵称了,需要在客户端用户主动点击授权才可以。

对比数据库存的用户头像吗

该回答引用Chatgpt
请参考下面的解决方案,如果可行,还请点击 采纳 ,感谢!

不能通过数据对比来解决获取不到用户头像的问题。这可能是因为微信小程序限制了获取用户信息的权限,或者用户没有设置头像。为了解决这个问题,你需要在微信小程序中请求用户授权,以便获取其头像等信息。

以下是请求用户授权的示例代码:

wx.getUserInfo({
  success: function(res) {
    var userInfo = res.userInfo
    var nickName = userInfo.nickName
    var avatarUrl = userInfo.avatarUrl
    var gender = userInfo.gender //性别 0:未知、1:男、2:女
    var province = userInfo.province
    var city = userInfo.city
    var country = userInfo.country
  }
})

可以上传头像

题主你好,这个问题我之前遇到过,若是对你有所帮助,还望采纳,点击回答右侧采纳即可。
微信小程序登录获取不到头像和昵称主要原因是:小程序wx.getUserProfile接口被收回!
对于此次变化,现将小程序授权方式做以调整:

添加判断当前基础库是否支持头像昵称填写能力
在根目录App.vue中加入判断基础库是否大于2.21.2版本(大于此版本支持头像/昵称填写能力)

// #ifdef MP
    const version = uni.getSystemInfoSync().SDKVersion
    if (Routine.compareVersion(version, '2.21.2') >= 0) {
        that.$Cache.set('MP_VERSION_ISNEW', true)
    } else {
        that.$Cache.set('MP_VERSION_ISNEW', false)
    }
// #endif

2.修改/pages/users/wechat_login.vue文件
(1) 在data中加入基础库判断,决定授权逻辑

mp_is_new: this.$Cache.get('MP_VERSION_ISNEW') || false

(2)dom中新增逻辑判断

img

(3) methods中加入方法userLogin

// 小程序 22.11.8日删除getUserProfile 接口获取用户昵称头像
    userLogin() {
        Routine.getCode()
            .then(code => {
                uni.showLoading({
                    title: '正在登录中'
                });
                authLogin({
                    code,
                    spread_spid: app.globalData.spid,
                    spread_code: app.globalData.code
                }).then(res => {
                    if (res.data.key !== undefined && res.data.key) {
                        uni.hideLoading();
                        this.authKey = res.data.key;
                        this.isPhoneBox = true;
                    } else {
                        uni.hideLoading();
                        let time = res.data.expires_time - this.$Cache.time();
                        this.$store.commit('LOGIN', {
                            token: res.data.token,
                            time: time
                        });
                        this.getUserInfo()
                    }
    
                })
            })
            .catch(err => {
                console.log(err)
            });
    },

/api/public.js 文件添加接口

/**
 * code生成用户
 * @returns {*}
 */
export function authLogin(data) {
    return request.get("v2/wechat/silence_auth_login", data, {
        noAuth: true
    });
}

3.新增用户头像/昵称获取能力

(1)调整pages/users/user_info.vue文件
data中添加

mp_is_new: this.$Cache.get('MP_VERSION_ISNEW') || false
Copy

(2)调整dom中

img


(3)methods中加入方法

onChooseAvatar(e) {
    const { avatarUrl } = e.detail
    this.$util.uploadImgs('upload/image', avatarUrl, (res) => {
        this.userInfo.avatar = res.data.url
    }, (err) => {
        console.log(err)
    })
},

这里有一个公共方法uploadImgs需要在/utils/util.js中添加

uploadImgs(uploadUrl, filePath, successCallback, errorCallback) {
    let that = this;
    uni.uploadFile({
        url: HTTP_REQUEST_URL + '/api/' + uploadUrl,
        filePath: filePath,
        fileType: 'image',
        name: 'pics',
        formData: {
            'filename': 'pics'
        },
        header: {
            // #ifdef MP
            "Content-Type": "multipart/form-data",
            // #endif
            [TOKENNAME]: 'Bearer ' + store.state.app.token
        },
        success: (res) => {
            uni.hideLoading();
            if (res.statusCode == 403) {
                that.Tips({
                    title: res.data
                });
            } else if (res.statusCode == 413) {
                that.Tips({
                    title: '上传图片失败,请重新上传小尺寸图片'
                });
            } else {
                let data = res.data ? JSON.parse(res.data) : {};
                if (data.status == 200) {
                    successCallback && successCallback(data)
                    } else {
                    errorCallback && errorCallback(data);
                    that.Tips({
                        title: data.msg
                    });
                }
            }
        },
        fail: (err) => {
            uni.hideLoading();
                that.Tips({
                title: '上传图片失败'
            });
        }
    })
},

存量用户头像还可以继续使用,原来微信直接返回的用户头像url;
更新后只能通过用户上传,不传的话需要给一个默认头像。