微信小程序分享海报第一次进来获取不到option.query.custom_params自定义参数?
发布于 6 年前 作者 taodai 6460 次浏览 来自 问答
  if (this.onLive() && [1007100810141044104510461047104810491073115411551177].includes(option.scene)) {
      // 分享卡片入口场景才调用getShareParams接口获取以下参数
      // scene场景值:1007:单人聊天会话中的小程序消息卡片,1008:群聊会话中的小程序消息卡片,1044:带 shareTicket 的小程序消息卡片
      console.log(option, 11111);
      livePlayer.getShareParams().then(res => {
          // console.log(option.query.custom_params,'前面');
          console.log(res, '我是livePlayer里面');
          let data = { open_id: res.share_openid };
      
          // 房间号
          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);
      
          this.requesUtil.gettjrid(data).then(res => {
            console.log(res.data,'请求服务器了');
            if (res.data.error_code === 0) {
              uni.setStorageSync('tjr_id', res.data)
            }
          })
        })
        .catch(err => {
          console.log('get share params', err);
        });
            // 这是打印自定义参数,第一次接收不了,第二次扫码能接收到
        console.log(decodeURIComponent(option.query.custom_params), 'onShow后面打印');
        if (option.query.custom_params) {
          uni.setStorageSync('tjr_id'JSON.parse(decodeURIComponent(option.query.custom_params)).pid);
        }
    }else{
      console.log('livePlayer 失败进不来');
    }
1 回复

不知道你用的是不是微信官方的直播插件,直播的分享参数有两种判断,一种是在进入页面onload用option.custom_params,一种是在onlauch判断options.path == 'plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin’时用options.query.custom_params,其对应两种不同的分享行为,具体哪些有点忘记了,我固定都是这么判断的,两种判断最好一起写

回到顶部