小程序播放优酷和腾讯视频

小程序播放优酷和腾讯视频

解析出播放地址,直接通过video进行播放

解析优酷视频方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// const url = 'https://v.youku.com/v_show/id_XNDI2OTM5MTExNg==.html'

export function getYoukuVideoSrc(url) {
let key = url.split('.html')[0]
if (!key) return Promise.reject('解析失败')
key = key[key.length - 1].split('_')[1]

return new Promise(resolve => {
const apiUrl = `https://ups.youku.com/ups/get.json?vid=${key}&ccode=0405&client_ip=192.168.1.1&utid=7wNNESOeQS4CAXzP1pKImliK&client_ts=1499075140&r=bBLxVq7VfU4hVT%2BCjmrY20kogZckZZr%2FWdDwtoNBVjuXY5QTXYJPD7OxqmUWFe1c`
wx.request({
url: apiUrl,
success(res) {
const { data } = res.data
resolve({
src: data.stream[0].segs[0].cdn_url,
poster: data.video.logo
})
}
})
})
}

解析腾讯视频方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// const url = 'https://v.qq.com/x/page/t09052dfpvm.html' //腾讯视频地址 请替换

export function getQQVideoSrc(url) {
if (!url.includes('v.qq.com')) return ''
const key = url.match(/http(s?):\/\/(.+?)\/(\w+?).html/)
if (!(key && key[3])) return ''

return new Promise(resolve => {
wx.request({
url: `https://h5vv.video.qq.com/getinfo?otype=json&platform=11001&sphttps=1&vid=${
key[3]
}`,
success({ data }) {
const ret = JSON.parse(data.slice(13, data.length - 1))
resolve({
src: `${ret.vl.vi[0].ul.ui[0].url}${ret.vl.vi[0].fn}?vkey=${
ret.vl.vi[0].fvkey
}`,
poster: `https://puui.qpic.cn/qqvideo_ori/0/${key[3]}_496_280/0`
})
}
})
})
}