Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem of picture hotlink protection in Wechat articles

Shulou Source: shulou.com Published: 2022-06-03 13:12:10 11月14日 Update

How to solve the Wechat article picture hotlink protection problem, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

Wechat provides an API interface to allow us to obtain articles in our official account by authorization, or you can crawl Wechat articles through crawlers, but Wechat images are not allowed to be called from outside by default.

Here I found two options.

First kind

Load the picture locally in advance in JS, and then read the picture from the local cache

Var showImg = function (url) {var frameid = 'frameimg' + Math.random (); window.img ='

_ window.onload = function () {parent.document.getElementById (\'+ frameid +'\'). Height = document.getElementById (\ 'img\') .height +\'px\';}'; return';}

The second kind

Simulate browser requests with PHP

$url = $request- > input ('url'); $ch = curl_init (); $httpheader = array (' Host' = > 'mmbiz.qpic.cn',' Connection' = > 'keep-alive',' Pragma' = > 'no-cache',' Cache-Control' = > 'no-cache',' Accept' = > 'textml,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8',' User-Agent' = > 'Mozilla/5.0 (Windows NT 6.3) WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36', 'Accept-Encoding' = >' gzip, deflate, sdch', 'Accept-Language' = >' zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4'); $options = array (CURLOPT_HTTPHEADER = > $httpheader, CURLOPT_URL = > $url, CURLOPT_TIMEOUT = > 5, CURLOPT_FOLLOWLOCATION = > 1, CURLOPT_RETURNTRANSFER = > true); curl_setopt_array ($ch, $options) $result = curl_exec ($ch); curl_close ($ch); header ('Content-type: image/jpg'); echo $result;exit

The two methods are similar, I am currently using the JS method, which has been tested and can be used

After reading the above, do you know how to solve the problem of hotlink protection in Wechat articles? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Tags: Pictures articles questions methods anti-theft content can be passed ways more at a loss for this the public reasons skills interfaces solutions browsers crawlers articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Information NVidia Docker Microsoft