Blogger Information
Blog 30
fans 1
comment 0
visits 23198
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP如何解决微信文章图片防盗链
P粉896289085
Original
460 people have browsed it

这篇文章主要介绍了PHP如何解决微信文章图片防盗链,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

微信对外提供了API接口,让我们可以通过授权的方式获取到自己公众号里面的文章
或者你也可以通过爬虫去抓取微信的文章
但是微信的图片默认是不允许外部调用的
解决微信文章图片防盗链

  1. function actionWechatImg()
  2. {
  3. header('Content-type: image/jpg');
  4. $url = $_GET['url'];
  5. $refer = "http://www.qq.com/";
  6. $opt = [
  7. 'http'=>[
  8. 'header'=>"Referer: " . $refer
  9. ]
  10. ];
  11. $context = stream_context_create($opt);
  12. $file_contents = file_get_contents($url,false, $context);
  13. echo $file_contents;
  14. }

调用示例:
<img src="http://xxx.com.cn/wechat-img?url=http%3A%2F%2Fmmbiz.qpic.cn%2Fmmbiz%2F5ddyukqqNUt7ic07NicfAz9u0KrHEibKKMiab2cXA2sIqoj81hRsMZC65DCiaN67FsH2WaXkNOEE0YFLj5OHwIOegIg%2F0%3Fwx_fmt%3Djpeg">
其实就是模拟来源站点。

以上就是本文的全部内容,希望对大家的学习有所帮助。

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post