Polyv Help Center

Help Center

Send Donation Message

Updated: 2022-09-02 18:08:07

API Description

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

API URL

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

Online API Call

Request Method

POST

API Constraints

  1. The API supports both HTTP and HTTPS. HTTPS is recommended for security. API calls have frequency limits. See details

Request Parameters

Parameter Required Type Description
appId true String Account appId See Get Secret Key
timestamp true Long Current 13-digit millisecond timestamp, valid within 3 minutes
sign true String Signature, a 32-character uppercase MD5 value. The appSecret key used to generate the signature is critical for communication data security. It must not be stored or used directly on the client side. All APIs must be called through the customer's own server to relay requests to the POLYV server for response data. See Signature Generation Rules
channelId true String Channel ID
nickname true String Donor nickname
avatar true String Donor avatar
viewerId true String Donor ID, must be the ID of an online user, typically used with whitelist viewing, custom authorization, external authorization, or independent authorization
donateType true String Donation type
cash: Cash donation
good: Item donation
content true String Donation content: Item name for item donations, amount for cash donations
goodImage false String Item image for item donations, empty for cash donations
sessionId false String Live session ID
goodNum false String Donation quantity, defaults to 1 if not provided
needUserImage false String Whether the socket message requires the user image, defaults to N (Y: Yes, N: No)

Example

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

Form Parameters:

viewerId=1615772956066&goodImage=https%3A%2F%2Fs1.videocc.net%2Fdefault-img%2Fdonate%2Fflower.png&appId=frlr1zazn3&nickname=rock&sign=EB6BB879F2C5962E77324C81A9C453D0&donateType=good&avatar=https%3A%2F%2Flivestatic.videocc.net%2Fuploaded%2Fimages%2Fwebapp%2Favatar%2Fdefault-teacher.png&channelId=2191532&content=%E9%B2%9C%E8%8A%B1&timestamp=1621844118743

Response Parameters

Parameter Type Description
code Integer Response status code, 200 for success, non-200 for failure See Global Error Description
status String Response status text
message String Response description, provides error details when code is 400 or 500
data String Empty for both success and failure requests

Java Request Example

For quick integration of the basic code, download the relevant dependency source code. Click to download source code. After downloading, add it to your own source project. The HttpUtil.java and LiveSignUtil.java in the test cases are included in the download file.

It is strongly recommended to use the Live Java SDK for API integration. The Live Java SDK provides unified encapsulation and optimization for API call logic, exception handling, data signing, and HTTP request thread pools.

private static final Logger log = LoggerFactory.getLogger(LiveInteractionTest.class);
/**
     * 发送打赏消息
     * @throws IOException
     */
    @Test
    public void testSendRewardMsg() throws IOException, NoSuchAlgorithmException {
        //公共参数,填写自己的实际参数
        String appId=super.appId;
        String appSecret=super.appSecret;
        String userId = super.userId;
        String timestamp=String.valueOf(System.currentTimeMillis());
        //业务参数
        String channelId = "2191532";
        String nickname = "rock";
        String avatar = "https://livestatic.videocc.net/uploaded/images/webapp/avatar/default-teacher.png";
        String viewerId = "1615772956066";
        String donateType = "good";
        String content = "鲜花";
        String goodImage = "http://s1.videocc.net/default-img/donate/flower.png";
        String url = "http://api.polyv.net/live/v3/channel/chat/send-reward-msg";
        //http 调用逻辑
        Map<String,String> requestMap = new HashMap<>();
        requestMap.put("appId", appId);
        requestMap.put("timestamp",timestamp);
        requestMap.put("channelId",channelId);
        requestMap.put("viewerId",viewerId);
        requestMap.put("nickname",nickname);
        requestMap.put("avatar",avatar);
        requestMap.put("donateType",donateType);
        requestMap.put("content",content);
        requestMap.put("goodImage",goodImage);

        requestMap.put("sign",LiveSignUtil.getSign(requestMap, appSecret));
        String response = HttpUtil.postFormBody(url,requestMap);
        log.info("测试发送打赏消息接口返回值:{}",response);
        //do somethings
    }

Response Example

See Global Error Description for system-wide error descriptions.

Success Example

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

Error Example

{
    "code": 400,
    "status": "error",
    "message": "invalid signature.",
    "data": ""
}
联系客服,在线咨询