微信小程序新版协议弹窗

微信小程序新版隐私协议弹窗实现最新版

1. 微信小程序又双叒叕更新了

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中加入"usePrivacyCheck": true
 "mp-weixin" : {
        "appid" : "wx4xxxxxxxxa5c",
        "__usePrivacyCheck__": true
  },

    
    

涉及到以下接口的地方需要加上隐私协议弹窗

处理的信息接口或组件
收集你的昵称、头像、、wx.getUserInfo (已回收)、wx.getUserProfile (已回收)、(已回收)
收集你的位置信息wx.authorize({scope:‘scope.userLocation’})、wx.authorize({scope: ‘scope.userLocationBackground’})、wx.authorize({scope: ‘scope.userFuzzyLocation’})、wx.getLocation、wx.startLocationUpdate、wx.startLocationUpdateBackground、wx.getFuzzyLocation
收集你选择的位置信息wx.choosePoi、wx.chooseLocation
收集你的地址wx.chooseAddress
收集你的发票信息wx.chooseInvoiceTitle、wx.chooseInvoice
收集你的微信运动步数wx.authorize({scope: ‘scope.werun’})、wx.getWeRunData
收集你的手机号
收集你的车牌号wx.chooseLicensePlate
收集你选中的照片或视频信息wx.chooseImage、wx.chooseMedia、wx.chooseVideo
收集你选中的文件wx.chooseMessageFile
访问你的麦克风wx.authorize({scope: ‘scope.record’})、wx.startRecord、RecorderManager.start、、wx.joinVoIPChat
访问你的摄像头wx.authorize({scope: ‘scope.camera’})、wx.createVKSession、、、
访问你的蓝牙wx.authorize({scope: ‘scope.bluetooth’})、wx.openBluetoothAdapter、wx.createBLEPeripheralServer
使用你的相册(仅写入)权限wx.authorize({scope: ‘scope.writePhotosAlbum’})、wx.saveImageToPhotosAlbum、wx.saveVideoToPhotosAlbum
使用你的通讯录(仅写入)权限wx.authorize({scope: ‘scope.addPhoneContact’})、wx.addPhoneContact
使用你的日历(仅写入)权限wx.authorize({scope: ‘scope.addPhoneCalendar’})、wx.addPhoneRepeatCalendar、wx.addPhoneCalendar
调用你的加速传感器wx.stopAccelerometer、wx.startAccelerometer、wx.onAccelerometerChange、wx.offAccelerometerChange
调用你的磁场传感器wx.stopCompass、wx.startCompass、wx.onCompassChange、wx.offCompassChange
调用你的方向传感器wx.stopDeviceMotionListening、wx.startDeviceMotionListening、wx.onDeviceMotionChange、wx.offDeviceMotionChange
调用你的陀螺仪传感器wx.stopGyroscope、wx.startGyroscope、wx.onGyroscopeChange、wx.offGyroscopeChange
读取你的剪切板wx.setClipboardData、wx.getClipboardData

2. 实现思路

  1. 初始化进入小程序时先检测用户是否已经授权了隐私协议。如果没有授权,就弹出用户授权隐私协议的弹窗
  2. 用户点击确认授权,即可正常使用小程序
  3. 用户如果取消授权,当用户点击需要授权的功能,比如获取手机号的按钮,开启蓝牙的按钮等待涉及用户隐私的功能,就重新弹窗,让用户确认授权后,才能使用对应的功能。否则只能浏览页面,无法使用小程序的功能。
  4. 隐私协议的名字和内容都是通过微信接口获得的。
    获取隐私协议名字接口
 uni.getPrivacySetting({
          success: res => {
            console.log("是否需要授权:", res.needAuthorization, "隐私协议的名称为:", res.privacyContractName)
          },
          fail: () => {
          },
          complete: () => {},
        })

    
    

获取隐私协议内容接口如下,调用该方法会自动进入隐私协议详情页面。

 openYsXyDetail(){
      uni.openPrivacyContract({});
},

    
    
  1. 如果是原生小程序只需要把下方代码实现中的所有uni.替换为wx.即可使用

3. 实现效果

用户初始化进入小程序时,弹出授权窗口,用户点击登录按钮时,如果未授权也弹出此窗口
在这里插入图片描述

4. 代码实现

<template>
  <view class="login-page">
