当前位置:   article > 正文

用户隐私问题小程序审核不通过,微信小程序隐私保护开发指南_小程序隐私协议开发指南

小程序隐私协议开发指南

目录

小程序隐私协议开发指南

一、功能介绍

二、接入流程

1. 配置《小程序用户隐私保护指引》

2. 主动查询隐私授权同步状态以及展示隐私协议

3. 被动监听隐私接口需要用户授权事件

4. 清空历史同步状态

三、其他说明

四、完整示例demo

五、常见错误说明

uniapp小程序特别指导:

封装公共方法

封装的弹窗提示组件

同意后,如何清除隐私授权,重新触发wx.getPrivacySetting回调的needAuthorization: true判断?


来自官方文档:小程序隐私协议开发指南 | 微信开放文档

文章中所有红字内容为重点!!!!!!

因为不设置隐私说明告知用户,会导致小程序审核不通过,隐私api无法调用

uniapp小程序需要阅读文章最后的 uniapp小程序特别指导:uniapp小程序特别指导:

小程序隐私协议开发指南

一、功能介绍

涉及处理用户个人信息的小程序开发者,需通过弹窗等明显方式提示用户阅读隐私政策等收集使用规则。

为规范开发者的用户个人信息处理行为,保障用户合法权益,微信要求开发者主动同步微信当前用户已阅读并同意小程序的隐私政策等收集使用规则,方可调用微信提供的隐私接口。

特别注意:

以下指南中涉及的 getPrivacySetting、onNeedPrivacyAuthorization、requirePrivacyAuthorize 等接口,目前仍处于 Beta 调试阶段,目前并未按预期返回正确的结果。开发者目前可以先阅读本指南文档和接口文档进行理解,平台将会尽快正式上线这些接口以及调试方法,上线后会在本指南文档和相关公告中进行说明。

2023.08.22更新:

以下指南中涉及的 getPrivacySetting、onNeedPrivacyAuthorization、requirePrivacyAuthorize 等接口目前可以正常接入调试。调试说明:

  1. 在 2023年9月15号之前,在 app.json 中配置 __usePrivacyCheck__: true 后,会启用隐私相关功能,如果不配置或者配置为 false 则不会启用。

  2. 在 2023年9月15号之后,不论 app.json 中是否有配置 __usePrivacyCheck__,隐私相关功能都会启用。

