ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
### 记录下使用curl获取微信公众号文章 ``` /** * 测试获取公众号文章 * 登录个人订阅号 */ public function test() { $cookie = ''; $key = '';// 农产品 家电等关键词 $res = $this->query($key, $cookie); // $res = $this->getList($fakeid, $cookie); // 获取公众号列表 fakeid 公众号标识 // $res = $this->getInfo($url); // 微信文章链接 dump($res);die; } /** * @param $key * @param $cookie * @return mixed * 根据关键词获取公众号 */ public function query($key, $cookie) { $url = 'https://mp.weixin.qq.com/cgi-bin/searchbiz?action=search_biz&begin=0&count=5&query=' . $key . '&token=743327251&lang=zh_CN&f=json&ajax=1'; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // 对认证证书来源的检查 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); // 从证书中检查SSL加密算法是否存在 curl_setopt($ch, CURLOPT_COOKIE, $cookie); // 从证书中检查SSL加密算法是否存在 $userAgent = 'user-agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'; curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $output = curl_exec($ch); curl_close($ch); return json_decode($output, true); } /** * @param $fakeid * @param $cookie * @return mixed * 获取微信公众号文章列表 */ public function getList($fakeid, $cookie) { $url = "https://mp.weixin.qq.com/cgi-bin/appmsg?action=list_ex&begin=0&count=5&fakeid=$fakeid&type=9&query=&token=743327251&lang=zh_CN&f=json&ajax=1"; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // 对认证证书来源的检查 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); // 从证书中检查SSL加密算法是否存在 curl_setopt($ch, CURLOPT_COOKIE, $cookie); // 从证书中检查SSL加密算法是否存在 $userAgent = 'user-agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'; curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $output2 = curl_exec($ch); curl_close($ch); return json_decode($output2, true); } /** * @param $url * @return mixed * 获取微信文章 */ public function getInfo($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $re = curl_exec($ch); curl_close($ch); return $re; } ```