微信小程序直播獲取分享卡片鏈接參數
接口說明:由于基礎庫數據安全策略,通過 App onShow(需在主包引入直播組件)或者 Page onShow(需在分包引入直播組件)生命周期里的query無法獲取直播間分享卡片鏈接參數。在直播組件版本 1.1.4 及以上版本通過該接口獲取以下參數,開發者可以根據這些參數建立用戶、直播間、商品之間的映射關系。
分享卡片進入直播間:房間號 room_id + 進入者 openid + 分享者 share_openid + 開發者自定義參數 custom_params
調用方法:若要調用【獲取分享卡片鏈接參數】接口 getShareParams,需在小程序頁面頂部引用【直播組件】 live-player-plugin。
示例代碼如下:
let livePlayer = requirePlugin('live-player-plugin')
App({
onShow(options) {
// 分享卡片入口場景才調用getShareParams接口獲取以下參數
if (options.scene == 1007 || options.scene == 1008 || options.scene == 1044 || pluginScene === 1154 || pluginScene === 1155) {
livePlayer.getShareParams()
.then(res => {
// 房間號
console.log('get room id', res.room_id)
// 用戶openid
console.log('get openid', res.openid)
// 分享者openid,分享卡片進入場景才有
console.log('get share openid', res.share_openid)
// 開發者在跳轉進入直播間頁面時,頁面路徑上攜帶的自定義參數,這里傳回給開發者
console.log('get custom params', res.custom_params)
}).catch(err => {
console.log('get share params', err)
})
}
}
})