这段 PHP 代码怎么使用?

2017-08-29 20:20:52 +08:00
 q137564495
我需要的是获取这个页面 http://fanxing.kugou.com/mvplay/807720485470212096
的 MP4 视频地址;别人给出了下面的 PHP 代码,我保存在 PHP 空间 打开
没反应,怎么回事?
代码如下:
function getVideUrl($requetUrl) {
preg_match('@http://fanxing.kugou.com/mvplay/(\d+)#?(\d+)*@', $requetUrl, $match);
// var_dump($match);exit;
if (empty($match)) {
return -1;
}
$videoId = isset($match[2]) ? $match[2] : $match[1];
$t = substr(microtime(1)*1000, 0, 13);
$content = file_get_contents('http://fanxing.kugou.com/Services.php?act=Video.OfflineVideoService&mtd=getVideoAllInfoByVideoId&args=['.$videoId.',0,0]&_='.$t.'&jsonpcallback=jsonp2');
$content = str_replace(['jsonp2(', ')'], '', $content);
$content = json_decode($content, 1);
if (empty($content['data']['videoInfo']['hashValue'])) {
return -2;
}
$hashValue = $content['data']['videoInfo']['hashValue'];
$g = "callbackcallbackformatjsonphash" .$hashValue. "pid6kugou_video";
$url = "http://tracker.v.kugou.com/video/query?pid=6&hash=" . $hashValue . "&sign=" . md5($g) . "&format=jsonp&callback=callback";
$content = file_get_contents($url);
$content = str_replace(['callback(', ')'], '', $content);
$content = json_decode($content, 1);
if (empty($content['data']['url'])) {
return -3;
}
return $content['data']['url'];
}

var_dump(getVideUrl('http://fanxing.kugou.com/mvplay/807720485470212096'));
2126 次点击
所在节点    PHP
2 条回复
fatears
2017-08-30 06:59:21 +08:00
有可能 php 版本低了
q137564495
2017-08-30 18:03:55 +08:00
@fatears 在你的 PHP 环境能用吗?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/386707

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX