方法很简单,就是一段段截取就行,虽然很傻瓜,但是能实现就行。
<?php
//设置 header
header("Content-type:application/json");
//初始化 CURL
$ch = curl_init();
//目标服务器地址
curl_setopt($ch, CURLOPT_URL, '公众号文章链接');
// 对认证证书来源的检查
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
// 从证书中检查SSL加密算法是否存在
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
//获取的信息以文件流的形式返回,而不是直接输出
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//发起请求
$result = curl_exec($ch);
$str_1 = substr($result,strripos($result,"profile_nickname")+18);
$str_2 = substr($str_1,0,strrpos($str_1,"profile_avatar")-52); //公众号名称
$str_3 = substr($result,strripos($result,"微信号")+81);
$str_4 = substr($str_3,0,strrpos($str_3,"功能介绍")-163); //公众号微信号
$str_5 = substr($str_3,strripos($str_3,"功能介绍")+84);
$str_6 = substr($str_5,0,strrpos($str_5,"profile_arrow_wrp")-172); //公众号简介
$str_7 = substr($result,strripos($result,"twitter:title")+24);
$str_8 = substr($str_7,0,strrpos($str_7,"twitter:creator")-23); //公众号文章标题
$str_9 = substr($result,strripos($result,"twitter:image")+24);
$str_10 = substr($str_9,0,strrpos($str_9,"twitter:title")-23); //公众号文章封面图
$str_11 = substr($result,strripos($result,"twitter:description")+30);
$str_12 = substr($str_11,0,strrpos($str_11,"var testRdmUrl")-110);
$str_13 = substr($str_12,0,strrpos($str_12,">")-3); //公众号文章摘要
$str_14 = substr($result,0,strrpos($result,"og:title")-27);
$str_15 = substr($str_14,strripos($str_14,"author")+17); //公众号文章作者
$str_16 = substr($result,strripos($result,"div class="rich_media_content")+76);
$str_17 = substr($str_16,0,strrpos($str_16,"first_sceen__time")-75); //公众号文章正文
$gzhmsg = array(
"公众号名称" => $str_2,
"微信号" => $str_4,
"公众号简介" => $str_6,
"文章标题" => $str_8,
"文章封面图" => $str_10,
"文章摘要" => $str_13,
"文章作者" => $str_15,
"正文" => $str_17
);
//关闭请求
curl_close($ch);
// 输出JSON
echo json_encode($gzhmsg,JSON_UNESCAPED_UNICODE);
?>
Author:TANKING
Date:2020-10-24
Web:http://www.likeyun.cn/
WeChat:face6009
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。