public function getcontent()
{
//需要插入的圖片
? ? ? ? $src= "xxx.png";
//需要插入的包含圖片的html,這個(gè)是我在公眾號(hào)里找到的,在手機(jī)顯示正常,在電腦端100%寬度
? ? ? ? $img= "? <div class='rich_media_content '><section style='white-space: normal;margin-bottom: 15px;'><img class='rich_pages js_insertlocalimg' data-ratio='0.1557285873192436' data-s='300,640' src={$src} data-type='png' data-w='899' style='text-align: center;'></section></div>";
//前端傳過(guò)來(lái)的文章地址
? ? ? ? $url= 'https://mp.weixin.qq.com/s?__biz=MjM5Mjg0NTE0MA==&mid=2661063748&idx=1&sn=1b48c7a003968624bfb2f86c207a7afa&chksm=bdc8207f8abfa96969580bd4780a806ff757ee302d1f63b12f99ebb589767440800ecfec30d0&mpshare=1&scene=1&srcid=09057aHsJ67scUCp69ud6Rhj&sharer_sharetime=1599240250039&sharer_shareid=76489e20cbd53225b7c0817b598987da&key=4598b5ee8f6c4950abe956fc65719d5630fd1ff38dafb29fdb358adad752388a24f68d6864c75f2f90e0f4c1e861567228102c619827533ab5879e26a8e12d7eb903e5e7664bd04505876520273bb6a4050ae209a14ccbde0662be5cca95325ffad25b1ce792615eed7f31a350060c62a6419c723bad5d7d110330dff9f320f5&ascene=1&uin=MTM4MzI3NDM0NA%3D%3D&devicetype=Windows+10+x64&version=62090529&lang=zh_CN&exportkey=AeIDb29Z2RO5CXkd%2F3nuVQ4%3D&pass_ticket=%2BhWX2WRH5XF%2BO8bjUroz52v6otU7fIIa3EvAlnMiP21oPzt2tQEQQyaoehR9ob07&wx_header=0';
//獲取內(nèi)容
? ? ? ? $html= file_get_contents($url);
//替換圖片
? ? ? ? $content= str_replace("data-src","src", $html);
//頭部插入圖片
? ? ? ? $content= $img. $content;
//尾部插入圖片
? ? ? ? $content= $content. $img;
//添加防和諧代碼 這個(gè)一定要添加不然生成的html圖片會(huì)被和諧.可能有更好的方法我沒(méi)找到
? ? ? ? $content= str_replace("<!DOCTYPE html>",'<!DOCTYPE html> <meta name="referrer" content="never">', $content);
//文件名稱(chēng) 請(qǐng)自定義
? ? ? ? $id= '2';
//路徑 根據(jù)自己的修改
? ? ? ? $biz= '123';
$dir= "./" . $biz. "/";
$filename= $dir. $id. ".html";
if (!is_dir($dir)) {
mkdir($dir);
chmod($dir,0777);
}
$file= fopen($filename,"w");
fwrite($file, $content);
fclose($file);
echo $_SERVER['SERVER_NAME']. '/' . $biz. '/' . $id. '.html';
}
------- 下面是獲取公眾號(hào)名稱(chēng)和頭像方法
//獲取員公眾號(hào)名稱(chēng)
//? preg_match_all('/var nickname = \"(.*?)\";/si',$content,$m);
// $nickname = $m[1][0];//公眾號(hào)昵稱(chēng)
//獲取員公眾號(hào)頭像
//? preg_match_all('/var round_head_img = \"(.*?)\";/si',$content,$m);
//? $head_img = $m[1][0];//公眾號(hào)頭像
//? $content = $referrer.$html;