uniapp微信小程序《隐私保护协议》弹窗处理流程

news2025/5/26 9:35:53
背景

请添加图片描述
《关于小程序隐私保护指引设置的公告》
《小程序隐私协议开发指南》

流程

1.第一步
必须设置且审核通过!!!
在这里插入图片描述
2.第二步

uniapp在manifest.json中添加!!!

/*
在 2023年9月15号之前,在 app.json 中配置 __usePrivacyCheck__: true 后,会启用隐私相关功能,如果不配置或者配置为 false 则不会启用。
在 2023年9月15号之后,不论 app.json 中是否有配置 __usePrivacyCheck__,隐私相关功能都会启用。
*/
"mp-weixin": { /* 微信小程序特有相关 */
	"appid": "wxc8888888888",
	"__usePrivacyCheck__":true,
	"plugins": {
	    "WechatSI": {
	      "version": "0.3.5",
	      "provider": "wx069ba97219f66d99"
	    }
	 },
},

很多人前两步没做或者做的不对,导致出现needAuthorization一直为false情况

{needAuthorization: false, privacyContractName: "《小程序隐私保护指引》", errMsg: "getPrivacySetting:ok"}

3.第三步
此处需要根据情况决定,在何时弹出隐私授权弹窗:
1.进入小程序就弹(对开发来说好,就是用户体验不好)
2.在使用到的页面弹出(繁琐,但是用户体验好,有些小程序可能就一两个页面涉及)
3.本示例采用方法2,因为就一个页面需要用到音视频授权,流程为进入需要使用的页面,弹出隐私授权,等待用户确认后,依次弹出音频授权、视频授权确认,让用户一次性点完,以免多处导致用户不耐烦。
如图:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

<template>
	<!-- 如果拒绝隐私授权或者音视频授权,当我们触发例如音频时,会再次弹出 -->
	<button @longpress="startRecord" @touchend="endRecord" type="default">长按发送语音</button>
	<!-- camera组件等自动触发【视频授权】会和【隐私授权】同时出现情况,需要在隐私授权之前隐藏 -->
	<camera v-if="empower"></camera>
	<!-- 隐私授权弹窗 -->
	<view class="mask flex alic justc" v-if="showPrivacy">
	    <view class="privacyBox">
	        <view class="title fz16 fw tc lh40">用户隐私保护</view>
	        <view class="txt borBox fz14 lh22 color3">
	            感谢您使用本产品,您使用本产品前应当仔细阅读并同意<text class="colorb" @click="handleOpenPrivacyContract">《小程序隐私保护指引》</text>当您点击同意并开始使用产品服务时,即表示你已理解并同意该条款内容,该条款将对您产生法律约束力。如您拒绝,将无法更好的体验产品。
	        </view>
	        <view class="footer flex justsa alic">
	            <button class="cancel borBox" type="primary" @click="showPrivacy = false">拒绝</button>
	            <button class="iknow" type="primary" id="agree-btn" open-type="agreePrivacyAuthorization" @agreeprivacyauthorization="handleAgreePrivacyAuthorization">同意</button>
	        </view>
	    </view>
	</view>
</template>

