终于找到解决方案了,这是一个值得庆祝的事情....
原来是因为微信在源码中加入了防采集代码<!--headTrap<body></body><head></head><html></html>-->,把文章源码中的这一段去掉就可以了!
具体代码如下:
public function getCon(){
header('Content-type: text/html; charset=utf-8');
import('Vendor.QL.QueryList');
$w_url=$_POST['wurl']; //接收到的文章地址
// 测试文章地址
// $w_url='http://mp./s?__biz=MzA5NzQ5OTMxMA==&mid=2650621512&idx=1&sn=2059946e820805c0d62a450aa3af62be&chksm=88960789bfe18e9f47417eb45cd8efe458af9e93fea3e8e4e242ea2376fd3e4c69f5218293cb&scene=0#wechat_redirect';
// echo "<script>alert('".$w_url."');</script>";
$html = file_get_contents($w_url); //获取文章源码并保存到参数中
// echo "<script>alert('".$html."');</script>";
$html = str_replace("<!--headTrap<body></body><head></head><html></html>-->", "", $html); //去除微信中的抓取干扰代码
// die($w_url);
// var_dump($html);
$data = \QueryList::Query($html,array(
//采集规则库
//'规则名' => array('jQuery选择器','要采集的属性'),
'titleTag' => array('title','text'),
// 'title' => array('#activity-name','text'),
'content' => array('body','text'),
// 'image' => array('img','src'),
//微信规则
'contentWx' => array('#js_content','text'),
// 'imageWx' => array('img','data-src'),
// 'conText' => array('.rich_media_content>p','text'),
))->data;
foreach ($data as $k => $v) {
$data[$k]['imageWx'] = $this->cut_str($v['imageWx'],'?',0);
}
//打印结果
// print_r($data);
$this->assign('conD',$data);
$this->display();
}
String token = AccessTokenTool.getAccessToken();String URL = "https://api./cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN";// 原始jsonString jsonResult = HttpUtil.sendGet(URL.replace("OPENID", openid).replace("ACCESS_TOKEN", token));System.out.println(jsonResult);// 编码后的jsonString json = new String(jsonResult.getBytes("ISO-8859-1"), "UTF-8");System.out.println(json);
静下心来好好敲代码,没有任何一项技能是不需要经过长年累月的琢磨就可以轻易成就的
原文地址:/lens85/p/6007111.html