<!--    当用户点击授权同意隐私协议后才可以正常点击登录按钮获取手机号码-->
    <button open-type="getPhoneNumber" @getphonenumber="authPhone" v-if="ysxy.agree">
      <u-icon name="fingerprint" color="#2979ff" size="68"></u-icon>
    </button>
    <!--    当用户未授权同意意思协议时,打开授权隐私协议的弹窗,否则无法登录系统-->
    <button v-else @click="ysxy.show = true">
      <u-icon name="fingerprint" color="#2979ff" size="68"></u-icon>
    </button>
    <u-modal v-model="ysxy.show" :negative-top="200" title="用户隐私提示保护" :show-confirm-button="false"
             :mask-close-able="true">
      <view class="slot-content" >
        <view class="ysbox">
          感谢您使用本产品,您使用本产品前应当仔细阅读并同意<span  @click="openYsXyDetail" class="ysname">{
     
     { ysxy.name }}</span>
          当您点击同意并开始使用产品服务时,即表示你已理解并同意该条款内容,该条款将对您产生法律约束力。如您拒绝,将无法更好的体验产品。
        </view>
        <div class="auth-btncard">
          <div class="btn-unok">
            <u-button :hair-line='false' :custom-style="customStyleUnOk" @click="ysxy.show=false">
              拒绝</u-button>
          </div>
          <div class="btn-ok">
            <u-button :hair-line='false' :custom-style="customStyleOk" open-type="agreePrivacyAuthorization"
                      @click="ysxy.show=false;ysxy.agree=true;"> 同意</u-button>
          </div>
        </div>
      </view>
    </u-modal>
  </view>
</template>
<script>
import global from "../../common/utils/global";
export default {
  data() {
    return {
      ysxy:{
        show:false,
        name:'《小程序隐私保护指引》',
        agree:false
      },
      customStyleOk: {
        marginTop: '20rpx', // 注意驼峰命名,并且值必须用引号包括,因为这是对象
        border: 'none',
        color: '#157DFB'
      },
      customStyleUnOk: {
        marginTop: '20rpx', // 注意驼峰命名,并且值必须用引号包括,因为这是对象
        border: 'none',
        color: 'gray'
      },
    }
  },
  onLoad(option) {
    //#ifdef MP-WEIXIN
    this.initYsxy();
    //#endif
  },
  methods: {
    openYsXyDetail(){
      uni.openPrivacyContract({});
    },
    initYsxy(){
      this.ysxy.agree = false;
      let _this=this;
      if (uni.getPrivacySetting) {
        uni.getPrivacySetting({
          success: res => {
            console.log("是否需要授权:", res.needAuthorization, "隐私协议的名称为:", res.privacyContractName)
            if (res.needAuthorization) {
              _this.ysxy.name = res.privacyContractName
              _this.ysxy.show = true;
            } else {
              //已经同意了
              _this.ysxy.agree = true;
            }
          },
          fail: () => {
          },
          complete: () => {},
        })
      }
    },
  }
}
</script>
<style lang="scss" scoped>
.ysbox{
  margin: 40rpx;
  .ysname{
    color: #157DFB;
  }
}
.auth-btncard {
  .btn-unok {
    width: 50%;
    float: left;
  }
  .btn-ok {
    width: 50%;
    float: left;
    margin: 0;
    padding: 0;
    border: 0px solid transparent; //自定义边框
    outline: none; //消除默认点击蓝色边框效果
    u-button {
      margin: 0;
      padding: 0;
      border: 0px solid transparent; //自定义边框
      outline: none; //消除默认点击蓝色边框效果
    }
  }
}

</style>

文章知识点与官方知识档案匹配,可进一步学习相关知识
小程序技能树首页概览 7256 人正在系统学习中
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是微信小程序开发实现签到的步骤和代码示例: 1. 在wxml文件中添加签到按钮和组件 ```html <!-- 签到按钮 --> <button bindtap="showModal">签到</button> <!-- 组件 --> <view class="modal" hidden="{{!modalHidden}}"> <view class="modal-dialog"> <view class="modal-header"> <text class="modal-title">签到成功</text> </view> <view class="modal-body"> <text>恭喜您获得了一次抽奖机会!</text> </view> <view class="modal-footer"> <button class="modal-button" bindtap="hideModal">确定</button> </view> </view> </view> ``` 2. 在js文件中添加显示和隐藏的函数 ```javascript Page({ data: { modalHidden: true }, showModal: function() { this.setData({ modalHidden: false }) }, hideModal: function() { this.setData({ modalHidden: true }) } }) ``` 3. 在wxss文件中添加的样式 ```css .modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); z-index: 999; } .modal-dialog { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 80%; max-width: 400rpx; background-color: #fff; border-radius: 10rpx; overflow: hidden; } .modal-header { padding: 20rpx; text-align: center; background-color: #f8f8f8; } .modal-title { font-size: 32rpx; font-weight: bold; } .modal-body { padding: 20rpx; text-align: center; } .modal-footer { padding: 20rpx; text-align: center; background-color: #f8f8f8; } .modal-button { display: inline-block; padding: 10rpx 20rpx; border: 1rpx solid #ccc; border-radius: 5rpx; background-color: #fff; color: #333; } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值