微信小程序防止截屏录屏

一、使用css添加水印

使用微信小程序原生的view和css给屏幕添加水印这样可以防止用户将小程序内的隐私数据进行截图或者录屏分享导致信息泄露,给小程序添加一个水印浮层。这样即使被截图或者拍照,也能轻松地确定泄露的源头。效果图如下:

代码片段 https://developers.weixin.qq.com/s/V9dcdgmc7mOy

wxml文件:

注意回车符“\n”只能被text标签识别view标签无法识别

  <navigation-bar title="Weixin" back="{
  {false}}" color="black" background="#ccc"></navigation-bar>
<view class="water_top" style="pointer-events: none;">
    <text class="water-text" wx:for="{
  {50}}">{
  {"小程序水印\n12345678910"}}</text>
</view>

css文件:

.water_top{
  position: fixed;
  top:0;
  bottom: 0;
  left: 0;
  right: 0;
  /* background: #999; */
  transform:rotate(-10deg);
  /* opacity: 0.9; */
  z-index: -999;
}
.water-text{
  float: left;
  width:375rpx;
  color: rgba(169,169,169,.2);
  text-align: center;
  font-size: 40rpx;
  margin: 100rpx 0;
}
.watermark {
  position: fixed;
  top: 0;
  width: 100%;
  height: 100%;
  background: #eeeeee11;
  pointer-events: none;
  background-repeat: repeat;
  background-size: 50% auto;
}
.canvas {
  width: 200px;
  height: 200px;
  position: fixed;
  left: -200%;
}

二、使用微信小程序的api阻止用户截屏

使用wx.setVisualEffectOnCapture手机截屏或者录屏时,禁止调用,并提示无法截屏。

参数

属性 类型 默认值 必填 说明
visualEffect string none 截屏/录屏时的表现,仅支持 none / hidden,传入 hidden 则表示在截屏/录屏时隐藏屏幕
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数
complete function 接口调用结束的回调函数(调用成功、失败都会执行

注意:iOS 要求基础库版本为 3.3.0 以上,且系统版本为 iOS 16 以上

  onLoad() {
    wx.setVisualEffectOnCapture({
      visualEffect: 'hidden',
      success:(res) => {
        console.log(res)
      },
      fail:(err) => {
        console.log(err)
      },
      complete:(res) => {
        console.log(res)
      }
    })
    wx.onUserCaptureScreen(function (res) {
      console.log('用户截屏了')
    })
  },
})

微信开发者文档wx.setVisualEffectOnCapture

相关推荐

  1. adb 命令

    2024-01-17 12:28:06       27 阅读
  2. 【HarmonyOS】应用屏蔽

    2024-01-17 12:28:06       33 阅读
  3. 程序 - 登录(切后继续倒计时)

    2024-01-17 12:28:06       28 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-17 12:28:06       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-17 12:28:06       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-17 12:28:06       82 阅读
  4. Python语言-面向对象

    2024-01-17 12:28:06       91 阅读

热门阅读

  1. 开箱即用之MyBatisPlus XML 自定义分页

    2024-01-17 12:28:06       54 阅读
  2. 记一次Log记录大对象导致的CPU异常和磁盘打满

    2024-01-17 12:28:06       53 阅读
  3. PHP 字符串面试题

    2024-01-17 12:28:06       61 阅读
  4. 什么是池化层?

    2024-01-17 12:28:06       53 阅读
  5. 2024华数杯国际数学建模A题思路模型详解

    2024-01-17 12:28:06       43 阅读
  6. 设计模式——原型模式

    2024-01-17 12:28:06       49 阅读
  7. 正则表达式 (用于灵活匹配文本的表达式)

    2024-01-17 12:28:06       53 阅读
  8. 自定义shell工具函数之pull_image()

    2024-01-17 12:28:06       50 阅读
  9. Spring 整合Shiro鉴权授权

    2024-01-17 12:28:06       48 阅读
  10. 【Flask】使用 werkzeug 安全地处理密码

    2024-01-17 12:28:06       56 阅读