ini_set('user_agent','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 Edg/135.0.0.0');
$option=array('ssl'=>array('verify_peer' => false,'verify_peer_name' => false));
$html = file_get_contents($content,false,stream_context_create($option));
获取微信公众号文章页面内容时,页面提示:当前环境异常,完成验证后即可继续访问。调试发现是user_agent没有配置导致。
PHP中,file_get_contents发送user_agent的代码。网上有案例写入到option中,但是测试无效。