<script>
//同声传译
const plugin = requirePlugin("WechatSI");
const manager = plugin.getRecordRecognitionManager();
export default {
	data(){
		return {
			// 是否弹出隐私授权弹窗
			showPrivacy: false,
			// 是否点击同意隐私授权,此变量为了防止例如camera组件等自动触发【视频授权】会和【隐私授权】同时出现情况
			// 只需在未同意隐私授权情况下,隐藏会触发uni.authorize效果的组件,如下
			// <camera v-if="empower"></camera>
            empower:false,
		}
	},
	async onLoad(val) {
		// 模拟隐私接口调用,并触发隐私弹窗逻辑
        // wx.requirePrivacyAuthorize({
        //     success: () => {
        //         console.log('点击同意');
        //         this.showPrivacy = true
        //     },
        //     fail: () => {
        //         console.log('点击拒绝');       
        //     }, 
        //     complete: () => {
        //         console.log('用户已点击');
        //     }
        // })
        // 监听隐私接口需要用户授权事件,处理被拒绝情况下再次唤醒弹窗
        if (wx.onNeedPrivacyAuthorization) {
            wx.onNeedPrivacyAuthorization(resolve => {
                // 需要用户同意隐私授权时,弹出开发者自定义的隐私授权弹窗
                this.showPrivacy = true
                console.log(resolve)
            })
        }
        // 查询隐私授权情况,进入页面有需要直接弹出情况
        wx.getPrivacySetting({
            success: res => {
                console.log(res) // 返回结果为: res = { needAuthorization: true/false, privacyContractName: '《xxx隐私保护指引》' }
                if (res.needAuthorization) {
                    console.log('需要授权???')
                    // 需要弹出隐私协议
                    this.showPrivacy = true
                    this.empower = false
                } else {
                    console.log('已授权???')
                    this.empower = true
                    // 用户已经同意过隐私协议,所以不需要再弹出隐私协议,也能调用已声明过的隐私接口
                    // wx.getUserProfile()
                    // wx.chooseMedia()
                    // wx.getClipboardData()
                    // wx.startRecord()
                }
            },
            fail: () => { },
            complete: () => { }
        })
	},
	methods: {
		// 开始录音
        async startRecord() {
            manager.stop();
            // 点击录音再次检验权限
            await this.getAuth('scope.camera')
            await this.getAuth('scope.record')
            manager.start({
                lang: "zh_CN",
                duration: 60 * 1000
            });
        },
        // 结束录音
        endRecord() {
            manager.stop();
        },
        // 用户隐私协议确认按钮
		handleAgreePrivacyAuthorization(e) {
            console.log('确认',e)
            this.showPrivacy = false
            this.empower = true
            // 点击同意隐私授权后依次弹出授权
            this.getAuth('scope.camera', false)
            this.getAuth('scope.record', false)
            // 用户同意隐私协议事件回调
            // 用户点击了同意,之后所有已声明过的隐私接口和组件都可以调用了
            // wx.getUserProfile()
            // wx.chooseMedia()
            // wx.getClipboardData()
            // wx.startRecord()
        },
        // 打开协议
        handleOpenPrivacyContract() {
            // 打开隐私协议页面
            wx.openPrivacyContract({
                success: () => { }, // 打开成功
                fail: () => { }, // 打开失败
                complete: () => { }
            })
        },
        /**
         * 根据权限名检查权限是否开启,未开启引导开启
         * @param { string } name 
         * @param { boolean } showAgain 拒绝后再次点击触发弹窗跳转授权列表页
         */
        getAuth(name, showAgain = true) {
            const nameObj = {
                'scope.camera': '摄像头',
                'scope.record': '麦克风'
            }
            let authCamera = false
            return new Promise((res, rej) => {
                uni.getSetting({
                    success(e) {
                        if (!e.authSetting[name]) {
                            uni.authorize({
                                scope: name,
                                // success(){
                                //     console.log('获取权限')
                                // },
                                fail() {
                                    if (showAgain) {
                                        uni.showModal({
                                            title: '提示',
                                            content: `您已拒绝授权,为了更好的体验,请重新授权使用${nameObj[name]}`,
                                            success(event) {
                                                if (event.confirm) {
                                                    uni.openSetting({
                                                        success(data) {
                                                            if (data.authSetting[name]) {
                                                                authCamera = true
                                                                res(true)
                                                            } else {
                                                                uni.showToast({
                                                                    title: '未授权',
                                                                    icon: 'none'
                                                                })
                                                            }
                                                        }
                                                    })
                                                }
                                            }
                                        })
                                    }
                                }
                            })
                        } else {
                            authCamera = true
                            res(true)
                        }
                    }
                })
                return authCamera
            })
        },
	}
}
</script>

<style lang="less" scoped>
	// 缺少的样式从下面样式表获取
	.privacyBox{
        background: #fff;
        width: 70vw;
        border-radius: 6px;
        .title{
            border-bottom:1px solid #ebedf0;
        }
        .txt{
            // height: 30vh;
            // overflow-y: auto;
            padding: 10px;
        }
        .footer{
            border-top:1px solid #ebedf0;
            .cancel{
                color: #666;
                background-color: #fff;
                font-size: 14px;
                border: 1px solid #aaa;
                border-radius: 20px;
                margin: 8px 0;
                width: 100px;
            }
            .iknow{
                color: #fff;
                background-color: #409eff;
                font-size: 14px;
                border-radius: 20px;
                margin: 8px 0;
                width: 100px;
            }
        }
    }
</style>

样式表

