• 给微信小程序添加隐私协议


    前些日子,微信官方针对用户的安全信息又进行了增强,这次更新几乎要求所有的小程序都需要进行整改,只要是涉及到用户的隐私的小程序都需要进行整改,这次整改是强制性的。
    在这里插入图片描述
    点开相关指引之后会跳转到下面的链接:参考链接,这里面有相关的整改措施。
    这里使用uniapp进行演示,对于原生微信小程序基本一致
    在这里插入图片描述
    然后需要在小程序的首页去校验用户是否需要弹出隐私对话框部分核心代码如下:
    这里一定要进行try catch,因为getPrivacySetting对于低版本的微信客户端不支持

       <template>
          <!-- 小程序官方隐私授权 -->
          <u-modal show-cancel-button v-model="showPrivacy" @confirm="confirmPrivacy" cancel-text="拒绝" title="隐私政策">
            <template #default>
              <!-- defaultdefaultdefault -->
              <view class="privacyTips">
                请您务必审慎阅读、充分理解"隐私政策"各条款包括但不限于为了向您提供持续的服务,我们需要收集您的设备信息您可以阅读<span class="privateTitle" @click="openPrivacyContract">《大地云农小程序隐私协议条款》</span>了解详细信息如您同意,请点击"同意"开始接受我们的服务。
              </view>
            </template>
            <template #confirm-button>
              <button plain id="agree-btn" open-type="agreePrivacyAuthorization" bindagreeprivacyauthorization="handleAgreePrivacyAuthorization">同意</button>
            </template>
          </u-modal>
          <!-- 针对低版本的用户要求升级客户端 -->
          <u-modal v-model="show1" :content="content1" @confirm="confirmExit"></u-modal>
      </template>
      onShow() {
        this.checkPrivacy()
      },
      data() {
    	  return {
       		   showPrivacy:false,
       		   content1:"",
       		   show1:fasle
    	  }
      }methods: {
       checkPrivacy(){
         try {
           wx.getPrivacySetting({
             success: res => {
               console.log(res) // 返回结果为: res = { needAuthorization: true/false, privacyContractName: '《xxx隐私保护指引》' }
               console.log('是否需要弹出隐私政策',res.needAuthorization);
               if (res.needAuthorization) {
                 this.showPrivacy=true
               }
             },
           })  
         } catch (error) {
           // console.log(error);
           this.show1=true
           this.content1='当前微信版本过低,无法使用小程序,请升级到最新微信版本后删除小程序并重新进入'
         }
       },
        handleAgreePrivacyAuthorization() {
          // 用户点击同意按钮后
          console.log(555,this.resolvePrivacyAuthorization);
          if(this.resolvePrivacyAuthorization){
            this.resolvePrivacyAuthorization({ buttonId: 'agree-btn', event: 'agree' })
            // 用户点击同意后,开发者调用 resolve({ buttonId: 'agree-btn', event: 'agree' })  告知平台用户已经同意,参数传同意按钮的id
            // 用户点击拒绝后,开发者调用 resolve({ event:'disagree' }) 告知平台用户已经拒绝
          }
    
        },
        confirmPrivacy(){
          this.handleAgreePrivacyAuthorization()
        },
        // 确认退出小程序
        confirmExit(){
          wx.exitMiniProgram({
            success: () => {
              console.log('退出成功');
            }, // 打开成功
          })
        },
        openPrivacyContract(){
          wx.openPrivacyContract({
            success: () => {}, // 打开成功
          })
        }
      }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71

    注意:一定要先在小程序的后台填写用户用户隐私保护指引,否则相关的隐私一个也无法调用成功。
    在这里插入图片描述

  • 相关阅读:
    【数据结构】栈和队列
    RK3588开发板的性能参数、功耗及功能特点|飞凌动态讲解
    迅为IMX8M开发板安装VMware Tool工具
    b站手机缓存文件转MP4
    MinGW-w64下载文件失败the file has been downloaded incorrectly!
    网络基础知识点
    软件测试架构师的知识能力模型
    一文解读 SmartX 超融合虚拟化下的网络 I/O 虚拟化技术
    RabbitMQ系列【1】概述
    【洛谷 P1364】医院设置 题解(图论+深度优先搜索)
  • 原文地址:https://blog.csdn.net/ksjdbdh/article/details/132922576