保利威文档中心

幫助中心

修改帳號積分打賞設定

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

介面URL

http://api.polyv.net/live/v3/channel/donate/update-point

介面說明

1、接口用于设置账号通用设置的积分打赏
2、通用参数通过普通url参数传递(timestamp, appId, sign),设置打赏参数的json通过请求体的方式传递
3、接口支持https

支援格式

JSON

請求方式

POST

請求參數

帶在url後面

參數名 必選 類型 說明
appId string 從API設定中取得,在直播系統登記的appId
timestamp long 13位當前時間戳
sign String 簽名,為32位大寫的MD5值,產生簽名的appSecret金鑰作為通訊資料安全的關鍵資訊,嚴禁儲存在用戶端直接使用,所有API都必須透過客戶自己伺服器中轉呼叫POLYV伺服器取得回應資料【詳見簽名產生規則

請求體傳參

參數名 必選 類型 說明
donatePointEnabled string 積分打賞開關,取值Y/N
queryPointUrl string 取得觀眾積分打賞介面
updatePointUrl string 修改觀眾積分打賞介面
requestFailTips string 請求失敗提示
pointNotEnoughTips string 積分不足提示
pointUnit string 積分單位
goods object[] 積分打賞的道具列表
goodName string 道具名稱,不能超過5個字元
goodImg string 道具圖片,不能超過120個字元(圖片地址可以使用預設地址,或透過上傳圖片介面上傳取得圖片地址)
goodPrice double 道具打賞價格
goodEnabled string 道具開關,值為 Y/N , Y為開啟

註:這裡的channelId,appId,timestamp,sign必須透過url傳參,json資料透過請求體傳參,如: http://api.polyv.net/live/v3/channel/donate/update-point?appId={{appId}}&timestamp={{timestamp}}&sign={{sign}}

請求體json拼接

{
    "donatePointEnabled": "Y",
    "queryPointUrl": "xxx",
    "updatePointUrl": "yyy",
    "requestFailTips": "请求失败了",
    "pointNotEnoughTips": "积分不足啊",
    "pointUnit": "Q币",
    "goods": [
        {
            "goodName": "鲜花123",
            "goodImg": "//livestatic.videocc.net/uploaded/images/webapp/channel/donate/01-flower.png",
            "goodPrice": 123,
            "goodEnabled": "N"
        },
        {
            "goodName": "大跑车",
            "goodImg": "//livestatic.videocc.net/uploaded/images/webapp/channel/donate/08-car.png",
            "goodPrice": 999,
            "goodEnabled": "Y"
        }
    ]
}

回應成功JSON範例:

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

回應失敗JSON範例:

#參數錯誤

{
    "code": 400,
    "status": "error",
    "message": "param validate error",
    "data": 400
}

#未輸入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": ""
}

#json為空或json解析錯誤

{
    "code": 400,
    "status": "error",
    "message": "param validate error",
    "data": ""
}

#json中的goods數量限制

{
    "code": 400,
    "status": "error",
    "message": "goods over limit",
    "data": ""
}

#json中的goods的名稱字元限制

{
    "code": 400,
    "status": "error",
    "message": "goods name over limit",
    "data": ""
}

#json中的goods的圖片地址字元限制

{
    "code": 400,
    "status": "error",
    "message": "goods image length over limit",
    "data": ""
}

#json中的goods的價格資料型別錯誤

{
    "code": 400,
    "status": "error",
    "message": "number range error",
    "data": ""
}

欄位說明

參數名 說明
code 狀態碼,成功為200,簽名失敗為403,參數錯誤為400,伺服器端錯誤為500
status 成功為success,錯誤時為error
message 成功為"",錯誤時為錯誤描述資訊
data 暫無作用

java請求範例

