Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program small program live access instructions


May 18, 2021 WeChat Mini Program Development Document


Table of contents


Small program live

Small program live broadcast is WeChat officially provided business tools. By calling this component, merchants can close the loop of live interaction and merchandise sales in a small program.

Follow the instructions below to access live streaming by introducing live components into your small program. If you encounter problems during use, you can post an exchange in the community live on the small program.

Instructions for how to use it

1. How to introduce the Live Components

Version restrictions: WeChat client version 7.0.7 and above (base library version 2.9.x and above support the same layer rendering) can watch live and use the functions of the live broadcast room, the low version just entered the live broadcast room will prompt the user to upgrade the WeChat client version (the low version can only watch the live broadcast, can not use the function between the live broadcast).

Supports the introduction of live-player-plugin code packs within the main package or subcontracts (Note: live components do not count as code package volume), app.json references to the project root, as follows:

(1) The main package is introduced

"plugins": {
    "live-player-plugin": {
        "version": "1.1.4", // 注意填写该直播组件最新版本号,微信开发者工具调试时可获取最新版本号(复制时请去掉注释)
        "provider": "wx2b03c6e691cd7370" // 必须填该直播组件appid,该示例值即为直播组件appid(复制时请去掉注释)
    }
}

(2) Subcontracted introduction

"subpackages": [
    {
        "plugins": {
            "live-player-plugin": {
                "version": "1.1.4", // 注意该直播组件最新版本号,微信开发者工具调试时可获取最新版本号(复制时请去掉注释)
                "provider": "wx2b03c6e691cd7370" // 必须填该直播组件appid,该示例值即为直播组件appid(复制时请去掉注释)
            }
        }
    }
]

2. How to use the Live Components

Once the component code pack configuration is introduced in step 1, you can jump directly from the link address to the live component page (that is, to the live room page) and the link address needs to be brought with you a live room id, which can be obtained through the Live Room List API below.

The sample code is as follows:

(1) Use the Navigator component to jump into the live room

index.js
let roomId = [直播房间id] // 填写具体的房间号,可通过下面【获取直播房间列表】 API 获取
let customParams = encodeURIComponent(JSON.stringify({ path: 'pages/index/index', pid: 1 })) // 开发者在直播间页面路径上携带自定义参数(如示例中的path和pid参数),后续可以在分享卡片链接和跳转至商详页时获取,详见【获取自定义参数】、【直播间到商详页面携带参数】章节(上限600个字符,超过部分会被截断)
this.setData({
    roomId,
    customParams
})
index.wxml
<navigator url="plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id={{roomId}}&custom_params={{customParams}}"></navigator>
// 其中wx2b03c6e691cd7370是直播组件appid不能修改

(2) Use the NavigateTo method to jump into the live room

index.js
let roomId = [直播房间id] // 填写具体的房间号,可通过下面【获取直播房间列表】 API 获取
let customParams = encodeURIComponent(JSON.stringify({ path: 'pages/index/index', pid: 1 })) // 开发者在直播间页面路径上携带自定义参数(如示例中的path和pid参数),后续可以在分享卡片链接和跳转至商详页时获取,详见【获取自定义参数】、【直播间到商详页面携带参数】章节(上限600个字符,超过部分会被截断)
wx.navigateTo({
    url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomId}&custom_params=${customParams}`
})
// 其中wx2b03c6e691cd7370是直播组件appid不能修改

This link allows you to jump to the live component page (the current page portal is only open 'live-player-plugin').

The example effect diagram looks like this:

WeChat small program small program live access instructions

Live components and interfaces

Component Interface

By introducing live-streaming components into the main package/subcontract, developers can easily implement features such as subscriptions, get live status, get user openids, and get shared card link parameters.

Service-side interface

The service-side interface includes a live inter-stream interface and a commodity management interface.

  • The live-streaming interface is the interface capability that a small program-live program provides to developers to perform bulk operations between live streams. Developers can create live streaming rooms in bulk, get playback source videos, get live-streaming room lists, and more.
  • The commodity management interface is the interface capability that the small program live program provides to the developer to carry out bulk operation on the live product. Developers can add, adage, delete, and update items in bulk.
Category Name Description of the function
The component interface Subscribe to the component subscribe The user enters the live broadcast room, can be a single subscription to an unostable live broadcast, the broadcast component will automatically issue an on-air alert to the user
Get live status getLiveStatus Get back to live status for the first time, and poll for live status at a frequency of 1 minute or more later
Get the user openid parameter getOpenid The user openid parameters are obtained through this interface in the live component version 1.1.4 and above
Get the share card link parameter getShare Params In the live component version 1.1.4 and above, the following parameters are obtained through this interface, according to which the developer can establish a mapping relationship between users, live streams, and commodities
Live window control parameters close_picture_in_picture_mode Use parameters to set whether to close the window
Carry parameters (live room to business details page, from the group sharing card back to the live room.) Live component version 1.1.4 and above supports carrying the following parameters, which can be used to establish a mapping relationship between users, live streams, and merchandise.
The service-side interface Create a live room The interface creates the live room directly, and after the success of the creation, the live room will be displayed in the live room list
Get a list of live rooms in the background This interface provides a list of live rooms
Get the playback source video in the background The interface provides playback source video at the end of the live broadcast
Import the listed item to the specified live room Call this interface to import stored items to the specified live stream
Items added and adrogated Call this interface to upload and admiss the commodity information that needs to be broadcast live, after the approval of the commodity entry into the "small program live" commodity library
Recall the product review Call this interface, you can withdraw the live goods of the request for atrial, the number of times consumed is not returned
Resubmit the product review Calling this interface can re-initiate a request for atrial hearing for a commodity that has been withdrawn for questioning
Delete the item Call this interface, you can delete the "small program live" commodity library of goods, after deletion of the live broadcast between the shelves of the goods will also be deleted synchronously, not recoverable
Update the product Call this interface to update the commodity information, the approved goods only allow to update the price type and price, the approved items are not allowed to update, the unoly approved items are allowed to update all fields, only the fields that need to be updated
Get the status of the product Call this interface to get the product's information and audit status
Get a list of items Call this interface to get a list of items