V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
q137564495
V2EX  ›  PHP

这段 PHP 代码怎么使用?

  •  
  •   q137564495 · 2017-08-29 20:20:52 +08:00 · 2110 次点击
    这是一个创建于 2442 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我需要的是获取这个页面 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'));
    2 条回复    2017-08-30 18:03:55 +08:00
    fatears
        1
    fatears  
       2017-08-30 06:59:21 +08:00 via iPad
    有可能 php 版本低了
    q137564495
        2
    q137564495  
    OP
       2017-08-30 18:03:55 +08:00
    @fatears 在你的 PHP 环境能用吗?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3545 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 11:37 · PVG 19:37 · LAX 04:37 · JFK 07:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.