php 小程序播放腾讯视频 video标签无法播放腾讯视频问题

解决小程序播放腾讯视频问题。同适用于微擎....

需要引用一些腾讯视频网站上的视频去播放,很多地方都是教人用F12抓一个mp4地址,这根本不行,因为那个地址是动态的,

翻了微信小程序的官方社区这方面的问题只有人提问,没有人有正确的回答(包括官方人员也都不懂),那就只能自己研究了。还好不是很难,折腾了一晚上一上午搞定了。

 

1、首先我们从腾讯视频网站上找到一个视频网页的连接,格式是这样的

https://v.qq.com/x/page/b0136et5ztz.html

上面我标红色的是视频的vid

2、我们把vid放到接口地址上变成 (get请求就OK)

http://vv.video.qq.com/getinfo?vids=b0136et5ztz&platform=101001&charge=0&otype=json

3、直接访问返回的是

QZOutputJson={"dltype":1,"exem":0,"fl":{"cnt":2,"fi":[{"id":100701,"name":"msd","lmt":0,"sb":1,"cname":"流畅;(180P)","br":29,"drm":0,"video":1,"fs":35776912,"sl":1},{"id":2,"name":"mp4","lmt":0,"sb":1,"cname":"高清;(480P)","br":34,"drm":0,"video":1,"fs":74129447,"sl":0}]},"hs":0,"ip":"119.137.195.73","ls":0,"preview":1186,"s":"o","sfl":{"cnt":0},"tm":1503504934,"vl":{"cnt":1,"vi":[{"br":29,"ch":0,"cl":{"fc":0,"keyid":"b0136et5ztz.100701"},"ct":21600,"drm":0,"dsb":0,"fmd5":"87d7d2ef15f55a456bcdb359dd580795","fn":"b0136et5ztz.m701.mp4","fs":35776912,"fst":5,"fvkey":"EBB1F5C7B5100A3DA80802119E3FF9D0AAE3DA6670594D507B02AD489CF21D2868B0803B76F7434CE51B5C70D75554D68ED24A49EE3DE4791E0BA58444A77756FA7CBC6FB1B3E579F44F87AFB1CB79E8522A48576A4949037A5EDC1C842A9EF7536E090EBD018BB2","head":0,"hevc":0,"iflag":0,"level":0,"lnk":"b0136et5ztz","logo":1,"mst":8,"pl":null,"share":1,"sp":0,"st":2,"tail":0,"td":"1186.92","ti":"解密潮汕多神信仰","type":3,"ul":{"ui":[{"url":"http://113.105.167.156/vhot2.qqvideo.tc.qq.com/AuRJoSSIabzpOb1RsXSviFl-nYwRDSZoFU5OpwBhfrAk/","vt":200,"dtc":0,"dt":2},{"url":"http://113.105.167.155/vhot2.qqvideo.tc.qq.com/AuRJoSSIabzpOb1RsXSviFl-nYwRDSZoFU5OpwBhfrAk/","vt":200,"dtc":0,"dt":2},{"url":"http://113.105.167.154/vhot2.qqvideo.tc.qq.com/AuRJoSSIabzpOb1RsXSviFl-nYwRDSZoFU5OpwBhfrAk/","vt":200,"dtc":0,"dt":2},{"url":"http://video.dispatch.tc.qq.com/62098754/","vt":0,"dtc":0,"dt":2}]},"vh":272,"vid":"b0136et5ztz","videotype":27,"vr":0,"vst":2,"vw":480,"wh":1.7647059,"wl":{"wi":[]}}]}}; 

(假如我标红的url都不一样的话,默认取第一个,随便哪个都一样的,最起码我现在还没问题)

//这个视频链接的话需要的不是通用代码  而是页面链接就好了。
        $goods['video'] = 'https://v.qq.com/x/page/b0809n3hsw2.html';

     if(strpos($goods['video'],'v.qq.com') !== false){
          $video = substr($goods['video'],strripos($goods['video'],"/")+1);
          $goods['video'] = substr($video,0,strrpos($video,"."));
          $url = "http://vv.video.qq.com/getinfo?vids=".$goods['video']."&platform=101001&charge=0&otype=json";
          $data = $this->GetHttp($url);
          $data = substr($data,13);
          $data =  json_decode(substr($data,0,strlen($data)-1),ture); 

          $url = $this->recur('url',$data)[0];
          $fn = $this->recur('fn',$data)[0];
          $fvkey = $this->recur('fvkey',$data)[0];
          $goods['video'] = $url.'/'.$fn.'?vkey='.$fvkey;
          //dump($goods['video']);die;

          /*** 修改完毕*/
        }

4、我们把前面的QZOutputJson=跟最后的 ; 过滤掉,得到一个json字符串了。解析它变成json对象,然后把标红的三个部分组合一下,顺序是 

url + fn + '?vkey=' + fvkey 

例如上面这串,组合下来就是 

http://113.105.167.156/vhot2.qqvideo.tc.qq.com/AuRJoSSIabzpOb1RsXSviFl-nYwRDSZoFU5OpwBhfrAk/b0136et5ztz.m701.mp4?ckey=EBB1F5C7B5100A3DA80802119E3FF9D0AAE3DA6670594D507B02AD489CF21D2868B0803B76F7434CE51B5C70D75554D68ED24A49EE3DE4791E0BA58444A77756FA7CBC6FB1B3E579F44F87AFB1CB79E8522A48576A4949037A5EDC1C842A9EF7536E090EBD018BB2

这个地址就可以直接放在小程序的video组件里面播放了。

附:

注意:由于腾讯视频的地址vkey是定时变化的,所以肯定是不能写死在程序里面的。必须走后端照着上面写的方式抓取接口,过滤掉无用字符串,解析json,组合地址,通过接口返回给小程序video组件的src即可正常播放。

当然如果你的后端解析json比较麻烦的(例如古老的asp ^_^),可以把第2步最后的json去掉或者改成xml,直接解析xml也一样。

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 1024 设计师:白松林 返回首页