diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..802ccbe Binary files /dev/null and b/.DS_Store differ diff --git a/pages/.DS_Store b/pages/.DS_Store new file mode 100644 index 0000000..f2dbd2e Binary files /dev/null and b/pages/.DS_Store differ diff --git a/pages/contact/index.js b/pages/contact/index.js index a5304a3..8eda5d7 100644 --- a/pages/contact/index.js +++ b/pages/contact/index.js @@ -35,9 +35,8 @@ Page({ this.setData({ appid: accountInfo.miniProgram.appId, }); - console.log('contact page onLoad, options:', options); - // this.getMessages() + // 检查是否已有用户信息 if (wx.getStorageSync('user_info')) { this.setData({ showGetUser: false, @@ -47,16 +46,9 @@ Page({ // start polling when page loads and user is present this.startPolling(); } else { - this.setData({ - showGetUser: true, - }); + // 直接进行静默登录,不显示授权弹窗 + this.silentLogin(); } - - // this.setData({ - // appid: accountInfo.miniProgram.appId, - // }); - - // console.log('appId',accountInfo.miniProgram); }, // onShow() { // this.getMessages() @@ -139,43 +131,43 @@ Page({ that.setData({ loadingMore: false }); }); }, - requestUserProfile(e) { - console.log('user', e.detail); - const user = e.detail; + // 静默登录方法,只需要appid和js_code + silentLogin() { const that = this; - // wx.setStorageSync('user_info', e.detail.userInfo); const accountInfo = wx.getAccountInfoSync(); wx.login({ success: function (res) { request('wechat/miniprogram/login', 'post', { "app_id": accountInfo.miniProgram.appId, - "js_code": res.code, - "encrypted_data": user.encryptedData, - "iv": user.iv, - "raw_data": user.rawData, - "signature": user.signature + "js_code": res.code }).then(resp => { wx.setStorageSync('user_info', resp); - // wx.setStorageSync('open_id', resp.openid); that.setData({ showGetUser: false, userInfo: resp }); request('app/user/create', 'post', { "app_id": accountInfo.miniProgram.appId, - "user_avatar": resp.user_avatar, + "user_avatar": resp.user_avatar || '/static/user.png', "user_id": resp.openid, - "user_name": resp.user_name + "user_name": resp.user_name || '微信用户' }).then(resp => { that.getMessages() // start polling once user info exists that.startPolling(); - + }); + }).catch(err => { + console.error('静默登录失败:', err); + // 如果静默登录失败,可以选择显示授权弹窗或其他处理 + that.setData({ + showGetUser: true }); }); }, + fail: function(err) { + console.error('wx.login失败:', err); + } }); - }, // Start polling messages every 1 second. Ensures only one interval exists. @@ -234,11 +226,7 @@ Page({ } }, - dismissGetUser() { - this.setData({ - showGetUser: false - }); - }, + onReady() { // 初始化欢迎消息,带时间分割线 diff --git a/pages/contact/index.wxml b/pages/contact/index.wxml index 738b28a..8a4d1d1 100644 --- a/pages/contact/index.wxml +++ b/pages/contact/index.wxml @@ -39,17 +39,12 @@ - + - 授权获取您的用户信息 - 授权后可用于显示头像、昵称等,提升聊天体验。 - - - - - + 正在登录... + 请稍候,正在为您自动登录。 diff --git a/pages/index/detail.js b/pages/index/detail.js index 25185c9..a3ea738 100644 --- a/pages/index/detail.js +++ b/pages/index/detail.js @@ -144,5 +144,19 @@ Page({ danceIndex: nextIndex, currentDance: danceList[nextIndex] }); + }, + handleContact() { + wx.requestSubscribeMessage({ + tmplIds: ['9dCV3z7vRPBGm8iMtSXsD7ZVyUjld46w7HTH9zLnzWw'], + success: (res) => { + wx.navigateTo({ + url: `/pages/contact/index` + }); + }, + fail: (err) => { + console.log(err); + } + }); + } }); \ No newline at end of file diff --git a/pages/index/detail.wxml b/pages/index/detail.wxml index 9a26ef8..91c3e85 100644 --- a/pages/index/detail.wxml +++ b/pages/index/detail.wxml @@ -9,14 +9,14 @@ > - 欢迎联系人工客服 - +