SHA1 Signature Generation Rules
Obtain the userid and secretkey signature key information. See Get Development Key for details.
The secretkey 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 API calls must be relayed through your own server to the POLYV server to obtain response data.Use the SHA1 signature algorithm to generate the signature. The specific encryption calculation method is as follows:
2.1 Arrange the required parameters (parameters with non-null values) in dictionary order of parameter names. Concatenate parameter names and values using the HTTP GET request parameter format (key=value&key=value&key=value). For example:
date=2020-10-13&ptime=1621997347695&userid=1b448be323
2.2 Append the secretkey to the end of the string. Taking secretKey=abc as an example, the result is:
date=2020-10-13&ptime=1621997347695&userid=1b448be323abc
2.3 Then compute the SHA1 hash, and convert the SHA1 result to uppercase letters as the sign.
Common Issues:
Parameters with null values were not excluded during string concatenation.
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 project. The test cases HttpUtil.java and VodSignUtil.java are included in the download file.
It is strongly recommended to use the VOD Java SDK for API integration. The VOD Java SDK provides unified encapsulation and optimization for API call logic, exception handling, data signing, and HTTP request thread pooling.
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.VodSignUtil;
/**
* @author: thomas
**/
public class VodSignTest {
private static final Logger log = LoggerFactory.getLogger(VodSignTest.class);
@Test
public void buildSign() throws UnsupportedEncodingException, NoSuchAlgorithmException {
String userid = "XXXXXXXX";
String secretkey = "XXXXXXXXXXXXXXXXXXXXXXXX";
long timestamp = System.currentTimeMillis();
Map<String, String> paramMap = new HashMap<String, String>();
//公共参数
paramMap.put("userid", userid);
paramMap.put("ptime", Long.toString(timestamp));
//业务参数
paramMap.put("requestId", UUID.randomUUID().toString().replaceAll("-",""));
paramMap.put("vid","1b448be3233659acf35d430ba9210bd4_1");
String sign = VodSignUtil.getSign(paramMap, secretkey);
log.debug("生成签名:{}",sign);
}
}
