diff --git a/wechat-miniprogram/pages/edit-profile/index.js b/wechat-miniprogram/pages/edit-profile/index.js index da7b938..ee288a9 100644 --- a/wechat-miniprogram/pages/edit-profile/index.js +++ b/wechat-miniprogram/pages/edit-profile/index.js @@ -370,6 +370,12 @@ Page({ wx.showToast({ title: '请先获取并输入验证码', icon: 'none' }); return; } + // 验证码清洗:提取纯数字取前 6 位 + const cleanCode = (code.replace(/\D/g, '') || '').slice(0, 6); + if (cleanCode.length !== 6) { + wx.showToast({ title: '验证码为 6 位数字,请检查邮件中【 】括号内数字', icon: 'none', duration: 2500 }); + return; + } if (this.data.bindingEmail) return; // 邮箱一经绑定不可更改:绑定前强确认 wx.showModal({ @@ -383,7 +389,7 @@ Page({ async doBindEmail(email, code) { this.setData({ bindingEmail: true }); try { - const res = await bindEmail(email, code); + const res = await bindEmail(email, cleanCode); if (res.success) { wx.showToast({ title: res.data && res.data.chaishuAutoBound ? '绑定成功,已认证拆书帮身份' : '绑定成功', icon: 'none' }); this.stopOtpCountdown(); diff --git a/wechat-miniprogram/pages/edit-profile/index.wxml b/wechat-miniprogram/pages/edit-profile/index.wxml index 7a1a36f..2f84895 100644 --- a/wechat-miniprogram/pages/edit-profile/index.wxml +++ b/wechat-miniprogram/pages/edit-profile/index.wxml @@ -70,7 +70,7 @@ class="form-input email-otp-input" value="{{emailOtp}}" type="number" - maxlength="6" + maxlength="8" placeholder="邮箱验证码" bindinput="onEmailOtpInput" /> diff --git a/wechat-miniprogram/pages/login/index.js b/wechat-miniprogram/pages/login/index.js index dc74527..60c834c 100644 --- a/wechat-miniprogram/pages/login/index.js +++ b/wechat-miniprogram/pages/login/index.js @@ -157,13 +157,19 @@ Page({ wx.showToast({ title: '请输入邮箱验证码', icon: 'none' }); return; } + // 验证码清洗:提取纯数字取前 6 位(邮件中「5 分钟」等数字可能被一并输入) + const cleanCode = (code.replace(/\D/g, '') || '').slice(0, 6); + if (cleanCode.length !== 6) { + wx.showToast({ title: '验证码为 6 位数字,请检查邮件中的【 】括号内数字', icon: 'none', duration: 2500 }); + return; + } if (this.data.loading) return; this.setData({ loading: true }); try { // 携带微信 code:登录成功后服务端补绑 openid(用于裸号合并升级) let wxCode = ''; try { wxCode = await getWechatCode(); } catch (e) { /* 不阻断邮箱登录 */ } - const res = await post('/auth/email/login', { email, code, wxCode }, { showLoading: false }); + const res = await post('/auth/email/login', { email, code: cleanCode, wxCode }, { showLoading: false }); if (res.success && res.data) { const { token, user } = res.data; saveLoginState(token, user?.id, user); diff --git a/wechat-miniprogram/pages/login/index.wxml b/wechat-miniprogram/pages/login/index.wxml index 515a6d4..ca3ab3b 100644 --- a/wechat-miniprogram/pages/login/index.wxml +++ b/wechat-miniprogram/pages/login/index.wxml @@ -54,7 +54,7 @@ { } const code = String(crypto.randomInt(100000, 999999)); try { - await smtpSend(email, '拆约邮箱验证码', `您正在绑定邮箱(邮箱一经绑定不可更改)。\n\n验证码:${code}\n\n5 分钟内有效。若非本人操作请忽略本邮件。`); + await smtpSend(email, '拆约邮箱验证码', `您正在绑定邮箱(邮箱一经绑定不可更改)。\n\n您的验证码(6 位数字):\n\n【 ${code} 】\n\n5 分钟内有效。请输入方括号内的 6 位数字。若非本人操作请忽略本邮件。`); } catch (e) { console.error('OTP 邮件发送失败:', e.message); return res.json({ success: false, message: '验证码邮件发送失败,请稍后重试或联系客服 554176937@qq.com' }); @@ -952,7 +952,7 @@ app.post('/auth/email/otp/send', async (req, res) => { } const code = String(crypto.randomInt(100000, 999999)); try { - await smtpSend(email, '拆约登录验证码', `您正在登录「拆约」小程序。\n\n验证码:${code}\n\n5 分钟内有效。若非本人操作请忽略本邮件。`); + await smtpSend(email, '拆约登录验证码', `您正在登录「拆约」小程序。\n\n您的验证码(6 位数字):\n\n【 ${code} 】\n\n5 分钟内有效。请输入方括号内的 6 位数字。若非本人操作请忽略本邮件。`); } catch (e) { console.error('登录 OTP 邮件发送失败:', e.message); return res.json({ success: false, message: '验证码邮件发送失败,请稍后重试或联系客服 554176937@qq.com' });