From 466dbfbd96ae689c5fdfe579660d957a3c3f4f4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=A3=9E=E6=B4=8B?= <15778543+xufeiyang6017@user.noreply.gitee.com> Date: Mon, 8 Dec 2025 13:37:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BE=AE=E4=BF=A1=E5=A4=B4?= =?UTF-8?q?=E5=83=8F=E8=8E=B7=E5=8F=96=E4=B8=8E=E5=AD=98=E5=82=A8=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8C=E7=A1=AE=E4=BF=9D=E6=89=80=E6=9C=89=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E5=85=A5=E5=8F=A3=E4=BC=98=E5=85=88=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E7=94=A8=E6=88=B7=E7=9C=9F=E5=AE=9E=E5=A4=B4?= =?UTF-8?q?=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.js | 3 ++- pages/profile/index.js | 18 ++++++++++-------- pages/seller/index.js | 31 +++++++++++++++++++++++++++++-- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/pages/index/index.js b/pages/index/index.js index ff1831d..1456b7a 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -296,7 +296,8 @@ Page({ // 6. 创建用户信息 const tempUserInfo = { nickName: userProfile ? userProfile.userInfo.nickName : '微信用户', - avatarUrl: userProfile ? userProfile.userInfo.avatarUrl : this.data.avatarUrl, + // 获取微信头像失败时使用微信默认头像,而不是本地头像 + avatarUrl: userProfile ? userProfile.userInfo.avatarUrl : 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0', gender: userProfile ? userProfile.userInfo.gender : 0, country: userProfile ? userProfile.userInfo.country : '', province: userProfile ? userProfile.userInfo.province : '', diff --git a/pages/profile/index.js b/pages/profile/index.js index cd174dc..c7d7ee4 100644 --- a/pages/profile/index.js +++ b/pages/profile/index.js @@ -449,13 +449,14 @@ Page({ const app = getApp() const existingUserInfo = app.globalData.userInfo || wx.getStorageSync('userInfo') || {} const userInfo = { - nickName: existingUserInfo.nickName || (userProfile ? userProfile.userInfo.nickName : '微信用户'), - avatarUrl: existingUserInfo.avatarUrl || (userProfile ? userProfile.userInfo.avatarUrl : 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'), - gender: existingUserInfo.gender || (userProfile ? userProfile.userInfo.gender : 0), - country: existingUserInfo.country || (userProfile ? userProfile.userInfo.country : ''), - province: existingUserInfo.province || (userProfile ? userProfile.userInfo.province : ''), - city: existingUserInfo.city || (userProfile ? userProfile.userInfo.city : ''), - language: existingUserInfo.language || (userProfile ? userProfile.userInfo.language : 'zh_CN'), + // 优先使用最新获取的微信头像和昵称,如果没有获取到则使用本地存储的 + nickName: (userProfile ? userProfile.userInfo.nickName : existingUserInfo.nickName) || '微信用户', + avatarUrl: (userProfile ? userProfile.userInfo.avatarUrl : existingUserInfo.avatarUrl) || 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0', + gender: (userProfile ? userProfile.userInfo.gender : existingUserInfo.gender) || 0, + country: (userProfile ? userProfile.userInfo.country : existingUserInfo.country) || '', + province: (userProfile ? userProfile.userInfo.province : existingUserInfo.province) || '', + city: (userProfile ? userProfile.userInfo.city : existingUserInfo.city) || '', + language: (userProfile ? userProfile.userInfo.language : existingUserInfo.language) || 'zh_CN', phoneNumber: phoneNumber } @@ -555,11 +556,12 @@ Page({ return; } - // 构造上传数据(包含所有必要字段,包括phoneNumber) + // 构造上传数据(包含所有必要字段,包括phoneNumber和头像URL) const uploadData = { userId: userId, openid: openid, nickName: userInfo.nickName, + avatarUrl: userInfo.avatarUrl, // 添加头像URL字段 phoneNumber: userInfo.phoneNumber, // 添加phoneNumber字段,满足服务器要求 type: type, timestamp: Date.now() diff --git a/pages/seller/index.js b/pages/seller/index.js index 3af9e30..3076937 100644 --- a/pages/seller/index.js +++ b/pages/seller/index.js @@ -2373,8 +2373,9 @@ Page({ isNewPhone: isNewPhone }) - // 5. 创建临时用户信息并保存 - const tempUserInfo = { + // 5. 获取用户微信头像和昵称 + let userProfile = null; + let tempUserInfo = { nickName: '微信用户', avatarUrl: this.data.avatarUrl, gender: 0, @@ -2383,6 +2384,32 @@ Page({ city: '', language: 'zh_CN', phoneNumber: finalPhoneNumber + }; + + try { + userProfile = await new Promise((resolve, reject) => { + wx.getUserProfile({ + desc: '用于完善会员资料', + success: resolve, + fail: reject + }); + }); + console.log('获取用户信息成功:', userProfile); + + // 更新临时用户信息 + tempUserInfo = { + nickName: userProfile.userInfo.nickName, + avatarUrl: userProfile.userInfo.avatarUrl, + gender: userProfile.userInfo.gender, + country: userProfile.userInfo.country, + province: userProfile.userInfo.province, + city: userProfile.userInfo.city, + language: userProfile.userInfo.language, + phoneNumber: finalPhoneNumber + }; + } catch (err) { + console.warn('获取用户信息失败:', err); + // 如果获取失败,继续使用现有临时用户信息 } const storedUserId = wx.getStorageSync('userId')