fix(privacy): 修复微信隐私协议chooseImage报错问题

- 调整requiredPrivateInfos字段,仅保留位置类API白名单
- 在uploadFile中添加ensurePrivacyAuthorized预检逻辑,避免权限缺失导致失败
- 在app.tsx的useLaunch生命周期中注册Taro.onNeedPrivacyAuthorization回调,实现自定义协议弹窗交互
- 提示需在小程序管理后台配置“开发者收集你的相册/摄像头”声明,避免首次调用弹窗
- 警告requiredPrivateInfos不可添加非位置类API,防止app.json解析失败
- 说明直接调用Taro.chooseImage的页面需单独添加预检措施
This commit is contained in:
2026-07-14 23:46:29 +08:00
parent a353bc9ea8
commit 6dafbf47c9
3 changed files with 11 additions and 9 deletions

View File

@@ -25,11 +25,12 @@
## 微信隐私协议chooseImage errno:112修复
- 报错:`MiniProgramError {errMsg:"chooseImage:fail api scope is not declared in the privacy agreement", errno:112}`(基础库 3.16.1+ 强制)
- 影响范围:所有调用 `Taro.chooseImage` 的地方,本轮修复统一入口 `uploadFile`(商品管理页、订单评价、售后申请、门店订单都走这个)
- 修复三处
1. **`src/app.config.ts`** — `requiredPrivateInfos` 补齐 `chooseImage``chooseMedia`
2. **`src/api/system/file/index.ts`** — `uploadFile``ensurePrivacyAuthorized()` 预检(`getPrivacySetting` + `requirePrivacyAuthorize`
3. **`src/app.tsx`** — `useLaunch` 里注册 `Taro.onNeedPrivacyAuthorization` 回调,弹自定义 showModal 协议弹窗,同意 resolve({event:'agree'}) 拒绝 resolve({event:'disagree'})
- 修复:
1. **`src/api/system/file/index.ts`** — `uploadFile``ensurePrivacyAuthorized()` 预检(`getPrivacySetting` + `requirePrivacyAuthorize`
2. **`src/app.tsx`** — `useLaunch` 里注册 `Taro.onNeedPrivacyAuthorization` 回调,弹自定义 showModal 协议弹窗,同意 resolve({event:'agree'}) 拒绝 resolve({event:'disagree'})
3. **小程序管理后台**(必须手动去配)→ 设置 → 第三方设置 → 用户隐私保护指引 → 添加「开发者收集你的相册/摄像头」声明,否则首次调用仍会触发协议弹窗
- 旧基础库兼容:`typeof wxAny.requirePrivacyAuthorize !== 'function'` 时直接放行
- ⚠️ **易错点:`requiredPrivateInfos` 字段只接受位置类 API 白名单**chooseAddress/chooseLocation/choosePoi/getFuzzyLocation/getLocation/onLocationChange/startLocationUpdate/startLocationUpdateBackground不要加 `chooseImage`/`chooseMedia` 等非位置类,会导致 app.json 解析失败
- 后续若别的页面直接调 `Taro.chooseImage`(如 `evaluate/index.tsx``after-sale/apply/index.tsx``store/orders/index.tsx`),仍要单独加 `ensurePrivacyAuthorized` 预检