微信公众号同步腾讯视频搞笑排行榜
public function syncVideo(){
Vendor(\'Weixin.wxyhq_class\');
$weixin = new \weixin();
//笑脸 array(2) { ["media_id"]=> string(43) "bntHjEN8oAlFVjW3oT2XNRiAyyi9pt5Iwk-mTfTBpCw" ["url"]=> string(130) "http://mmbiz.qpic.cn/mmbiz_png/BIZBsErRy29aehCPtjQHZS0LECMlYlfpZjDjyldKG72BOhW3pOqUefwNbnCnZT0xdE701elOfznkF03QwJzoEw/0?wx_fmt=png" }
$index = 0;
Vendor(\'Html.simple_html_dom\');
$resource = M(\'resource\',\'tp_\');
$url = "https://v.qq.com/x/channel/fun";
try
{
$html_main = file_get_html($url);
if (!isset($html_main)){
$html_main->clear();
return "文件载入出错!";
}
// echo $html_main;
$express = "/page\/(.+)\.html/i";
$id = 0;
$media_id = "bntHjEN8oAlFVjW3oT2XNZGdlAbmEm09huwHBdsuOFs";// 热播排行榜 日榜
foreach($html_main->find(\'ul[class="figure_list _toplist_type1 _quickopen"] li[class="list_item"]\') as $iteminfo)
{
$url = trim($iteminfo->find(\'a\', 0)->href);
preg_match($express, $url, $qvid);
$vid = $qvid[1];
$imgurl = trim("http:".$iteminfo->find(\'img\', 0)->lz_src);
$title = trim($iteminfo->find(\'strong[class="figure_title figure_title_two_row"] a\', 0)->plaintext);
// $desc = trim($iteminfo->find(\'div[class="figure_desc"]\', 0)->plaintext);
$filename = time().".jpg";
file_put_contents(SAE_TMP_PATH."/".$filename, file_get_contents($imgurl));
$data = array("media" => "@".SAE_TMP_PATH.$filename);
$result2 = $weixin->upload_permanent_material_raw("thumb", $data); //logo.jpg须放于类同目录,注意路径
if (isset($result2["media_id"])){
$thumb_media_id = $result2["media_id"];
}else{
$thumb_media_id = "bntHjEN8oAlFVjW3oT2XNRiAyyi9pt5Iwk-mTfTBpCw";
}
$content = "<p><img data-type=\'gif\' data-src=\'https://mmbiz.qpic.cn/mmbiz_gif/BIZBsErRy2ibgbtkAF72c3AicWkRxDzXAjL0yk8DOnmzcxoticnibOeia05zHdEL6gjxXEGHV4b8aFpSW4W7gsWLC3g/0?wx_fmt=gif\' data-ratio=\'0.11875\' data-w=\'640\'/></p><p><span style=\'color: rgb(255, 255, 255);\'>1</span></p><p><iframe class=\'video_iframe\' data-vidtype=\'2\' allowfullscreen=\'\' frameborder=\'0\' data-ratio=\'1.7666666666666666\' data-w=\'848\' data-src=\'https://v.qq.com/iframe/preview.html?vid=".$vid."&width=500&height=375&auto=0\'></iframe><br/></p>";
$news = array( "media_id"=>$media_id,
"index"=>$id,
"articles"=> array("title"=>$title,
"thumb_media_id"=>$thumb_media_id,
"author"=>"",
"digest" =>"关注 东购 公众号还有更多好看的",
"show_cover_pic" =>"0",
"content" =>$content,
"content_source_url" =>"",
)
);
$result = $weixin->update_permanent_news($news);
$id ++;
// var_dump($desc);
}
$id = 0;
$index = 0;
$media_id = "bntHjEN8oAlFVjW3oT2XNfp-vkOuccogcUvyzfGjrO8";// 最强笑点
foreach($html_main->find(\'div[class="mod_figure_1f2r"] li[class="list_item"]\') as $iteminfo)
{
$id ++;
if ($id % 5 == 0){
continue;
}
$url = trim($iteminfo->find(\'a\', 0)->href);
preg_match($express, $url, $qvid);
$vid = $qvid[1];
$imgurl = trim("http:".$iteminfo->find(\'img\', 0)->src);
$title = trim($iteminfo->find(\'div[class="figure_detail figure_detail_two_row"] a\', 0)->plaintext);
$desc = trim($iteminfo->find(\'div[class="figure_desc"]\', 0)->plaintext);
$filename = time().".jpg";
file_put_contents(SAE_TMP_PATH."/".$filename, file_get_contents($imgurl));
$data = array("media" => "@".SAE_TMP_PATH.$filename);
$result2 = $weixin->upload_permanent_material_raw("thumb", $data); //logo.jpg须放于类同目录,注意路径
if (isset($result2["media_id"])){
$thumb_media_id = $result2["media_id"];
}else{
$thumb_media_id = "bntHjEN8oAlFVjW3oT2XNRiAyyi9pt5Iwk-mTfTBpCw";
}
$content = "<p><img data-type=\'gif\' data-src=\'https://mmbiz.qpic.cn/mmbiz_gif/BIZBsErRy2ibgbtkAF72c3AicWkRxDzXAjL0yk8DOnmzcxoticnibOeia05zHdEL6gjxXEGHV4b8aFpSW4W7gsWLC3g/0?wx_fmt=gif\' data-ratio=\'0.11875\' data-w=\'640\'/></p><p><span style=\'color: rgb(255, 255, 255);\'>1</span></p><p><iframe class=\'video_iframe\' data-vidtype=\'2\' allowfullscreen=\'\' frameborder=\'0\' data-ratio=\'1.7666666666666666\' data-w=\'848\' data-src=\'https://v.qq.com/iframe/preview.html?vid=".$vid."&width=500&height=375&auto=0\'></iframe><br/></p>";
$news = array( "media_id"=>$media_id,
"index"=>$index,
"articles"=> array("title"=>$title,
"thumb_media_id"=>$thumb_media_id,
"author"=>"",
"digest" =>(empty($desc)?"关注 东购 公众号还有更多好看的":$desc),
"show_cover_pic" =>"0",
"content" =>$content,
"content_source_url" =>"",
)
);
$result = $weixin->update_permanent_news($news);
$index ++;
}
// var_dump("================================");
$html_main->clear();
}catch (Exception $e){
echo $e;
exit;
}
$this->success(\'数据更新成功!\',\'index\');
}