Polyv Help Center

Help Center

Signature Generation Rules

Updated: 2024-10-21 09:33:43
  1. Obtain the key information: userId, appId, and appSecret. For details, see Obtain Development Key. The appSecret is used to generate the signature and is critical for communication data security. It must never be stored or used directly on the client side. All APIs must be called through your own server, which then relays requests to the POLYV server to obtain response data.

  2. Use the MD5 signature algorithm to generate the signature. The specific encryption calculation method is as follows:

  2.1 Sort the required request parameters (parameters with non-null values) in dictionary order by parameter name, then concatenate the parameter name and parameter value. For example: ts1552447784505userIde6b23c6f51videoIde6b23c6f51c4b1cb9f0302a92ed42440_eviewerIdabcd1234viewerIp127.0.0.1

  2.2 Append the appSecret to both the beginning and end of the concatenated string. Taking appSecret = abc as an example, the result is: abcts1552447784505userIde6b23c6f51videoIde6b23c6f51c4b1cb9f0302a92ed42440_eviewerIdabcd1234viewerIp127.0.0.1abc

  2.3 Then, calculate the MD5 hash using UTF-8 encoding, and convert the MD5 result to uppercase letters as the sign.

Common Issues:

  1. When concatenating strings, parameters with null values are not excluded.

  2. The character set used for signing must be UTF-8. If not specified, the platform's default character set may be used, leading to errors.

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

package net.polyv.common;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.polyv.util.LiveSignUtil;


/**
 * @author: thomas
 **/
public class LiveSignTest {
    
    private static final Logger log = LoggerFactory.getLogger(LiveSignTest.class);
    
    @Test
    public void buildSign() throws UnsupportedEncodingException, NoSuchAlgorithmException {
        String appId = "XXXXXXXX";
        String userId = "XXXXXXXX";
        String appSecret = "XXXXXXXXXXXXXXXXXXXXXXXX";
    
        long timestamp = System.currentTimeMillis();
        Map<String, String> paramMap = new HashMap<String, String>();
        //公共参数
        paramMap.put("appId", appId);
        paramMap.put("timestamp", Long.toString(timestamp));
        //业务参数
        paramMap.put("lessonId","2149813");
    
        String sign = LiveSignUtil.getSign(paramMap, appSecret);
        log.debug("生成签名:{}",sign);
    
    }
    
    
}


联系客服,在线咨询