微信对外提供了api接口,让我们可以通过授权的方式获取到自己公众号里面的文章,或者你也可以通过爬虫去抓取微信的文章,但是微信的图片默认是不允许外部调用的
这里我找到了两种方案
第一种
在js中提前把图片加载到本地,然后从本地缓存中读取图片
var showimg = function (url) {
var frameid = 'frameimg' + math.random();
window.img = '<img id="img" src='' + url + '?' + math.random() + '' /><script>window.onload = function() { parent.document.getelementbyid('' + frameid + '').height = document.getelementbyid('img').height+'px'; }<' + '/script>';
return '<iframe id="' + frameid + '" src="javascript:parent.img;" frameborder="0" scrolling="no" width="100%"></iframe>';
}
第二种
用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;
两种方法类似,我目前用的js的方式,测试过可以用
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!