fix(privacy): 修复微信隐私协议chooseImage报错问题
- 调整requiredPrivateInfos字段,仅保留位置类API白名单 - 在uploadFile中添加ensurePrivacyAuthorized预检逻辑,避免权限缺失导致失败 - 在app.tsx的useLaunch生命周期中注册Taro.onNeedPrivacyAuthorization回调,实现自定义协议弹窗交互 - 提示需在小程序管理后台配置“开发者收集你的相册/摄像头”声明,避免首次调用弹窗 - 警告requiredPrivateInfos不可添加非位置类API,防止app.json解析失败 - 说明直接调用Taro.chooseImage的页面需单独添加预检措施
This commit is contained in:
@@ -25,11 +25,12 @@
|
|||||||
## 微信隐私协议(chooseImage errno:112)修复
|
## 微信隐私协议(chooseImage errno:112)修复
|
||||||
- 报错:`MiniProgramError {errMsg:"chooseImage:fail api scope is not declared in the privacy agreement", errno:112}`(基础库 3.16.1+ 强制)
|
- 报错:`MiniProgramError {errMsg:"chooseImage:fail api scope is not declared in the privacy agreement", errno:112}`(基础库 3.16.1+ 强制)
|
||||||
- 影响范围:所有调用 `Taro.chooseImage` 的地方,本轮修复统一入口 `uploadFile`(商品管理页、订单评价、售后申请、门店订单都走这个)
|
- 影响范围:所有调用 `Taro.chooseImage` 的地方,本轮修复统一入口 `uploadFile`(商品管理页、订单评价、售后申请、门店订单都走这个)
|
||||||
- 修复三处:
|
- 修复:
|
||||||
1. **`src/app.config.ts`** — `requiredPrivateInfos` 补齐 `chooseImage`、`chooseMedia`
|
1. **`src/api/system/file/index.ts`** — `uploadFile` 加 `ensurePrivacyAuthorized()` 预检(`getPrivacySetting` + `requirePrivacyAuthorize`)
|
||||||
2. **`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. **`src/app.tsx`** — `useLaunch` 里注册 `Taro.onNeedPrivacyAuthorization` 回调,弹自定义 showModal 协议弹窗,同意 resolve({event:'agree'}) 拒绝 resolve({event:'disagree'})
|
3. **小程序管理后台**(必须手动去配)→ 设置 → 第三方设置 → 用户隐私保护指引 → 添加「开发者收集你的相册/摄像头」声明,否则首次调用仍会触发协议弹窗
|
||||||
- 旧基础库兼容:`typeof wxAny.requirePrivacyAuthorize !== 'function'` 时直接放行
|
- 旧基础库兼容:`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` 预检
|
- 后续若别的页面直接调 `Taro.chooseImage`(如 `evaluate/index.tsx`、`after-sale/apply/index.tsx`、`store/orders/index.tsx`),仍要单独加 `ensurePrivacyAuthorized` 预检
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -43,10 +43,11 @@
|
|||||||
|
|
||||||
## 微信隐私协议(基础库 3.16.1+ 强制)
|
## 微信隐私协议(基础库 3.16.1+ 强制)
|
||||||
- 报错特征:`chooseImage:fail api scope is not declared in the privacy agreement` + `errno:112`
|
- 报错特征:`chooseImage:fail api scope is not declared in the privacy agreement` + `errno:112`
|
||||||
- 三处必改:
|
- 两处代码修复:
|
||||||
1. `src/app.config.ts` 的 `requiredPrivateInfos` 必含 `chooseImage`、`chooseMedia`(已经包含 `getLocation`、`chooseLocation`)
|
1. 调用 `Taro.chooseImage` 前必须先 `getPrivacySetting` → `requirePrivacyAuthorize` 预检(封装在 `src/api/system/file/index.ts` 的 `ensurePrivacyAuthorized()` 里)
|
||||||
2. 调用 `Taro.chooseImage` 前必须先 `getPrivacySetting` → `requirePrivacyAuthorize` 预检(封装在 `src/api/system/file/index.ts` 的 `ensurePrivacyAuthorized()` 里)
|
2. `src/app.tsx` 的 `useLaunch` 中注册 `Taro.onNeedPrivacyAuthorization` 回调(用 `showModal` 自定义弹窗)
|
||||||
3. `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` 预检
|
- 直接调 `Taro.chooseImage` 的页面:`pages/order/evaluate/index.tsx`、`pages/after-sale/apply/index.tsx`、`pages/store/orders/index.tsx` —— 这些页面绕过了 `uploadFile`,需要单独加 `ensurePrivacyAuthorized` 预检
|
||||||
|
|
||||||
## 分享 / 朋友圈能力(2026-07-13 接入)
|
## 分享 / 朋友圈能力(2026-07-13 接入)
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ export default {
|
|||||||
desc: '用于获取您的位置,按距离展示附近门店和选择收货地址定位',
|
desc: '用于获取您的位置,按距离展示附近门店和选择收货地址定位',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
requiredPrivateInfos: ['getLocation', 'chooseLocation', 'chooseImage', 'chooseMedia'],
|
requiredPrivateInfos: ['getLocation', 'chooseLocation'],
|
||||||
tabBar: {
|
tabBar: {
|
||||||
custom: false,
|
custom: false,
|
||||||
color: '#8a8a8a',
|
color: '#8a8a8a',
|
||||||
|
|||||||
Reference in New Issue
Block a user