V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
q137564495
V2EX  ›  PHP

这段 PHP 代码怎么使用?

  •  
  •   q137564495 · Aug 29, 2017 · 2822 views
    This topic created in 3167 days ago, the information mentioned may be changed or developed.
    我需要的是获取这个页面 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 replies    2017-08-30 18:03:55 +08:00
    fatears
        1
    fatears  
       Aug 30, 2017 via iPad
    有可能 php 版本低了
    q137564495
        2
    q137564495  
    OP
       Aug 30, 2017
    @fatears 在你的 PHP 环境能用吗?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2587 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 12:50 · PVG 20:50 · LAX 05:50 · JFK 08:50
    ♥ Do have faith in what you're doing.