function video_js($key,$key_class){
if($key_class=='wb'){#微博
$d =http('https://m.weibo.cn/status/'.$key);
//echo $d;
if(strpos($d,'stream_url_hd": "')!=false){
return str_get_zj($d,'stream_url_hd": "','"');
}else if(strpos($d,'"stream_url": "')!=false){
return str_get_zj($d,'"stream_url": "','"');
}
echo "解析失败";
}elseif ($key_class=='dz') {
return $key;
}
echo '失败失败!';
return '';
}
/**
* 取文本中间
* 参数1 内容
* 参数2 文本左边
* 参数3 文本右边
* 返回值 取出中间文本
*/
function str_get_zj ($nr,$zb,$yb){
//功能 取文本中间内容() 参数 内容,文本左边,文本右边
$ls = stripos($nr,$zb);
if($ls === false){
return ;
}
$ls+=strlen($zb);
$lsy=stripos($nr,$yb,$ls);
if($lsy === false){
return ;
}
return substr ($nr,$ls,$lsy-$ls) ;
}
/**
* HTTP访问
* 参数url 网址
* 参数get_post 访问模式 0=GET 1=POST
* 参数postdata POST数据
* 参数head 访问协议头 一行一个
* 参数cookie cookies
* 参数location 重定向 0=不重定向 1=重定向
* 参数proxy 代理ip:端口
* 参数timeout 访问超时 单位是秒 默认是8秒
* 参数headr 返回协议头
* 返回值 取出中间文本
*/
function http($url,$get_post=0,$postdata='',$head='',$cookie='',$location=1,$proxy='',$timeout=8,&$headr='',$cookier=''){
$ch = curl_init();//初始化
curl_setopt($ch,CURLOPT_URL,$url);//设置URL
curl_setopt($ch, CURLOPT_COOKIE, $cookie);//设置cookies
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,$location);//是否重定向
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//允许https访问。
curl_setopt($ch,CURLOPT_POST,$get_post);//设置get或者post
if($get_post == 1){
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);//提交POST内容
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//在执行curl_exec返回结果
curl_setopt($ch, CURLOPT_HEADER,1);//设置输出响应头
curl_setopt($ch,CURLOPT_HTTPHEADER,explode("\r\n",$head));//设置协议附加头head
curl_setopt($ch, CURLOPT_PROXY, $proxy); //设置代理ip
curl_setopt ($ch, CURLOPT_TIMEOUT, $timeout);//设置超时 单位是秒
$x=curl_exec($ch);//执行
$header = curl_getinfo($ch);//获取信息
$headr= substr ($x,0,$header['header_size']);
//var_dump($header);
//$cookier= implode('',preg_match('/Set-Cookie:(.*;)/iU',$headr,$str));
curl_close($ch);
return substr ($x,$header['header_size'],strlen($x)-$header['header_size']);;
}
-----------------------------------------------------------
#例如https://weibo.com/tv/v/FxTtuuP2j
#调用方法 echo video_js("FxTtuuP2j",'wb');
原理是访问https://m.weibo.cn/status/FxTtuuP2j 获得视频地址 然后302跳转,,到视频地址就完成视频解析
微博因为有做临时保密接口 视频地址都是临时的