import com.live.util.EncryptionUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Demo {

    private static RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(15000).setConnectTimeout(15000)
            .setConnectionRequestTimeout(15000).build();

    public static void main(String[] args) {
        
        String url = "http://api.polyv.net/live/v3/channel/donate/update-point";
        String appId = "XXXXXX";
        String key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        Map<String, String> map = new HashMap<>();
        long timestamp = System.currentTimeMillis();
        map.put("appId", appId);
        map.put("timestamp", String.valueOf(timestamp));

        String sign = getSign(map, key);
        map.put("sign", sign);
        String body = "{\"goods\":[{\"goodName\":\"鲜花333\",\"goodImg\":\"//livestatic.videocc.net/uploaded/images/webapp/channel/donate/01-flower.png\",\"goodPrice\":0,\"goodEnabled\":\"Y\"},{\"goodName\":\"咖啡\",\"goodImg\":\"//livestatic.videocc.net/uploaded/images/webapp/channel/donate/02-coffee.png\",\"goodPrice\":0.99,\"goodEnabled\":\"Y\"},{\"goodName\":\"点赞\",\"goodImg\":\"//livestatic.videocc.net/uploaded/images/webapp/channel/donate/03-good.png\",\"goodPrice\":1.99,\"goodEnabled\":\"Y\"},{\"goodName\":\"掌声\",\"goodImg\":\"//livestatic.videocc.net/uploaded/images/webapp/channel/donate/04-applaud.png\",\"goodPrice\":2.99,\"goodEnabled\":\"Y\"},{\"goodName\":\"666\",\"goodImg\":\"//livestatic.videocc.net/uploaded/images/webapp/channel/donate/05-666.png\",\"goodPrice\":6.66,\"goodEnabled\":\"Y\"},{\"goodName\":\"小星星\",\"goodImg\":\"//livestatic.videocc.net/uploaded/images/webapp/channel/donate/06-star.png\",\"goodPrice\":9.99,\"goodEnabled\":\"Y\"},{\"goodName\":\"钻石\",\"goodImg\":\"//livestatic.videocc.net/uploaded/images/webapp/channel/donate/07-diamond.png\",\"goodPrice\":19.99,\"goodEnabled\":\"Y\"},{\"goodName\":\"跑车\",\"goodImg\":\"//livestatic.videocc.net/uploaded/images/webapp/channel/donate/08-car.png\",\"goodPrice\":29.99,\"goodEnabled\":\"Y\"},{\"goodName\":\"火箭233\",\"goodImg\":\"//livestatic.videocc.net/uploaded/images/webapp/channel/donate/09-rocket.png\",\"goodPrice\":66.66,\"goodEnabled\":\"Y\"}]}";
        String content = sendHttpPost(url, map, body);
        System.out.println(content);

    }

    /**
     * 发送 post请求
     * @param httpUrl 地址
     * @param maps 参数
     */
    public static String sendHttpPost(String httpUrl, Map<String, String> maps, String body) {
        StringBuilder url = new StringBuilder();
        url.append(httpUrl).append("?");
        for (Map.Entry<String, String> map : maps.entrySet()) {
            url.append(map.getKey()).append("=").append(map.getValue()).append("&");
        }
        String urlStr = url.toString().substring(0, url.length() - 1);
        // 创建httpPost
        HttpPost httpPost = new HttpPost(urlStr);
        try {
            StringEntity entity = new StringEntity(body, Charset.forName("UTF-8"));
            httpPost.setEntity(entity);
        } catch (Exception e) {
            // ...
        }
        return sendHttpPost(httpPost);
    }

    /**
     * 发送Post请求
     * @param httpPost
     * @return
     */
    private static String sendHttpPost(HttpPost httpPost) {
        CloseableHttpClient httpClient = null;
        CloseableHttpResponse response = null;
        HttpEntity entity;
        String responseContent = null;
        try {
            // 创建默认的httpClient实例.
            httpClient = HttpClients.createDefault();
            httpPost.setConfig(requestConfig);
            // 执行请求
            response = httpClient.execute(httpPost);
            entity = response.getEntity();
            responseContent = EntityUtils.toString(entity, "UTF-8");
        } catch (Exception e) {
            // ...
        } finally {
            try {
                // 关闭连接,释放资源
                if (response != null) {
                    response.close();
                }
                if (null != httpPost) {
                    httpPost.releaseConnection();
                }
                if (httpClient != null) {
                    httpClient.close();
                }
            } catch (IOException e) {
                // ...
            }
        }
        return responseContent;
    }

    /**
     * 根据map里的参数构建加密串
     * @param map
     * @param secretKey
     * @return
     */
    protected static String getSign(Map<String, String> map, String secretKey) {
        Map<String, String> params = paraFilter(map);
        // 处理参数,计算MD5哈希值
        String concatedStr = concatParams(params);
        String plain = secretKey + concatedStr + secretKey;
        String encrypted = EncryptionUtils.md5Hex(plain);

        // 32位大写MD5值
        return encrypted.toUpperCase();
    }

    /**
     * 对params根据key来排序并且以key1=value1&key2=value2的形式拼接起来
     * @param params
     * @return
     */
    private static String concatParams(Map<String, String> params) {
        List<String> keys = new ArrayList<>(params.keySet());
        Collections.sort(keys);

        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < keys.size(); i++) {
            String key = keys.get(i);
            String value = params.get(key);

            sb.append(key).append(value);
        }

        return sb.toString();
    }

    /**
     * 除去数组中的空值和签名参数
     * @param sArray 签名参数组
     * @return 去掉空值与签名参数后的新签名参数组
     */
    private static Map<String, String> paraFilter(Map<String, String> sArray) {

        Map<String, String> result = new HashMap<>();

        if (sArray == null || sArray.size() <= 0) {
            return result;
        }

        for (String key : sArray.keySet()) {
            String value = sArray.get(key);
            if (value == null || value.equals("") || key.equalsIgnoreCase("sign")
                    || key.equalsIgnoreCase("sign_type")) {
                continue;
            }
            result.put(key, value);
        }

        return result;
    }

}

php請求範例

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

$params = array(
  'appId' => $appId,
  'timestamp' => $timestamp
);

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

$json = '{"queryPointUrl": "xxx","updatePointUrl": "yyy","requestFailTips": "请求失败了","pointNotEnoughTips": "积分不足啊","pointUnit": "Q币","goods": [{"goodName": "鲜花123","goodImg": "//livestatic.videocc.net/uploaded/images/webapp/channel/donate/01-flower.png","goodPrice": 123,"goodEnabled": "N"},{"goodName": "大跑车","goodImg": "//livestatic.videocc.net/uploaded/images/webapp/channel/donate/08-car.png","goodPrice": 999,"goodEnabled": "Y"}]}';

$params["sign"] = $sign;
$url="http://api.polyv.net/live/v3/channel/donate/update-point?".http_build_query($params);

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/json', 'Content-Length: ' . strlen($post_data)));
   $file_contents = curl_exec($ch);
   curl_close($ch);
   return $file_contents;
}

echo post($url,$json);
?>
联系客服,在线咨询