From 6dafbf47c9ccf53f40a631f7c164053a40a94e3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Tue, 14 Jul 2026 23:46:29 +0800 Subject: [PATCH] =?UTF-8?q?fix(privacy):=20=E4=BF=AE=E5=A4=8D=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E9=9A=90=E7=A7=81=E5=8D=8F=E8=AE=AEchooseImage?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 调整requiredPrivateInfos字段,仅保留位置类API白名单 - 在uploadFile中添加ensurePrivacyAuthorized预检逻辑,避免权限缺失导致失败 - 在app.tsx的useLaunch生命周期中注册Taro.onNeedPrivacyAuthorization回调,实现自定义协议弹窗交互 - 提示需在小程序管理后台配置“开发者收集你的相册/摄像头”声明,避免首次调用弹窗 - 警告requiredPrivateInfos不可添加非位置类API,防止app.json解析失败 - 说明直接调用Taro.chooseImage的页面需单独添加预检措施 --- .workbuddy/memory/2026-07-14.md | 9 +++++---- .workbuddy/memory/MEMORY.md | 9 +++++---- src/app.config.ts | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.workbuddy/memory/2026-07-14.md b/.workbuddy/memory/2026-07-14.md index eee5eec..bddc405 100644 --- a/.workbuddy/memory/2026-07-14.md +++ b/.workbuddy/memory/2026-07-14.md @@ -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` 预检 diff --git a/.workbuddy/memory/MEMORY.md b/.workbuddy/memory/MEMORY.md index 5b9ccd9..6324ff4 100644 --- a/.workbuddy/memory/MEMORY.md +++ b/.workbuddy/memory/MEMORY.md @@ -43,10 +43,11 @@ ## 微信隐私协议(基础库 3.16.1+ 强制) - 报错特征:`chooseImage:fail api scope is not declared in the privacy agreement` + `errno:112` -- 三处必改: - 1. `src/app.config.ts` 的 `requiredPrivateInfos` 必含 `chooseImage`、`chooseMedia`(已经包含 `getLocation`、`chooseLocation`) - 2. 调用 `Taro.chooseImage` 前必须先 `getPrivacySetting` → `requirePrivacyAuthorize` 预检(封装在 `src/api/system/file/index.ts` 的 `ensurePrivacyAuthorized()` 里) - 3. `src/app.tsx` 的 `useLaunch` 中注册 `Taro.onNeedPrivacyAuthorization` 回调(用 `showModal` 自定义弹窗) +- 两处代码修复: + 1. 调用 `Taro.chooseImage` 前必须先 `getPrivacySetting` → `requirePrivacyAuthorize` 预检(封装在 `src/api/system/file/index.ts` 的 `ensurePrivacyAuthorized()` 里) + 2. `src/app.tsx` 的 `useLaunch` 中注册 `Taro.onNeedPrivacyAuthorization` 回调(用 `showModal` 自定义弹窗) +- 一处手动配置:**小程序管理后台** → 设置 → 第三方设置 → 用户隐私保护指引 → 添加「开发者收集你的相册/摄像头」声明 +- ⚠️ **`requiredPrivateInfos` 字段只接受位置类 API 白名单**(chooseAddress/chooseLocation/choosePoi/getFuzzyLocation/getLocation/onLocationChange/startLocationUpdate/startLocationUpdateBackground),不要加 `chooseImage`/`chooseMedia` 等非位置类,会导致 app.json 解析失败 - 直接调 `Taro.chooseImage` 的页面:`pages/order/evaluate/index.tsx`、`pages/after-sale/apply/index.tsx`、`pages/store/orders/index.tsx` —— 这些页面绕过了 `uploadFile`,需要单独加 `ensurePrivacyAuthorized` 预检 ## 分享 / 朋友圈能力(2026-07-13 接入) diff --git a/src/app.config.ts b/src/app.config.ts index 3e96b3a..c95e399 100644 --- a/src/app.config.ts +++ b/src/app.config.ts @@ -140,7 +140,7 @@ export default { desc: '用于获取您的位置,按距离展示附近门店和选择收货地址定位', }, }, - requiredPrivateInfos: ['getLocation', 'chooseLocation', 'chooseImage', 'chooseMedia'], + requiredPrivateInfos: ['getLocation', 'chooseLocation'], tabBar: { custom: false, color: '#8a8a8a',