uniapp则在manifest.json中对应位置添加

 "mp-weixin": {

        "__usePrivacyCheck__": true,

接口用法可参考下方完整示例demo

二、接入流程

1. 配置《小程序用户隐私保护指引》

开发者需在「小程序管理后台」配置《小程序用户隐私保护指引》,详细指引可见:用户隐私保护指引填写说明

需要注意的是,仅有在指引中声明所处理的用户信息,才可以调用平台提供的对应接口或组件。若未声明,对应接口或组件将直接禁用。隐私接口与对应的处理的信息关系可见:小程序用户隐私保护指引内容介绍

配置完成后,对于每个使用小程序的用户,开发者均需要同步微信当前用户已阅读并同意小程序的隐私政策等收集使用规则后,才可以调用已声明的接口或组件。同步的开发方式见下文。

对于已经同步过的用户,后续若开发者更新了配置,对于旧版本已经有接口或组件,不需要重新同步;对于更新后产生的新的接口或组件,需要重新同步。例如,7月11日更新的版本中包含「收集你选择的位置信息」,7月12日同步用户同意状态,7月13日更新后新增了「收集你的微信运动步数」,则在未再次同步的情况下,可以调用 wx.chooseLocation 接口,无法调用 wx.getWeRunData 接口。

2. 主动查询隐私授权同步状态以及展示隐私协议

从基础库 2.32.3 开始支持

开发者可通过 wx.getPrivacySetting 接口,查询微信侧记录的用户是否有待同意的隐私政策信息。该信息可通过返回结果 res 中的 needAuthorization 字段获取。

同时,wx.getPrivacySetting 接口会返回开发者在小程序管理后台配置的《小程序用户隐私保护指引》名称信息,开发者可以调用 wx.openPrivacyContract 接口打开该页面。

如果存在有待用户同意的隐私政策信息,开发者需要主动提示用户阅读隐私政策等收集使用规则,对于提示方式,小程序开发者可自行设计,同时需要在相关界面中使用 <button open-type="agreePrivacyAuthorization"> 组件,当用户轻触该 <button> 组件后,表示用户已阅读并同意小程序的隐私政策等收集使用规则,微信会收到该同步信息,此时开发者可以在该组件的 bindagreeprivacyauthorization 事件回调后调用已声明的隐私接口

代码示例

  1. <span style="background-color:#f9f9fa"><span style="color:#222222"><span style="background-color:#f9f9fa"><code><span style="color:rgba(0, 0, 0, 0.3)"><!-- page.wxml --></span>
  2. <span style="color:#b457ff"><span style="color:#b457ff"><span style="color:#222222"><</span>view</span> <span style="color:#ff4d00">wx:if</span><span style="color:#222222"><span style="color:#222222">=</span><span style="color:#222222">"</span>{{showPrivacy}}<span style="color:#222222">"</span></span><span style="color:#222222">></span></span>
  3. <span style="color:#b457ff"><span style="color:#b457ff"><span style="color:#222222"><</span>view</span><span style="color:#222222">></span></span>隐私弹窗内容....<span style="color:#b457ff"><span style="color:#b457ff"><span style="color:#222222"></</span>view</span><span style="color:#222222">></span></span>
  4. <span style="color:#b457ff"><span style="color:#b457ff"><span style="color:#222222"><</span>button</span> <span style="color:#ff4d00">bindtap</span><span style="color:#222222"><span style="color:#222222">=</span><span style="color:#222222">"</span>handleOpenPrivacyContract<span style="color:#222222">"</span></span><span style="color:#222222">></span></span>查看隐私协议<span style="color:#b457ff"><span style="color:#b457ff"><span style="color:#222222"></</span>button</span><span style="color:#222222">></span></span>
  5. <span style="color:#b457ff"><span style="color:#b457ff"><span style="color:#222222"><</span>button</span> <span style="color:#ff4d00">id</span><span style="color:#222222"><span style="color:#222222">=</span><span style="color:#222222">"</span>agree-btn<span style="color:#222222">"</span></span> <span style="color:#ff4d00">open-type</span><span style="color:#222222"><span style="color:#222222">=</span><span style="color:#222222">"</span>agreePrivacyAuthorization<span style="color:#222222">"</span></span> <span style="color:#ff4d00">bindagreeprivacyauthorization</span><span style="color:#222222"><span style="color:#222222">=</span><span style="color:#222222">"</span>handleAgreePrivacyAuthorization<span style="color:#222222">"</span></span><span style="color:#222222">></span></span>同意<span style="color:#b457ff"><span style="color:#b457ff"><span style="color:#222222"></</span>button</span><span style="color:#222222">></span></span>
  6. <span style="color:#b457ff"><span style="color:#b457ff"><span style="color:#222222"></</span>view</span><span style="color:#222222">></span></span>
  7. </code></span></span></span>
  1. <span style="background-color:#f9f9fa"><span style="color:#222222"><span style="background-color:#f9f9fa"><code><span style="color:rgba(0, 0, 0, 0.3)">// page.js</span>
  2. <span style="color:#23a0ff">Page</span><span style="color:#222222">(</span><span style="color:#222222">{</span>
  3. data<span style="color:#ff4d00">:</span> <span style="color:#222222">{</span>
  4. showPrivacy<span style="color:#ff4d00">:</span> <span style="color:#ff4d00">false</span>
  5. <span style="color:#222222">}</span><span style="color:#222222">,</span>
  6. <span style="color:#23a0ff">onLoad</span><span style="color:#222222">(</span><span style="color:#222222">)</span> <span style="color:#222222">{</span>
  7. wx<span style="color:#222222">.</span><span style="color:#23a0ff">getPrivacySetting</span><span style="color:#222222">(</span><span style="color:#222222">{</span>
  8. <span style="color:#23a0ff">success</span><span style="color:#ff4d00">:</span> <span style="color:#ff4d00">res</span> <span style="color:#ff4d00">=></span> <span style="color:#222222">{</span>
  9. console<span style="color:#222222">.</span><span style="color:#23a0ff">log</span><span style="color:#222222">(</span>res<span style="color:#222222">)</span> <span style="color:rgba(0, 0, 0, 0.3)">// 返回结果为: res = { needAuthorization: true/false, privacyContractName: '《xxx隐私保护指引》' }</span>
  10. <span style="color:#b457ff">if</span> <span style="color:#222222">(</span>res<span style="color:#222222">.</span>needAuthorization<span style="color:#222222">)</span> <span style="color:#222222">{</span>
  11. <span style="color:rgba(0, 0, 0, 0.3)">// 需要弹出隐私协议</span>
  12. <span style="color:#b457ff">this</span><span style="color:#222222">.</span><span style="color:#23a0ff">setData</span><span style="color:#222222">(</span><span style="color:#222222">{</span>
  13. showPrivacy<span style="color:#ff4d00">:</span> <span style="color:#ff4d00">true</span>
  14. <span style="color:#222222">}</span><span style="color:#222222">)</span>
  15. <span style="color:#222222">}</span> <span style="color:#b457ff">else</span> <span style="color:#222222">{</span>
  16. <span style="color:rgba(0, 0, 0, 0.3)">// 用户已经同意过隐私协议,所以不需要再弹出隐私协议,也能调用已声明过的隐私接口</span>
  17. <span style="color:rgba(0, 0, 0, 0.3)">// wx.getUserProfile()</span>
  18. <span style="color:rgba(0, 0, 0, 0.3)">// wx.chooseMedia()</span>
  19. <span style="color:rgba(0, 0, 0, 0.3)">// wx.getClipboardData()</span>
  20. <span style="color:rgba(0, 0, 0, 0.3)">// wx.startRecord()</span>
  21. <span style="color:#222222">}</span>
  22. <span style="color:#222222">}</span><span style="color:#222222">,</span>
  23. <span style="color:#23a0ff">fail</span><span style="color:#ff4d00">:</span> <span style="color:#222222">(</span><span style="color:#222222">)</span> <span style="color:#ff4d00">=></span> <span style="color:#222222">{</span><span style="color:#222222">}</span><span style="color:#222222">,</span>
  24. <span style="color:#23a0ff">complete</span><span style="color:#ff4d00">:</span> <span style="color:#222222">(</span><span style="color:#222222">)</span> <span style="color:#ff4d00">=></span> <span style="color:#222222">{</span><span style="color:#222222">}</span>
  25. <span style="color:#222222">}</span><span style="color:#222222">)</span>
  26. <span style="color:#222222">}</span><span style="color:#222222">,</span>
  27. <span style="color:#23a0ff">handleAgreePrivacyAuthorization</span><span style="color:#222222">(</span><span style="color:#222222">)</span> <span style="color:#222222">{</span>
  28. <span style="color:rgba(0, 0, 0, 0.3)">// 用户同意隐私协议事件回调</span>
  29. <span style="color:rgba(0, 0, 0, 0.3)">// 用户点击了同意,之后所有已声明过的隐私接口和组件都可以调用了</span>
  30. <span style="color:rgba(0, 0, 0, 0.3)">// wx.getUserProfile()</span>
  31. <span style="color:rgba(0, 0, 0, 0.3)">// wx.chooseMedia()</span>
  32. <span style="color:rgba(0, 0, 0, 0.3)">// wx.getClipboardData()</span>
  33. <span style="color:rgba(0, 0, 0, 0.3)">// wx.startRecord()</span>
  34. <span style="color:#222222">}</span><span style="color:#222222">,</span>
  35. <span style="color:#23a0ff">handleOpenPrivacyContract</span><span style="color:#222222">(</span><span style="color:#222222">)</span> <span style="color:#222222">{</span>
  36. <span style="color:rgba(0, 0, 0, 0.3)">// 打开隐私协议页面</span>
  37. wx<span style="color:#222222">.</span><span style="color:#23a0ff">openPrivacyContract</span><span style="color:#222222">(</span><span style="color:#222222">{</span>
  38. <span style="color:#23a0ff">success</span><span style="color:#ff4d00">:</span> <span style="color:#222222">(</span><span style="color:#222222">)</span> <span style="color:#ff4d00">=></span> <span style="color:#222222">{</span><span style="color:#222222">}</span><span style="color:#222222">,</span> <span style="color:rgba(0, 0, 0, 0.3)">// 打开成功</span>
  39. <span style="color:#23a0ff">fail</span><span style="color:#ff4d00">:</span> <span style="color:#222222">(</span><span style="color:#222222">)</span> <span style="color:#ff4d00">=></span> <span style="color:#222222">{</span><span style="color:#222222">}</span><span style="color:#222222">,</span> <span style="color:rgba(0, 0, 0, 0.3)">// 打开失败</span>
  40. <span style="color:#23a0ff">complete</span><span style="color:#ff4d00">:</span> <span style="color:#222222">(</span><span style="color:#222222">)</span> <span style="color:#ff4d00">=></span> <span style="color:#222222">{</span><span style="color:#222222">}</span>
  41. <span style="color:#222222">}</span><span style="color:#222222">)</span>
  42. <span style="color:#222222">}</span>
  43. <span style="color:#222222">}</span><span style="color:#222222">)</span>
  44. </code></span></span></span>

从基础库 2.32.3 版本起,隐私同意按钮支持与手机号快速验证组件手机号实时验证组件耦合使用,调用方式为 <button open-type="getPhoneNumber|agreePrivacyAuthorization"> 或 <button open-type="getRealtimePhoneNumber|agreePrivacyAuthorization">

也支持隐私同意按钮获取用户信息组件耦合使用,调用方式为<button open-type="getUserInfo|agreePrivacyAuthorization">

示例代码

  1. <span style="background-color:#f9f9fa"><span style="color:#222222"><span style="background-color:#f9f9fa"><code><span style="color:rgba(0, 0, 0, 0.3)"><!-- page.wxml --></span>
  2. <span style="color:#b457ff"><span style="color:#b457ff"><span style="color:#222222"><</span>button</span> <span style="color:#ff4d00">id</span><span style="color:#222222"><span style="color:#222222">=</span><span style="color:#222222">"</span>agree-btn1<span style="color:#222222">"</span></span> <span style="color:#ff4d00">open-type</span><span style="color:#222222"><span style="color:#222222">=</span><span style="color:#222222">"</span>getPhoneNumber|agreePrivacyAuthorization<span style="color:#222222">"</span></span> <span style="color:#ff4d00">bindgetphonenumber</span><span style="color:#222222"><span style="color:#222222">=</span><span style="color:#222222">"</span>handleGetPhoneNumber<span style="color:#222222">"</span></span> <span style="color:#ff4d00">bindagreeprivacyauthorization</span><span style="color:#222222"><span style="color:#222222">=</span><span style="color:#222222">"</span>handleAgreePrivacyAuthorization<span style="color:#222222">"</span></span><span style="color:#222222">></span></span>同意隐私协议并授权手机号<span style="color:#b457ff"><span style="color:#b457ff"><span style="color:#222222"></</span>button</span><span style="color:#222222">></span></span>
  3. <span style="color:#b457ff"><span style="color:#b457ff"><span style="color:#222222"><</span>button</span> <span style="color:#ff4d00">id</span><span style="color:#222222"><span style="color:#222222">=</span><span style="color:#222222">"</span>agree-btn2<span style="color:#222222">"</span></span> <span style="color:#ff4d00">open-type</span><span style="color:#222222"><span style="color:#222222">=</span><span style="color:#222222">"</span>getRealtimePhoneNumber|agreePrivacyAuthorization<span style="color:#222222">"</span></span> <span style="color:#ff4d00">bindgetrealtimephonenumber</span><span style="color:#222222"><span style="color:#222222">=</span><span style="color:#222222">"</span>handleGetRealtimePhoneNumber<span style="color:#222222">"</span></span> <span style="color:#ff4d00">bindagreeprivacyauthorization</span><span style="color:#222222"><span style="color:#222222">=</span><span style="color:#222222">"</span>handleAgreePrivacyAuthorization<span style="color:#222222">"</span></span><span style="color:#222222">></span></span>同意隐私协议并授权手机号<span style="color:#b457ff"><span style="color:#b457ff"><span style="color:#222222"></</span>button</span><span style="color:#222222">></span></span>
  4. <span style="color:#b457ff"><span style="color:#b457ff"><span style="color:#222222"><</span>button</span> <span style="color:#ff4d00">id</span><span style="color:#222222"><span style="color:#222222">=</span><span style="color:#222222">"</span>agree-btn3<span style="color:#222222">"</span></span> <span style="color:#ff4d00">open-type</span><span style="color:#222222"><span style="color:#222222">=</span><span style="color:#222222">"</span>getUserInfo|agreePrivacyAuthorization<span style="color:#222222">"</span></span> <span style="color:#ff4d00">bindgetuserinfo</span><span style="color:#222222"><span style="color:#222222">=</span><span style="color:#222222">"</span>handleGetUserInfo<span style="color:#222222">"</span></span> <span style="color:#ff4d00">bindagreeprivacyauthorization</span><span style="color:#222222"><span style="color:#222222">=</span><span style="color:#222222">"</span>handleAgreePrivacyAuthorization<span style="color:#222222">"</span></span><span style="color:#222222">></span></span>同意隐私协议并获取头像昵称信息<span style="color:#b457ff"><span style="color:#b457ff"><span style="color:#222222"></</span>button</span><span style="color:#222222">></span></span>
  5. </code></span></span></span>
  1. <span style="background-color:#f9f9fa"><span style="color:#222222"><span style="background-color:#f9f9fa"><code><span style="color:rgba(0, 0, 0, 0.3)">// page.js</span>
  2. <span style="color:#23a0ff">Page</span><span style="color:#222222">(</span><span style="color:#222222">{</span>
  3. <span style="color:#23a0ff">handleAgreePrivacyAuthorization</span><span style="color:#222222">(</span><span style="color:#222222">)</span> <span style="color:#222222">{</span>
  4. <span style="color:rgba(0, 0, 0, 0.3)">// 用户同意隐私协议事件回调</span>
  5. <span style="color:rgba(0, 0, 0, 0.3)">// 用户点击了同意,之后所有已声明过的隐私接口和组件都可以调用了</span>
  6. <span style="color:rgba(0, 0, 0, 0.3)">// wx.getUserProfile()</span>
  7. <span style="color:rgba(0, 0, 0, 0.3)">// wx.chooseMedia()</span>
  8. <span style="color:rgba(0, 0, 0, 0.3)">// wx.getClipboardData()</span>
  9. <span style="color:rgba(0, 0, 0, 0.3)">// wx.startRecord()</span>
  10. <span style="color:#222222">}</span><span style="color:#222222">,</span>
  11. <span style="color:#23a0ff">handleGetPhoneNumber</span><span style="color:#222222">(</span><span style="color:#ff4d00">e</span><span style="color:#222222">)</span> <span style="color:#222222">{</span>
  12. <span style="color:rgba(0, 0, 0, 0.3)">// 获取手机号成功</span>
  13. console<span style="color:#222222">.</span><span style="color:#23a0ff">log</span><span style="color:#222222">(</span>e<span style="color:#222222">)</span>
  14. <span style="color:#222222">}</span><span style="color:#222222">,</span>
  15. <span style="color:#23a0ff">handleGetRealtimePhoneNumber</span><span style="color:#222222">(</span><span style="color:#ff4d00">e</span><span style="color:#222222">)</span> <span style="color:#222222">{</span>
  16. <span style="color:rgba(0, 0, 0, 0.3)">// 获取实时手机号成功</span>
  17. console<span style="color:#222222">.</span><span style="color:#23a0ff">log</span><span style="color:#222222">(</span>e<span style="color:#222222">)</span>
  18. <span style="color:#222222">}</span><span style="color:#222222">,</span>
  19. <span style="color:#23a0ff">handleGetUserInfo</span><span style="color:#222222">(</span><span style="color:#ff4d00">e</span><span style="color:#222222">)</span> <span style="color:#222222">{</span>
  20. <span style="color:rgba(0, 0, 0, 0.3)">// 获取头像昵称成功</span>
  21. console<span style="color:#222222">.</span><span style="color:#23a0ff">log</span><span style="color:#222222">(</span>e<span style="color:#222222">)</span>
  22. <span style="color:#222222">}</span>
  23. <span style="color:#222222">}</span><span style="color:#222222">)</span>
  24. </code></span></span></span>

3. 被动监听隐私接口需要用户授权事件

从基础库 2.32.3 开始支持

小程序开发者除了可以自行判断时机,提示用户阅读隐私政策等收集使用规则外,也可以通过 wx.onNeedPrivacyAuthorization 接口来监听何时需要提示用户阅读隐私政策。当用户触发了一个微信侧未记录过同意的隐私接口调用,则会触发该事件。开发者可在该事件触发时提示用户阅读隐私政策。

需要注意的是,对于 <input type="nickname"> 组件,由于 <input> 的特殊性,如果用户未同意隐私协议,则<input type="nickname"> 聚焦时不会触发 onNeedPrivacyAuthorization 事件,而是降级为 <input type="text"> 。

此外,微信还提供了 wx.requirePrivacyAuthorize 接口,可用于模拟隐私接口调用。

代码示例

  1. <span style="background-color:#f9f9fa"><span style="color:#222222"><span style="background-color:#f9f9fa"><code>// page.wxml
  2. <span style="color:#b457ff"><span style="color:#b457ff"><span style="color:#222222"><</span>view</span> <span style="color:#ff4d00">wx:if</span><span style="color:#222222"><span style="color:#222222">=</span><span style="color:#222222">"</span>{{showPrivacy}}<span style="color:#222222">"</span></span><span style="color:#222222">></span></span>
  3. <span style="color:#b457ff"><span style="color:#b457ff"><span style="color:#222222"><</span>view</span><span style="color:#222222">></span></span>隐私弹窗内容....<span style="color:#b457ff"><span style="color:#b457ff"><span style="color:#222222"></</span>view</span><span style="color:#222222">></span></span>
  4. <span style="color:#b457ff"><span style="color:#b457ff"><span style="color:#222222"><</span>button</span> <span style="color:#ff4d00">id</span><span style="color:#222222"><span style="color:#222222">=</span><span style="color:#222222">"</span>agree-btn<span style="color:#222222">"</span></span> <span style="color:#ff4d00">open-type</span><span style="color:#222222"><span style="color:#222222">=</span><span style="color:#222222">"</span>agreePrivacyAuthorization<span style="color:#222222">"</span></span> <span style="color:#ff4d00">bindagreeprivacyauthorization</span><span style="color:#222222"><span style="color:#222222">=</span><span style="color:#222222">"</span>handleAgreePrivacyAuthorization<span style="color:#222222">"</span></span><span style="color:#222222">></span></span>同意<span style="color:#b457ff"><span style="color:#b457ff"><span style="color:#222222"></</span>button</span><span style="color:#222222">></span></span>
  5. <span style="color:#b457ff"><span style="color:#b457ff"><span style="color:#222222"></</span>view</span><span style="color:#222222">></span></span>
  6. </code></span></span></span>
  1. <span style="background-color:#f9f9fa"><span style="color:#222222"><span style="background-color:#f9f9fa"><code><span style="color:rgba(0, 0, 0, 0.3)">// page.js</span>
  2. <span style="color:#23a0ff">Page</span><span style="color:#222222">(</span><span style="color:#222222">{</span>
  3. data<span style="color:#ff4d00">:</span> <span style="color:#222222">{</span>
  4. showPrivacy<span style="color:#ff4d00">:</span> <span style="color:#ff4d00">false</span>
  5. <span style="color:#222222">}</span><span style="color:#222222">,</span>
  6. <span style="color:#23a0ff">onLoad</span><span style="color:#222222">(</span><span style="color:#222222">)</span> <span style="color:#222222">{</span>
  7. wx<span style="color:#222222">.</span><span style="color:#23a0ff">onNeedPrivacyAuthorization</span><span style="color:#222222">(</span><span style="color:#222222">(</span><span style="color:#ff4d00">resolve<span style="color:#222222">,</span> eventInfo</span><span style="color:#222222">)</span> <span style="color:#ff4d00">=></span> <span style="color:#222222">{</span>
  8. console<span style="color:#222222">.</span><span style="color:#23a0ff">log</span><span style="color:#222222">(</span><span style="color:#07c160">'触发本次事件的接口是:'</span> <span style="color:#ff4d00">+</span> eventInfo<span style="color:#222222">.</span>referrer<span style="color:#222222">)</span>
  9. <span style="color:rgba(0, 0, 0, 0.3)">// 需要用户同意隐私授权时</span>
  10. <span style="color:rgba(0, 0, 0, 0.3)">// 弹出开发者自定义的隐私授权弹窗</span>
  11. <span style="color:#b457ff">this</span><span style="color:#222222">.</span><span style="color:#23a0ff">setData</span><span style="color:#222222">(</span><span style="color:#222222">{</span>
  12. showPrivacy<span style="color:#ff4d00">:</span> <span style="color:#ff4d00">true</span>
  13. <span style="color:#222222">}</span><span style="color:#222222">)</span>
  14. <span style="color:#b457ff">this</span><span style="color:#222222">.</span>resolvePrivacyAuthorization <span style="color:#ff4d00">=</span> resolve
  15. <span style="color:#222222">}</span><span style="color:#222222">)</span>
  16. wx<span style="color:#222222">.</span><span style="color:#23a0ff">getUserProfile</span><span style="color:#222222">(</span><span style="color:#222222">{</span>
  17. success<span style="color:#ff4d00">:</span> console<span style="color:#222222">.</span>log<span style="color:#222222">,</span>
  18. fail<span style="color:#ff4d00">:</span> console<span style="color:#222222">.</span>error
  19. <span style="color:#222222">}</span><span style="color:#222222">)</span>
  20. <span style="color:#222222">}</span><span style="color:#222222">,</span>
  21. <span style="color:#23a0ff">handleAgreePrivacyAuthorization</span><span style="color:#222222">(</span><span style="color:#222222">)</span> <span style="color:#222222">{</span>
  22. <span style="color:rgba(0, 0, 0, 0.3)">// 用户点击同意按钮后</span>
  23. <span style="color:#b457ff">this</span><span style="color:#222222">.</span><span style="color:#23a0ff">resolvePrivacyAuthorization</span><span style="color:#222222">(</span><span style="color:#222222">{</span> buttonId<span style="color:#ff4d00">:</span> <span style="color:#07c160">'agree-btn'</span><span style="color:#222222">,</span> event<span style="color:#ff4d00">:</span> <span style="color:#07c160">'agree'</span> <span style="color:#222222">}</span><span style="color:#222222">)</span>
  24. <span style="color:rgba(0, 0, 0, 0.3)">// 用户点击同意后,开发者调用 resolve({ buttonId: 'agree-btn', event: 'agree' }) 告知平台用户已经同意,参数传同意按钮的id</span>
  25. <span style="color:rgba(0, 0, 0, 0.3)">// 用户点击拒绝后,开发者调用 resolve({ event:'disagree' }) 告知平台用户已经拒绝</span>
  26. <span style="color:#222222">}</span>
  27. <span style="color:#222222">}</span><span style="color:#222222">)</span>
  28. </code></span></span></span>

4. 清空历史同步状态

当用户从「微信下拉-最近-最近使用的小程序」中删除小程序,将清空历史同步状态。下次访问小程序后,需要重新同步微信当前用户已阅读并同意小程序的隐私政策等收集使用规则。

开发者可通过此方式进行调试,也可以在开发者工具中「清除模拟器缓存-清除授权数据」清空历史同步状态。

三、其他说明

  • 低于 2.32.3 版本的基础库未集成隐私相关功能,也不会拦截隐私接口调用。

四、完整示例demo

demo1: 演示使用 wx.getPrivacySetting 和 <button open-type="agreePrivacyAuthorization"> 在首页处理隐私弹窗逻辑 https://developers.weixin.qq.com/s/gi71sGm67hK0

demo2: 演示使用 wx.onNeedPrivacyAuthorization 和 <button open-type="agreePrivacyAuthorization"> 在多个页面处理隐私弹窗逻辑,同时演示了如何处理多个隐私接口同时调用。 https://developers.weixin.qq.com/s/hndZUOmA7gKn

demo3: 演示 wx.onNeedPrivacyAuthorizationwx.requirePrivacyAuthorize<button open-type="agreePrivacyAuthorization"> 和 <input type="nickname"> 组件如何结合使用 https://developers.weixin.qq.com/s/jX7xWGmA7UKa

demo4: 演示使用 wx.onNeedPrivacyAuthorization 和 <button open-type="agreePrivacyAuthorization"> 在多个 tabBar 页面处理隐私弹窗逻辑 https://developers.weixin.qq.com/s/g6BWZGmt7XK9

五、常见错误说明

  • { "errMsg": "A:fail api scope is not declared in the privacy agreement", "errno": 112 } 使用到了 A 隐私接口,但是开发者未在[mp后台-设置-服务内容声明-用户隐私保护指引]中声明收集 A 接口对应的隐私类型

uniapp小程序特别指导:

uniapp则在manifest.json中对应位置添加

 "mp-weixin": {

        "__usePrivacyCheck__": true,

封装公共方法
  1. // 查询隐私设置
  2. export const getPrivacySetting = () => new Promise((resolve, reject) => {
  3. wx.getPrivacySetting({
  4. success: res => {
  5. // 返回结果为: res = { needAuthorization: true/false, privacyContractName: '《xxx隐私保护指引》' }
  6. console.log('隐私设置getPrivacySetting', res)
  7. resolve(res)
  8. },
  9. fail: () => {
  10. reject()
  11. },
  12. });
  13. })
封装的弹窗提示组件
  1. <template>
  2. <view class="private-modal">
  3. <u-modal
  4. title="用户隐私协议"
  5. v-model="showModal"
  6. :show-confirm-button="false"
  7. :show-cancel-button="false"
  8. >
  9. <!-- 弹窗内容主体 -->
  10. <view class="content-wrap">
  11. <view
  12. >欢迎使用“xxx”!我们非常重视您的个人信息和隐私保护。在您使用xxx服务之前,请仔细阅读
  13. <text style="color: #2979ff" @click="handleOpenPrivacyContract">{{
  14. privacyContractName
  15. }}</text
  16. >,我们将严格按照经您同意的各项条款使用您的个人信息,以便为您提供更好的服务。</view
  17. >
  18. <view class="tip"
  19. >如您同意此协议,请点击“同意”并开始使用我们的产品和服务,我们将尽全力保护您的个人信息安全。</view
  20. >
  21. </view>
  22. <!-- 自定义按钮 -->
  23. <view name="confirm-button" class="handle-btns-wrap">
  24. <button @click="cancel">拒绝</button>
  25. <button
  26. open-type="agreePrivacyAuthorization"
  27. @agreeprivacyauthorization="agreeprivacyauthorization"
  28. style="color: #2979ff"
  29. @click="confirm"
  30. >
  31. 同意
  32. </button>
  33. </view>
  34. </u-modal>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. data() {
  40. return {
  41. showModal: false,
  42. privacyContractName: '',
  43. };
  44. },
  45. methods: {
  46. getPrivacySetting() {
  47. return new Promise((resolve, reject) => {
  48. wx.getPrivacySetting({
  49. success: res => {
  50. // 返回结果为: res = { needAuthorization: true/false, privacyContractName: '《xxx隐私保护指引》' }
  51. console.log('隐私设置getPrivacySetting', res);
  52. resolve(res);
  53. },
  54. fail: () => {
  55. reject();
  56. },
  57. });
  58. });
  59. },
  60. open() {
  61. return new Promise(async (resolve, reject) => {
  62. const { needAuthorization, privacyContractName } =
  63. await this.getPrivacySetting();
  64. // 需要授权
  65. if (needAuthorization) {
  66. this.privacyContractName = privacyContractName;
  67. this.showModal = true;
  68. reject();
  69. } else {
  70. resolve();
  71. }
  72. });
  73. },
  74. // 用户点击同意的回调
  75. agreeprivacyauthorization() {
  76. this.showModal = false;
  77. this.$emit('confirm');
  78. },
  79. // 打开隐私协议页面
  80. handleOpenPrivacyContract() {
  81. wx.openPrivacyContract({
  82. success: () => {}, // 打开成功
  83. fail: () => {}, // 打开失败
  84. complete: () => {},
  85. });
  86. },
  87. confirm() {},
  88. cancel() {
  89. this.showModal = false;
  90. this.$emit('cancel');
  91. },
  92. },
  93. };
  94. </script>
  95. <style lang="scss" scoped>
  96. .private-modal {
  97. .content-wrap {
  98. padding: 30rpx;
  99. }
  100. .tip {
  101. font-size: 24rpx;
  102. margin-top: 20rpx;
  103. color: #999;
  104. }
  105. .handle-btns-wrap {
  106. display: flex;
  107. align-items: center;
  108. border-top: 2rpx solid #e8e8e8;
  109. button {
  110. flex: 1;
  111. text-align: center;
  112. padding: 20rpx 0;
  113. background: none;
  114. border: none;
  115. border-radius: 0;
  116. border-color: none;
  117. font-size: 32rpx;
  118. &::after {
  119. display: none;
  120. }
  121. }
  122. }
  123. }
  124. </style>

你可以在你想要的地方引入组件,并在想要的地方调用判断

如我的页面需要微信登录调用 wx.getUserProfile

可以在涉及调用隐私api之前调用弹窗查询隐私是否同意弹窗,可以加载首页直接根据判断弹窗,可以在登录页添加等等,根据需要进行添加

可以主动查询,也可以被动查询

  1. <template>
  2. <view class="my">
  3. <navbar
  4. :title="'我的'"
  5. :isBack="false"
  6. :background="{
  7. backgroundColor: '#ffffff',
  8. }"
  9. />
  10. <view class="top flex" @click="login">
  11. <img :src="userInfo.avatarUrl" />
  12. <view class="name" v-if="hasLogin">{{ userInfo.nickName || '' }}</view>
  13. <view class="name" v-else>请登录!</view>
  14. </view>
  15. <view class="loginOut" @click="loginOut" v-if="hasLogin">退出登录</view>
  16. <!-- 点击了同意可以继续执行登录方法 -->
  17. <private-modal ref="privateModal" @confirm="login" @cancel="cancelTip" />
  18. <tab-bar />
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. data() {
  24. return {
  25. hasLogin: false,
  26. userInfo: {
  27. avatarUrl: '', //头像
  28. city: '',
  29. country: '',
  30. gender: '', //性别
  31. language: '',
  32. nickName: '', //用户名
  33. province: '',
  34. },
  35. };
  36. },
  37. async onShow() {
  38. if (uni.getStorageSync('loginInfo')) {
  39. this.getUserInfo();
  40. this.hasLogin = true;
  41. }
  42. },
  43. methods: {
  44. async login() {
  45. if (this.hasLogin) return;
  46. // 点击微信登录时调用判断,根据结果弹窗或者继续执行
  47. await this.$refs.privateModal.open();
  48. await this.$util.wxLogin();
  49. this.hasLogin = true;
  50. },
  51. loginOut() {
  52. wx.showModal({
  53. title: '温馨提示',
  54. content: '是否退出登录',
  55. success: res => {
  56. //如果用户点击了确定按钮
  57. if (res.confirm) {
  58. this.userInfo = {
  59. avatarUrl: '', //头像
  60. city: '',
  61. country: '',
  62. gender: '', //性别
  63. language: '',
  64. nickName: '', //用户名
  65. province: '',
  66. };
  67. uni.clearStorageSync(); //清空所有缓存
  68. this.hasLogin = false;
  69. } else {
  70. this.$util.showModal('您已取消退出');
  71. }
  72. },
  73. });
  74. },
  75. // 可以加提示
  76. cancelTip() {
  77. this.$util.showModal('提示:拒绝后您将无法进行微信登录', 'none', 3500);
  78. },
  79. },
  80. };
  81. </script>

同意后,如何清除隐私授权,重新触发wx.getPrivacySetting回调的needAuthorization: true判断?

当用户从「微信下拉-最近-最近使用的小程序」中删除小程序,将清空历史同步状态。下次访问小程序后,需要重新同步微信当前用户已阅读并同意小程序的隐私政策等收集使用规则。

开发者可通过此方式进行调试,也可以在开发者工具中「清除模拟器缓存-清除授权数据」清空历史同步状态

如下图:先点击清除授权数据,再点击编译进行重新编译

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/280319
推荐阅读
相关标签
  

闽ICP备14008679号