@charset "utf-8";
/* CSS Document */
html,body{height: 100%;width: 100%;word-wrap:break-word;}
.w50{width: 50%;}
.w100{width: 100%;}
*{margin: 0;padding: 0;outline: none;}
.tc{text-align: center}
.tl{text-align: left;}
.tr{text-align: right}
.vm{vertical-align: middle;}
.fl{float: left;}
.fr{float: right;}
.fz26{font-size: 26px;}
.fz25{font-size: 25px;}
.fz24{font-size: 24px;}
.fz22{font-size: 22px;}
.fz20{font-size: 20px;}
.fz18{font-size: 18px;}
.fz16{font-size: 16px;}
.fz14{font-size: 14px;}
.fz12{font-size: 12px;}
.fz11{font-size: 11px;-webkit-transform: scale(0.85);transform: scale(0.85);display: inline-block;transform-origin: left;}
.fz10{font-size: 10px;-webkit-transform: scale(0.8);transform: scale(0.8);display: inline-block;transform-origin: left;}
.fw{font-weight: 600;font-weight: bold;}
.fw4{font-weight: 400;}
.fwB{font-weight: bold;}
.mr5{margin-right: 5px}
.mr10{margin-right: 10px}
.mr12{margin-right: 12px}
.mr15{margin-right: 15px}
.mr20{margin-right: 20px}

.ml5{margin-left:5px;}
.ml10{margin-left:10px;}
.ml12{margin-left:12px;}
.ml15{margin-left:15px;}
.ml20{margin-left:20px;}

.mt40{margin-top:40px;}
.mt20{margin-top: 20px;}
.mt15{margin-top: 15px;}
.mt12{margin-top: 12px;}
.mt10{margin-top: 10px;}
.mt5{margin-top: 5px;}
.mt3{margin-top: 3px;}
.mt7{margin-top: 7px;}

.mb5{margin-bottom: 5px;}
.mb10{margin-bottom: 10px;}
.mb12{margin-bottom: 12px;}
.mb15{margin-bottom: 15px;}
.mb20{margin-bottom: 20px;}

.pt5{padding-top: 5px;}
.pt10{padding-top: 10px;}
.pt12{padding-top: 12px;}
.pt15{padding-top: 15px;}
.pt20{padding-top: 20px;}

.pb5{padding-bottom: 5px;}
.pb10{padding-bottom: 10px;}
.pb12{padding-bottom: 12px;}
.pb15{padding-bottom: 15px;}
.pb20{padding-bottom: 20px;}

.pl5{padding-left: 5px;}
.pl10{padding-left: 10px;}
.pl12{padding-left: 12px;}
.pl15{padding-left: 15px;}
.pl20{padding-left: 20px;}

