Files
xinlong-shop-taro/overview.md
赵忠林 1b72ae37a5 feat(privacy): 修复微信隐私协议授权流程
- 新增全局隐私协议授权管理器 privacyManager,统一管理弹窗显示和授权结果
- 用 PrivacyModal 组件替代原先 Taro.showModal 实现,使用 open-type="agreePrivacyAuthorization" 的 Button 触发微信认可的隐私授权
- 在 app.tsx 中注册 onNeedPrivacyAuthorization 回调,通过 privacyManager.show 弹出隐私弹窗
- 登录和注册页面 useDidShow 钩子调用 ensurePrivacyAuthorized 函数预检隐私授权状态,避免授权失败
- 修复登录/注册接口调用,统一使用 request.post + SERVER_API_URL,修正错误接口地址及导入问题
- 新增隐私弹窗样式和逻辑,实现用户同意或拒绝后的正确流程处理
- 解决微信基础库 3.16.1+ 强制隐私协议授权导致敏感 API 调用失败问题
2026-07-16 01:11:54 +08:00

31 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 手机号授权登录修复概述
## 修复内容
1. **隐私协议授权流程修复**`src/app.tsx`
- 原代码在 `onNeedPrivacyAuthorization` 中直接 `resolve({ event: 'agree' })`,在基础库 3.16.1+ 下无法通过微信校验。
- 新增 `src/components/PrivacyModal`,使用原生 Button 的 `open-type="agreePrivacyAuthorization"` 触发真正的隐私授权;`Taro.showModal` 的按钮无法被微信识别。
2. **登录/注册页预检隐私协议**
- `src/passport/login.tsx``src/passport/register.tsx``useDidShow` 中调用 `ensurePrivacyAuthorized()`,避免用户点击授权按钮时因隐私协议未授权而失败。
3. **统一接口调用**
- 登录/注册页统一使用 `request.post` + `SERVER_API_URL` 调用 `/wx-login/loginByMpWxPhone`
- 修复 `register.tsx` 原本错误使用 `https://shop-api.websoft.top` 的问题。
4. **顺手修复构建错误**
- `src/passport/pay/index.tsx` 引用了不存在的 `@/api/passport/wx-login`,改为使用 `@/api/layout` 中的 `getWxOpenId` / `loginByOpenId`
## 验证
`npx taro build --type weapp` 构建成功。
## 需要你确认的后台配置
- 小程序管理后台 → 设置 → 第三方设置 → 用户隐私保护指引 → 添加「开发者收集你的手机号」声明。
- 确认小程序已开通「手机号快速验证组件」能力,且调用额度充足。
## 测试前清理
由于之前 `Taro.showModal` 的授权无效,微信可能已缓存该状态。重新上传后请先在开发者工具或真机中清理小程序缓存,再重新进入登录页,触发新的 PrivacyModal。