打赏-发送打赏消息

接口URL

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

接口说明

  1. 用于发送打赏消息
  2. 请求成功后,服务器会向聊天室的用户广播打赏消息,详见直播聊天室API接口
  3. 接口支持https

支持格式

JSON

请求方式

POST

请求参数

参数名 必选 类型 说明
channelId int 频道ID
appId string 账号的应用ID,在后台的“开发设置”获取
timestamp long 13位毫秒级时间戳
sign string 签名,为32位大写的MD5值
nickname string 打赏者昵称
avatar string 打赏者头像
viewerId string 打赏者ID
donateType string 打赏类型,取值:cash 现金打赏,good 道具打赏
content string 打赏内容:礼物打赏为礼物名称,现金打赏为金额
goodImage string 礼物打赏时为礼物图片,现金打赏时为空
sessionId string 直播场次ID

响应成功JSON示例:

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

响应失败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: 输入的错误频道号",
  "data": ""
}

道具打赏时未提交道具图片

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

发送失败

{
    "code": 400,
    "status": "error",
    "message": "send message failure",
    "data": ""
}

字段说明

参数名 说明
code 响应代码,成功为200,失败为400,签名错误为403,异常错误500
status 成功为success,失败为error
message 错误时为错误提示消息
data 暂无作用

请求示例

<?php
//引用config.php
include 'config.php';

$params = array(
  'appId' => $appId,
  'timestamp' => $timestamp,
  'channelId' => "108888",
  'nickname' => "wenen",
  'avatar' => "https://livestatic.videocc.net/uploaded/images/webapp/avatar/default-teacher.png",
  'viewerId' => "123",
  'donateType' => "good",
  'content' => "黄钻",
  'goodImage' => "http://livestatic.videocc.net/uploaded/images/webapp/channel/donate/06-star.png"
);

//生成sign
$sign = getSign($params); //详细查看config.php文件的getSign方法


$url="http://api.polyv.net/live/v3/channel/chat/send-reward-msg";

function post($url, $post_data = '', $timeout = 5){
   $ch = curl_init();
   curl_setopt ($ch, CURLOPT_URL, $url);
   curl_setopt ($ch, CURLOPT_POST, 1);
   if($post_data != ''){
      curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
   }

   curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
   curl_setopt($ch, CURLOPT_HEADER, false);
   curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
   $file_contents = curl_exec($ch);
   curl_close($ch);
   return $file_contents;
}

$params["sign"] = $sign;
echo post($url,http_build_query($params));
?>

签名规则(config.php文件代码查看)

http://dev.polyv.net/2018/liveproduct/l-api/rule/sign/

以上内容是否对您有帮助?根本没有帮助文档较差文档一般文档不错文档很好
Loading...