秒拍微博视频接口-学习记录

34 篇文章 1 订阅
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跳转,,到视频地址就完成视频解析

微博因为有做临时保密接口  视频地址都是临时的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值