php聊天记录保存到本地,php保存微信文章到本地

php保存微信文章到本地,同时自动下载微信里面的图片到本地

function get_wx_content($url) {

$ch = curl_init();

$headers = array();

$headers[] = 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7,ja;q=0.6';

$headers[] = 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 ;Safari/537.36';

$headers[] = 'Accept: application/json, text/javascript, */*; q=0.01';

$headers[] = 'Referer: https://mp.weixin.qq.com/cgi-bin/appmsg?t=media/;appmsg_edit_v2&action=edit&isNew=1&type=10&token=1112731269&lang=zh_CN';

$headers[] = 'X-Requested-With: XMLHttpRequest';

$headers[] = 'Connection: keep-alive';

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

curl_setopt($ch, CURLOPT_ENCODING, '');

curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);

curl_setopt($ch, CURLOPT_URL, $url);

$content = curl_exec($ch);

return $content;

}

function image_wx_handle($match_url,$prefix=null) {

var_dump($match_url);

$imgname = "img/".$prefix.md5($match_url[0]).".".$match_url[1];

// if (file_exist($imgname)) {

// echo fileGet($imgname);exit;

// }

$img = get_wx_content($match_url[0]);

file_put_contents($imgname, $img);

return $imgname;

}

$article=[

'dd.html'=>'http://www.benshifu.org/txjt/wx/dd.php',

'ft.html'=>'http://www.benshifu.org/txjt/wx/ft.php',

'jj.html'=>'http://www.benshifu.org/txjt/wx/jj.php',

'lhd.html'=>'http://www.benshifu.org/txjt/wx/lhd.php',

'pxd.html'=>'http://www.benshifu.org/txjt/wx/pxd.php',

'wsd.html'=>'http://www.benshifu.org/txjt/wx/wsd.php',

'zsd.html'=>'http://www.benshifu.org/txjt/wx/zsd.php',

'zzdf.html'=>'http://www.benshifu.org/txjt/wx/zzdf.php',

'ag.html'=>'http://www.benshifu.org/txjt/wx/ag.php',

'qsgy.html'=>'http://www.benshifu.org/txjt/wx/qsgy.php',

'wfl.html'=>'http://www.benshifu.org/txjt/wx/wfl.php',

];

foreach ($article as $filename => $url) {

//$url = $article[$x];

echo $filename," : url : ",$url;

$content = get_wx_content($url);

$content = str_replace("data-src", "src", $content);

//208——232 删除25行; 455——463,删除8行

$content = preg_replace_callback('@http://mmbiz.qpic.cn[^\s]+(jpeg|png)@i', 'image_wx_handle', $content,-1);

$content = preg_replace_callback('@https://mmbiz.qpic.cn[^\s]+(jpeg|png)@i', 'image_wx_handle', $content,-1);

file_put_contents($filename, $content);

//echo gzinflate($content);

//echo $content;

echo "\n";

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值