复制以下代码:

getVideoInfo: function (vid) {

var that = this;

var urlString = 'https://vv.video.qq.com/getinfo?otype=json&appver=3.2.19.333&platform=11&defnpayver=1&vid=' + vid;

var host = '' , pageArr = [];

wx.showLoading({

title : '正在缓冲...'

});

wx.request({

url: urlString,

success: function (res) {

var dataJson = res.data.replace(/QZOutputJson=/, '') + "qwe";

var dataJson1 = dataJson.replace(/;qwe/, '');

var data = JSON.parse(dataJson1);

var fn_pre = data.vl.vi[0].lnk

host = data['vl']['vi'][0]['ul']['ui'][0]['url']

var streams = data['fl']['fi']

var seg_cnt = data['vl']['vi'][0]['cl']['fc']

if (parseInt(seg_cnt) == 0) {

seg_cnt = 1

}

var best_quality = streams[streams.length - 1]['name']

var part_format_id = streams[streams.length - 1]['id']

for (var i = 1; i < (seg_cnt + 1); i++) {

var filename = fn_pre + '.p' + (part_format_id % 10000) + '.' + i + '.mp4';

console.log(filename);

pageArr.push(i);

that.requestVideoUrls(part_format_id, vid, filename, 'index' + i , host);

}

}

})

},

requestVideoUrls: function (part_format_id, vid, fileName, index , host) {

var keyApi = "https://vv.video.qq.com/getkey?otype=json&platform=11&format=" + part_format_id + "&vid=" + vid + "&filename=" + fileName + "&appver=3.2.19.333"

var that = this , part_urls = [];

wx.request({

url: keyApi,

success: function (res) {

var dataJson = res.data.replace(/QZOutputJson=/, '') + "qwe";

var dataJson1 = dataJson.replace(/;qwe/, '');

var data = JSON.parse(dataJson1);

if (data.key != undefined) {

var vkey = data['key']

var url = host + fileName + '?vkey=' + vkey;

part_urls[index] = String(url)

wx.hideLoading();

that.setData({

videoUrl: part_urls.index1

});

}

}

})

},

JS调用代码:

this.getVideoInfo('t0702s8qwu2');

模板代码:

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