• 微信小程序预约视频号直播


    一、概述

    微信小程序提供了可以唤起预约视频号直播弹窗的接口 reserveChannelsLive,该接口接收一个参数 noticeId,通过 getChannelsLiveNoticeInfo 接口获取。因此,过程如下:

    查看视频号 id ---finderUserName --> 调用 getChannelsLiveNoticeInfo 接口 ---noticeId --> 调用 reserveChannelsLive 接口 -----> 预约

    ⭐️ 完整代码实现可以直接看「四、总结」

    二、通过「视频号 id 」获取直播预告信息

    1、文档

    https://developers.weixin.qq.com/miniprogram/dev/api/open-api/channels/wx.getChannelsLiveNoticeInfo.html

     2、调用接口

    根据文档获取 视频号 id(finderUserName),调用 getChannelsLiveNoticeInfo 接口,代码如下:

    复制代码
    wx.getChannelsLiveNoticeInfo({
          finderUserName: 'sphABCDEF123456', // 视频号 id(视频号助手获取)
          success: function (res) {
            console.log('获取成功:', res);
          },
          fail: function (res) {
            console.error('获取失败:', res);
          }
        });
    复制代码

    3、返回结果

    调用接口后,打印结果如下,包含了预约接口需要的 noticeId 以及直播相关的其他信息。

     

    三、通过「预告 id 」预约直播

    1、文档

    https://developers.weixin.qq.com/miniprogram/dev/api/open-api/channels/wx.reserveChannelsLive.html

    2、调用接口

    reserveChannelsLive 接口只有一个参数 noticeId,代码如下:

    复制代码
    wx.reserveChannelsLive({
              noticeId: noticeId,
              success: function(reserveRes) {
                console.log('预约成功:', reserveRes);
                const reserveState = reserveRes.state;
                if(reserveState === 6) wx.showToast({title: '预约成功'});
              },
            });
    复制代码

    3、返回结果

     返回结果中包含了 state,state 值对应状态如下:

    复制代码
    state=1  正在直播中,用户点击“取消"拒绝前往直播
    state=2  正在直播中,用户点击“允许“前往直播
    state=3  预告已取消
    state=4  直播已结束
    state=5  用户此前未预约,在弹窗中未预约直播直接收起弹窗
    state=6  用户此前未预约,在弹窗中预约了直播
    state=7  用户此前已预约,在弹窗中取消了预约
    state=8  用户此前已预约,直接收起弹窗
    state=9  弹窗唤起前用户直接取消
    state=10 直播预约已过期
    复制代码

    四、总结

    1、完整代码

    index.wxml

    class="invite-btn" bindtap="onBookLive">立即预约

    index.js

    复制代码
    onBookLive: function () {
        wx.getChannelsLiveNoticeInfo({
          finderUserName: 'sphABCDE1234567', // 视频号 id
          success: function (res) {
            console.log('获取成功:', res);
            const noticeId = res.noticeId;
            wx.reserveChannelsLive({
              noticeId: noticeId,
              success: function (reserveRes) {
                console.log('预约成功:', reserveRes);
                const reserveState = reserveRes.state;
                if (reserveState === 6) wx.showToast({ title: '预约成功' });
              },
            });
          },
          fail: function (res) {
            console.error('获取失败:', res);
          }
        });
      }
    复制代码

     2、其他

    我遇到的一个小问题:小程序在调起预约直播弹窗的时候会触发页面 onHide,如果页面有音频,会导致音频播放停止,注意需要在 onShow 的时候再次播放。

     

    END-----------------------------------

     
     
  • 相关阅读:
    Java创建多线程的四种方式
    J2EE.List集合
    4.5 使用Go Modules自定义模块
    mmdetection训练得到的权重/checkpoints文件分析
    性能测试 —— Jmeter 常用三种定时器
    Python网络编程:构建网络应用与通信
    动手学深度学习—网络中的网络NiN(代码详解)
    读标准03-IEEE1451.5标准协议尝鲜实现
    全网独家:编译CentOS6.10系统的openssl-1.1.1多版本并存的rpm安装包
    H3C无线控制器AP license共享配置
  • 原文地址:https://www.cnblogs.com/MaiJiangDou/p/18217600