微信图片反防盗链的方法(此图片来自微信公众平台,未经允许不可饮用)
(未找到出处,如有侵犯,请及时告知,谢谢)
因为在<img>标签中引用微信的图片 <?php $img = "http://mmbiz.qpic.cn/mmbiz /ibbmVK4uC7iacR4KGWnyJHvQxl276DK6eGibiafBFTLObjBtKU9hGZoiaaiaD49r4u9otkQzCGAPAbWlPVzrpyCRaCVA/0"; ?> <img src="<?php echo $img;?>"/> 会显示如图所示: ![输入图片说明](https://static.oschina.net/uploads/img/201603/17171821_24sw.png "weixin") 这是因为微信现在也开始防外链导致,在经过一天的搜索努力以后发现了如下方法可以解决,利用js解决。 解决方法如下: ``` <script type="text/javascript"> function showImg(url) { var frameid = ‘frameimg‘ + Math.random(); console.debug(frameid); console.debug(url); window.img = ‘<img id="img" style="width:50%" src=\‘‘ + url + ‘?‘ + Math.random() + ‘\‘ /><script>window.onload = function() { parent.document.getElementById(\‘‘ + frameid + ‘\‘).height = document.getElementById(\‘img\‘).height+\‘px\‘; }<‘ + ‘/script>‘; document.write(‘<iframe id="‘ + frameid + ‘" src="javascript:parent.img;" frameBorder="0" scrolling="no" width="50%"></iframe>‘); } </script> <h1>原图:</h1> <br> <img src="http://mmbiz.qpic.cn/mmbiz/dYNplyiblCFna8JoYZw71MH8Z8ib8KBALnJ7DibpDVSLPW4oy0nVhPfEG7PxCVwia6YP1OFibowWWkm2T0pn63icArPQ/0?tp=webp&wxfrom=5&wx_lazy=2" /><br> <h1>js破解之后:</h1> <br> <div id="hotlinking"> <script type="text/javascript">showImg(‘http://mmbiz.qpic.cn/mmbiz/ibbmVK4uC7iacR4KGWnyJHvQxl276DK6eGlZQ10E7BeY7Fw0ZlnPLXOSF8W4qIiaCsNspcEiaicD0McR79qmicfPGntg/0‘);</script> </div>
还有网友说:
把它的data-src 改成src就好了
1
2
3
4
5
6
7
8
9
10
11
|
< img src="http://mmbiz.qpic.cn/mmbiz/CoJreiaicGKekEsuheJJ7Xh53AFe1BJKibyaQzsFiaxfHHdYibsHzfnicbcsj6yBmtYoJXxia9tFufsPxyn48UxiaccaAA/640? wx_fmt = jpeg & wxfrom = 5 & wx_lazy = 1 " data-s = "300,640" data-ratio = "0.6672661870503597" data-w = "" data-type = "jpeg" width = "auto" data-src = "" style="box-
sizing: border-box !important; word-wrap: break-word !important; width: auto !important; visibility: visible !important;" /></ p >< p style="max-width: 100%;
min-height: 1em; white-space: pre-wrap; color: rgb(62, 62, 62); rgb(255, 255, 255); box-sizing: border-box !important; word-wrap: break- word !important;"> |
还有一个data-src去掉值就好了。