微信小程序引用腾讯视频

仅限腾讯视频
$doctor['video'] = https://v.qq.com/x/page/v0741dpb1a0.html;必须是腾讯视频分享的第一种
$arr = explode('/',$doctor['video']);
$vid = str_replace(".html","",$arr[count($arr)-1]);

传入小程序跳转到视频页面之前的页面,用小程序路径传值

视频页JS片段

console.log(options.vid)
var that = this;
var vid = options.vid
wx.request({
url: app.u.url + 'wechatapi/doctor/tenvideo',
data:{
vid:vid
},
method: 'get',
head: {
'content-type': 'application / x - www - form - urlencoded',
'Accept': 'application/json'
},
success: function (res) {
console.log(res.data)
that.setData({ video:res.data.video})
}
})

public function tenvideo(){
$request = Request::instance();
$videoid = $request->get('vid');
if (!empty($videoid)) {
$tencent_video_info= curl_get("http://vv.video.qq.com/getinfo?vids=".$videoid."&platform=101001&charge=0&otype=json");
$tencent_video_json = substr(explode('QZOutputJson=',$tencent_video_info)[1],0,-1); // 我们把前面的QZOutputJson=跟最后的 ; 过滤掉,得到一个json字符串
$tencent_video_array = json_decode($tencent_video_json,true); // 得到过滤后json 数组
$fvkey = $tencent_video_array['vl']['vi'][0]['fvkey']; // 视频的fvkey会变动
$fn = $tencent_video_array['vl']['vi'][0]['fn'];
$url = $tencent_video_array['vl']['vi'][0]['ul']['ui'][0]['url'];
$video_url = $url.$fn.'?vkey='.$fvkey;
}else{
$video_url = '';
}
$data['video'] = $video_url;
echo json_encode($data);

}

 


//公共方法
function curl_get($url)
{

$info = curl_init();
curl_setopt($info,CURLOPT_RETURNTRANSFER,true);
curl_setopt($info,CURLOPT_HEADER,0);
curl_setopt($info,CURLOPT_NOBODY,0);
curl_setopt($info,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($info,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($info,CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($info,CURLOPT_URL,$url);
$output = curl_exec($info);
curl_close($info);
return $output;
}

posted @ 2019-02-20 14:10  DeStoryer、Hover  阅读(5117)  评论(0编辑  收藏  举报