保利威文档中心

幫助中心

發送聊天室商品資訊 socket 介面

更新時間:2022-09-02 18:08:07

介面 URL

http://api.polyv.net/live/v3/channel/chat/send-product-msg

介面說明

1、發送聊天室 socket 商品資訊

2、介面支援 https

3、介面請求頻次限制為每分鐘 30 次

支援格式

JSON

請求方式

POST

請求數限制

TRUE

請求參數

參數名 必選 類型 說明
appId string 從 API 設定中取得,在直播系統登記的 appId
timestamp long 當前 13 位毫秒級時間戳,3 分鐘內有效
sign String 簽名,為 32 位大寫的 MD5 值,產生簽名的 appSecret 金鑰作為通訊資料安全的關鍵資訊,嚴禁儲存在用戶端直接使用,所有 API 都必須透過客戶自己伺服器中轉呼叫 POLYV 伺服器取得回應資料【詳見簽名產生規則
channelId int 頻道號
status int 操作類型,必須為整型
1:上架商品
2:下架商品
3:刪除商品
4:新增商品
5:編輯商品
6:上移
7:下移
9:推送
10:商品庫開關
目前這個 status 可以自訂,0-20 為平台參數,21 及其以上客戶可自訂

請求體資訊

// 如下json,只有发送这种指定类型的json数据,polyv平台观看页才可以响应数据
// 如果发送其他自定义格式,需要自己开发观看页,接收到改socket 消息时自行进行处理。
// 请求体长度限制1000字符,如果超过,会返回错误。
// 4新增、5编辑、1上架、9推送
{
    "cover": "//liveimages.videocc.net/uploadimage/20200827/chat_img_1779741_15985125681801.jpeg?x-oss-process=image/crop,x_95,y_0,w_235,h_235",
    "link": "https://www.polyv.net",
    "linkType": 10,
    "mobileAppLink": "",
    "mobileLink": "https://ngrok.io/",
    "name": "66666666",
    "params": "{\"222\": 123}",
    "pcLink": "https://www.msuno.cn",
    "price": 23.01,
    "productId": 6282,
    "rank": 18,
    "realPrice": 11.02,
    "showId": 6,
    "status": 1,
    "wxMiniprogramLink": "",
    "wxMiniprogramOriginalId": ""
}
// 2下架(商品Id)、3删除
{
    "productId": 5324
}
// 6上移、7下移(两个商品移动的id和排序和状态)
[
    {
        "channelId": 1779741,
        "cover": "//liveimages.videocc.net/uploadimage/20200707/chat_img_1779741_15941160086266.jpeg?x-oss-process=image/crop,x_437,y_157,w_406,h_406",
        "createdTime": 1594116013000,
        "lastModified": 1599621435000,
        "link": "http://www.msuno.cn",
        "linkType": 10,
        "mobileAppLink": "",
        "mobileLink": "",
        "name": "goods02",
        "pcLink": "",
        "price": 29,
        "productId": 2129,
        "rank": 15,
        "realPrice": 12,
        "showId": 3,
        "status": 1,
        "type": "live",
        "userId": "ee7fe7fbda",
        "wxMiniprogramLink": "",
        "wxMiniprogramOriginalId": ""
    },
    {
        "channelId": 1779741,
        "cover": "//liveimages.videocc.net/uploadimage/20200910/chat_img_1779741_15997324532526.jpeg?x-oss-process=image/crop,x_280,y_0,w_719,h_719",
        "createdTime": 1594116048000,
        "lastModified": 1599756500000,
        "link": "",
        "linkType": 11,
        "mobileAppLink": "",
        "mobileLink": "",
        "name": "1111",
        "params": "{\"222\": 123}",
        "pcLink": "https://www.msuno.cn",
        "price": 23.01,
        "productId": 2130,
        "rank": 11,
        "realPrice": 11.02,
        "showId": 2,
        "status": 1,
        "type": "live",
        "userId": "ee7fe7fbda",
        "wxMiniprogramLink": "",
        "wxMiniprogramOriginalId": ""
    }
]
// 10商品库开关
{
    "content": "",
    "enabled": "N",
    "menuId": "e30e6d716a",
    "menuType": "buy",
    "name": "边看边买",
    "ordered": 6
}

回應成功 JSON 範例:

{
    "code": 200, 
    "status": "success", 
    "message": "", 
    "data": true
}

回應失敗 JSON 範例:

未輸入 appId

{
    "code": 400,
    "status": "error",
    "message": "appId is required.",
    "data": ""
}

appId 不正確

{
    "code": 400,
    "status": "error",
    "message": "application not found.",
    "data": ""
}

時間戳錯誤

{
    "code": 400,
    "status": "error",
    "message": "invalid timestamp.",
    "data": ""
}

簽名錯誤

{
    "code": 403,
    "status": "error",
    "message": "invalid signature.",
    "data": ""
}

頻道號格式錯誤

{
  "code": 400, 
  "status": "error", 
  "message": "param is not digit: dsadasd", 
  "data": ""
}

請求體為空

{
    "code": 400,
    "status": "error",
    "message": "param should not be empty: msg",
    "data": ""
}

請求體資料過長

{
    "code": 400,
    "status": "error",
    "message": "param length is incorrect: 1000",
    "data": ""
}

欄位說明

參數名 說明
code 回應代碼,成功為 200,失敗為 400,簽名錯誤為 401,異常錯誤 500
status 成功為 success,失敗為 error
message 錯誤時為錯誤提示訊息
data 暫無作用,不可作為判斷依據

Java 請求範例

public static void main(String[] args) {
        String url = "http://api.polyv.net/live/v3/channel/chat/send-product-msg";
        // 用户对应的appId和加密串
        String appId = "xxxxxx";
        String appSecret = "xxxxxxxxxxxxxxxxxxxxxxx";
        // 查询频道号
        String channelId = "1796673";
        Map<String, String> params = new HashMap<>();
        params.put("channelId", channelId);
        params.put("status", "1");
        // 调用Polyv的工具类方法设置sign
        PolyvTool.setLiveSign(params, appId, appSecret);
        // 调用Polyv的httpClient工具类发送请求
        String content = HttpClientUtil.getInstance()
                .sendHttpPostJson(url + "?" + PolyvTool.mapJoinNotEncode(params), "json请求体", null);
        System.out.println(content);
    }
联系客服,在线咨询