.pr5{padding-right: 5px;}
.pr10{padding-right: 10px;}
.pr12{padding-right: 12px;}
.pr15{padding-right: 15px;}
.pr20{padding-right: 20px;}
.bgf{background: #fff;}
.bgea{background: #EAEAEA;}
.bgF3{background: #5377F3;}
.bg48{background: #F2B448;}
.bgA2{background: #00D7A2;}
.bgF4{background: #FFFBF4;}
.bgFb{background: #EEFFFB;}
.bgs{ box-shadow: 0px 0px 15px #eee;}


.colorF{color: #fff;}
.color3{color: #333;}
.color6{color: #666;}
.color9{color: #999;}
.color49{color: #494949;}
.color80{color: #808080;}
.colorA5{color:#A5A5A5}
.colorb{color:blue}
.colorF3{color: #5377F3;}
.color48{color: #F2B448;}
.colorA2{color: #00D7A2;}
.color00{color: #FF0000}
.color26{color: #FFA926;}


.lh20{line-height: 20px;}
.lh22{line-height: 22px;}
.lh24{line-height: 24px;}
.lh30{line-height: 30px;}
.lh36{line-height: 36px;}
.lh40{line-height: 40px;}
.lh50{line-height: 50px;}
.lh60{line-height: 60px;}

.hide{display: none}
.show{display: block}
.inline{display: inline-block;}
.indent2{text-indent: 2em;}
.txt2{
  overflow : hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.txt3{
  overflow : hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
.txtno{white-space: nowrap;}/*不换行*/
.txtsa{text-align: justify;text-align-last: justify;}/*文字分散对齐*/
.wn{white-space:nowrap;}

.flex{display: flex;}
.flex1{flex:1;}
.colu{flex-direction: column;}
.justc{justify-content: center;}
.justs{justify-content: space-between}/*两端对齐*/
.justsa{justify-content: space-around}/*分散对齐*/
.juste{justify-content: flex-end;}
.alic{align-items: center}
.wrap{flex-wrap:wrap}
.childEnd{align-self:flex-end;}

.posAbs{position: absolute;}
.posRel{position: relative;}
.posFix{position: fixed;}
.top0{top:0;}
.bottom0{bottom:0;}
.left0{left:0;}
.right0{right: 0;}
.w100{width: 100%}
.h100{height: 100%}

.border0{border:0}
.borBox{box-sizing: border-box;}
.borderte0{border-top:1px solid #e0e0e0; }
.borderbe0{border-bottom:1px solid #e0e0e0; }
.borRad{border-radius:5px;}
.borRad50{border-radius:50%;}
.over{overflow:hidden;white-space:nowrap;text-overflow:ellipsis;}
.overH{overflow: hidden}
.overS{overflow: scroll;}
.clear{zoom:1;}
.clear:after{content: "\0020";display: block;height: 0;clear: both;}
.mask{width: 100%;height: 100%;background: rgba(20, 20, 20, 0.5);position: fixed;z-index: 5;top: 0;left: 0;}

.cursor{cursor: pointer;}
.noClick{pointer-events: none;}
li{list-style:none;}
a{text-decoration:none;color:#555;}
a:hover{color:#555;}
img{display:block;vertical-align:middle;}
a img,fieldset{border:0;}
i,em{font-style:normal}
input,textarea,select{outline:none;}
textarea{resize:none;}
table{border-collapse:collapse;}
[v-cloak] {
    display: none;
}
备注

下雨了

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1010407.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

汽车电子智能仓储系统的发展趋势与应用探索

现代汽车制造业中的仓储管理一直面临着多种挑战。仓库中物料的数量种类繁多&#xff0c;寻找物料耗时长、困难大。盘点过程耗费人力多、成本高、速度慢。管理无法达到先进先出的原则&#xff0c;也无法进行精准追溯。此外&#xff0c;多发、少发、错料等问题时有发生。仓库中的…

docker学习:dockerfile和docker-compose

学习如何使用dockerfile 以下内容&#xff0c;部分来自gpt生成&#xff0c;里面的描述可能会出现问题&#xff0c;但代码部分&#xff0c;我都会进行测试。 1. 需求 对于一个docker&#xff0c;例如python&#xff0c;我们需要其在构建成容器时&#xff0c;就有np。有以下两种方…

Linux内核源码分析 (B.x)Linux物理内存的初始化

Linux内核源码分析 (B.x)Linux物理内存的初始化 文章目录 Linux内核源码分析 (B.x)Linux物理内存的初始化一、DDR简介二、内存节点三、内存管理区域ZONE四、 struct zone五、 struct page六、mem_map数组七、伙伴系统简介八、迁移类型九、内存初始化十、总结 一、DDR简介 详细可…

电脑msvcp140.dll丢失问题的三种解决方法分享,快速修复dll问题

在我们的日常生活中&#xff0c;计算机已经成为了我们工作、学习和娱乐的重要工具。然而&#xff0c;在使用计算机的过程中&#xff0c;我们可能会遇到各种问题&#xff0c;其中之一就是 msvcp140.dll 丢失的困扰。本文将详细介绍 msvcp140.dll 丢失的原因、解决方法以及预防措…

可变参数JAVA

public class Main {public static void main(String[] args) {//方法形参的个数是可以变化的//格式&#xff1a;属性类型...名字System.out.println(getSum(1,2,3,4,5,6,7,8));}//通过键值对对象来遍历&#xff1b;public static int getSum(int a,int...args){//可变参数;int…

AirTag是什么?高精度测距定位防丢,UWB厘米级方案应用

随着科技的不断发展&#xff0c;超宽带&#xff08;UWB&#xff09;技术作为一种新兴的无线通信技术&#xff0c;逐渐受到人们的关注和追捧。 UWB技术以其传输速率高、抗干扰性强、带宽极宽、功耗低、安全性高、穿透力强、定位精准等优势&#xff0c;在众多领域具有广泛的应用…

输电线路故障数据集(基于simulink仿真批量生成故障数据,单相接地故障、两相接地故障、两相间短路故障、三相接地故障、三相间短路故障和正常)

分别获取单相接地故障、两相接地故障、两相间短路故障、三相接地故障、三相间短路故障和正常状态下的电流&#xff08;Ia,Ib,Ic&#xff09;大小和电压&#xff08;Ua,Ub和Uc&#xff09;大小。每种故障下获取1300行左右的数据 将故障区分为具体的不同类型&#xff08;一共五种…

JetBrains设置inline hint的背景色、前景色

如题。修改IDE的hint前景色和背景色。 修改后结果&#xff1a;

为什么DasViewer打开之后一直白屏?如图

答&#xff1a;这种情况可以检查一下电脑的集显驱动。 DasViewer是由大势智慧自主研发的免费的实景三维模型浏览器,采用多细节层次模型逐步自适应加载技术,让用户在极低的电脑配置下,也能流畅的加载较大规模实景三维模型,提供方便快捷的数据浏览操作。#DasViewer##实景三维##三…

跟踪源码技巧+阅读源码工具Sourcetrail

基于Eclipse IDE 1、Quick Type Hierarchy 快速查看类继承体系 &#xff08; 快捷键&#xff1a;Ctrl T&#xff09; 查看类很多人可能都知道&#xff0c;可源码阅读的时候更多用来查看方法体系更重要&#xff0c;可以方便快速的定位到方法的实现类。如&#xff1a; 此时如…

Mendelay-文献管理软件使用教程

Mendelay-文献管理软件 注册账号 注册账号 打开官网&#xff0c;注册个人账号 通过邮箱就可以注册账号啦&#xff0c;这是登录后的页面&#xff0c;并下载Mendeley客户端。 安装好客户端&#xff0c;打开软件首先登录以上注册的账号&#xff0c;则可进入客户端首页。

《安富莱嵌入式周报》第322期:自制10KV电子负载,史上最详细的电池系列资料,创意洞洞板任意互联,开源USB分析仪,英特尔雷电5, QNX功能安全免费课程

周报汇总地址&#xff1a;嵌入式周报 - uCOS & uCGUI & emWin & embOS & TouchGFX & ThreadX - 硬汉嵌入式论坛 - Powered by Discuz! 视频版&#xff1a; https://www.bilibili.com/video/BV1M8411q7dw/ 《安富莱嵌入式周报》第322期&#xff1a;自制10K…

nvue文件中@click.stop失效

在nvue文件中在子元素使用click.stop失效&#xff0c;父元素的事件触发了 在uniapp开发中nvue文件是跟vue文件是不一样的&#xff0c;就比如click.stop阻止点击事件继续传播就失效了&#xff0c;这时我们需要在子元素事件中添加条件编译&#xff0c;这样就会解决这个问题 // …

图论第三天|130. 被围绕的区域、417. 太平洋大西洋水流问题、827. 最大人工岛

130. 被围绕的区域 文档讲解 &#xff1a;代码随想录 - 130. 被围绕的区域 状态&#xff1a;开始学习。 思路&#xff1a; 步骤一&#xff1a; 深搜或者广搜将地图周边的 ‘O’ 全部改成 ’A’&#xff0c;如图所示&#xff1a; 步骤二&#xff1a; 再遍历地图&#xff0c;将 …

记录一次使用网云穿实现内网穿透操作

记录一次使用网云穿实现内网穿透操作 摘要 这段时间也很少写博客了,一方面工作表较忙,一方面觉得有些东西在百度上都能找到,甚至比我自己记录的详细,有些笔记也就没打, 这次记录笔记主要是觉得这个 网云穿 很好用,分享给大家. 1 什么是内网穿透? 内网穿透也叫内网映射&#xf…

zookeeper最基础教程

文章目录 一、简介1、工作机制2、特点3、数据结构4、应用场景5、选举机制 二、软件安装1、单机版安装2、集群安装3、配置参数解读(zoo.cfg)4、ZK集群启动脚本 三、命令行操作1、语法2、使用3、节点相关4、监听器原理5、节点删除与查看 三、写数据流程 一、简介 1、工作机制 官…

输电线路故障数据集(单相接地故障、两相接地故障、两相间短路故障、三相间短路故障)

1.数据集介绍 将故障区分为具体的不同类型&#xff1a;单相短路故障、两相接地短路故障、两相相间故障、三相相间短路故障。每类有1300行数据左右&#xff0c;这里随意举出每种类别的两个样本进行展示。 GCBAIaIbIcVaVbVc1001-151.2918124-9.67745156385.800162260.400749853…

Hadoop设置固定ip无效的解决办法

今天配置Hadoop的时候&#xff0c;执行vi /etc/sysconfig/network-scripts/ifcfg-ens33修改网络配置文件后&#xff0c;一切正常&#xff0c;但重启后IP改变了&#xff0c;并且在修改以及重启网络连接数次后&#xff0c;IP依旧不按照我在ifcfg-ens33中配置的那样&#xff0c;检…

C++ - map 的 例题

前言 本博客在 一下文章关于 map 和 set 讲解之下&#xff0c;对 map 当中的 operator[] &#xff08;&#xff09;函数的功能运用&#xff0c;感受 map 功能强大。 349. 两个数组的交集 - 力扣&#xff08;LeetCode&#xff09; 给定两个数组 nums1 和 nums2 &#xff0c;返回…

Python —— 捕获异常

1、Python中常见的异常 & 捕获异常 1、常见异常 1、NameError: name a is not defined 2、IndexError: list index out of range 3、KeyError: nam 4、ValueError: invalid literal for int() with base 10: b 5、ZeroDivisionError: div…