Skip to content

WeCom Office Live SKILL (wecom-office-live)

企业微信直播域 SKILL:覆盖预约直播创建/修改/取消、直播详情获取、观看明细统计、回放管理等 10 个 API + 1 个回调事件。


1. Prerequisites

应用类型凭证要求权限要求
自建应用应用 secret无特殊权限
第三方应用suite_access_token直播权限

2. API Quick Reference

#接口方法Endpoint
V1创建预约直播POSTliving/create
V2修改预约直播POSTliving/modify
V3取消预约直播POSTliving/cancel
V4获取成员直播ID列表POSTliving/get_living_id
V5获取直播详情GETliving/get_living_info
V6获取直播观看明细POSTliving/get_watch_stat
V7删除直播回放POSTliving/delete_replay_data
V8在微信中观看直播POSTliving/get_living_share_info
V9获取跳转小程序商城的直播观众信息POSTliving/get_living_code

3. API Details

V1. 创建预约直播

POST /cgi-bin/living/create?access_token=ACCESS_TOKEN

请求参数

参数必须类型说明
anchor_useridstring主播 userid
themestring直播主题
living_startint开始时间戳
living_durationint直播时长(秒)
typeint0=通用, 1=小班课, 2=大班课, 3=企业培训, 4=活动直播
descriptionstring直播描述
remind_timeint提前提醒秒数
activity_cover_mediaidstring活动封面 media_id
activity_share_mediaidstring分享图 media_id

返回参数{"livingid": "LIVING_ID"}

V5. 获取直播详情

GET /cgi-bin/living/get_living_info?access_token=ACCESS_TOKEN&livingid=LIVING_ID

返回包含:living_info(含 theme、living_start、living_duration、anchor_userid、living_range、viewer_num、comment_num、open_replay 等)。

V6. 获取观看明细

POST /cgi-bin/living/get_watch_stat?access_token=ACCESS_TOKEN

请求参数{"livingid": "LIVING_ID", "next_key": "0"}

返回包含:stat_info(含 users 数组,每个含 userid、watch_time、is_comment、invite_num 等),ending_watched_count, online_count 等。


4. Callbacks

C1. living_status_change — 直播状态变更

触发条件:直播开始/结束/取消

xml
<xml>
    <Event><![CDATA[living_status_change]]></Event>
    <LivingId><![CDATA[LIVING_ID]]></LivingId>
    <Status>1</Status>  <!-- 0=预约中, 1=直播中, 2=已结束, 3=已过期, 4=已取消 -->
</xml>

5. Code Templates

python
"""WeCom Live Client — 直播管理"""
from wecom_core import WeComClient


class LiveClient:
    def __init__(self, client: WeComClient):
        self.client = client

    def create(self, anchor_userid: str, theme: str,
               living_start: int, living_duration: int, **kwargs) -> str:
        """V1: 创建预约直播,返回 livingid"""
        resp = self.client.post("/living/create", json={
            "anchor_userid": anchor_userid, "theme": theme,
            "living_start": living_start, "living_duration": living_duration,
            **kwargs,
        })
        return resp["livingid"]

    def modify(self, livingid: str, **kwargs) -> None:
        """V2: 修改预约直播"""
        self.client.post("/living/modify", json={"livingid": livingid, **kwargs})

    def cancel(self, livingid: str) -> None:
        """V3: 取消预约直播"""
        self.client.post("/living/cancel", json={"livingid": livingid})

    def get_living_id(self, userid: str, begin_time: int, end_time: int,
                      cursor: str = "", limit: int = 100) -> dict:
        """V4: 获取成员直播ID列表"""
        return self.client.post("/living/get_living_id", json={
            "userid": userid, "begin_time": begin_time,
            "end_time": end_time, "cursor": cursor, "limit": limit,
        })

    def get_living_info(self, livingid: str) -> dict:
        """V5: 获取直播详情"""
        return self.client.get("/living/get_living_info", params={"livingid": livingid})

    def get_watch_stat(self, livingid: str, next_key: str = "0") -> dict:
        """V6: 获取观看明细"""
        return self.client.post("/living/get_watch_stat", json={
            "livingid": livingid, "next_key": next_key,
        })

    def delete_replay(self, livingid: str) -> None:
        """V7: 删除直播回放"""
        self.client.post("/living/delete_replay_data", json={"livingid": livingid})

5.1 Java 示例

java
public class WecomOfficeLiveService {
    private final WeComClient client;

    public WecomOfficeLiveService(WeComClient client) {
        this.client = client;
    }

    /**
     * 使用示例:调用 wecom-office-live 相关 API
     * 请参考本 SKILL 的 API 速查表选择具体接口
     */
    public JsonObject callApi(String path, JsonObject params) throws Exception {
        return client.post(path, params);
    }

    // 更多方法请参考上方 API 详细说明章节,每个接口对应一个方法
    // 关键注意事项请查阅「踩坑指南」章节
}

依赖 (Maven):

xml
<dependency>
    <groupId>com.squareup.okhttp3</groupId>
    <artifactId>okhttp</artifactId>
    <version>4.12.0</version>
</dependency>
<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.10.1</version>
</dependency>

5.2 PHP 示例

php
<?php
class WecomOfficeLiveService
{
    private WeComClient $client;

    public function __construct(WeComClient $client) { $this->client = $client; }

    /**
     * 使用示例:调用 wecom-office-live 相关 API
     * 请参考本 SKILL 的 API 速查表选择具体接口
     */
    public function callApi(string $path, array $params = []): array
    {
        return $this->client->post($path, $params);
    }

    // 更多方法请参考上方 API 详细说明章节
    // 关键注意事项请查阅「踩坑指南」章节
}

依赖 (Composer):

bash
composer require guzzlehttp/guzzle

6. Gotcha Guide

G1. 直播类型影响功能

不同 type 值对应不同的直播功能集合。例如 type=4(活动直播)支持活动封面和分享图。

G2. 观看明细需分页

get_watch_stat 返回的数据可能很大,需使用 next_key 分页获取。

G3. 直播开始前才能修改/取消

已经开始或已结束的直播不能修改/取消。


7. References

doc_id标题
26267获取成员直播ID列表
21995获取直播详情
21999获取直播观看明细
25240创建预约直播
25243取消预约直播
25516修改预约直播
28367直播回调事件

依赖 SKILLwecom-core

Released under the Apache 2.0 License.