public function getcontent()
{
//需要插入的图片
$src= "xxx.png";
//需要插入的包含图片的html,这个是我在公众号里找到的,在手机显示正常,在电脑端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>";
//前端传过来的文章地址
$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';
//获取内容
$html= file_get_contents($url);
//替换图片
$content= str_replace("data-src","src", $html);
//头部插入图片
$content= $img. $content;
//尾部插入图片
$content= $content. $img;
//添加防和谐代码 这个一定要添加不然生成的html图片会被和谐.可能有更好的方法我没找到
$content= str_replace("<!DOCTYPE html>",'<!DOCTYPE html> <meta name="referrer" content="never">', $content);
//文件名称 请自定义
$id= '2';
//路径 根据自己的修改
$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';
}
------- 下面是获取公众号名称和头像方法
//获取员公众号名称
// preg_match_all('/var nickname = \"(.*?)\";/si',$content,$m);
// $nickname = $m[1][0];//公众号昵称
//获取员公众号头像
// preg_match_all('/var round_head_img = \"(.*?)\";/si',$content,$m);
// $head_img = $m[1][0];//公众号头像
// $content = $referrer.$html;