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

前些日子,微信官方针对用户的安全信息又进行了增强,这次更新几乎要求所有的小程序都需要进行整改,只要是涉及到用户的隐私的小程序都需要进行整改,这次整改是强制性的。
在这里插入图片描述
点开相关指引之后会跳转到下面的链接:参考链接,这里面有相关的整改措施。
这里使用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: () => {}, // 打开成功
      })
    }
  }

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

白嫖leader

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值