签名算法
java
public class SignUtils {
// appKey=HEQHMVoMKTfwWGTa123&appSecret=agcLiNjfDBhiRaebBbpJXnauqfTefXfZxVK&tenantSign=test&version=v1×tamp=1582102489737
public static String sign(String appKey, String appSecret, String tenantSign, String version, String timestamp) throws UnsupportedEncodingException {
String params = "appKey="+appKey+"&appSecret="+appSecret+"&tenantSign="+tenantSign+"&version="+version+"×tamp="+timestamp;
MessageDigest md = DigestUtils.getSha256Digest();
md.update(tenantSign.getBytes("UTF-8"));
byte[] result = md.digest(params.getBytes("UTF-8"));
return Hex.encodeHexString(result);
}
}
golang
func GenSig( appKey , appSecret, tenantSign, version string, timestamp int64) (string, error) {
// appKey=HEQHMVoMKTfwWGTa123&appSecret=agcLiNjfDBhiRaebBbpJXnauqfTefXfZxVK&tenantSign=test&version=v1×tamp=1582102489737
params := fmt.Sprintf("appKey=%s&appSecret=%s&tenantSign=%s&version=%s×tamp=%d",appKey , appSecret, tenantSign, version, timestamp)
h := sha256.New()
h.Write([]byte(tenantSign))
h.Write([]byte(params))
hashInBytes := h.Sum(nil)
signature := hex.EncodeToString(hashInBytes)
//返回哈希值
return signature, nil
}
python
[Haima的博客]
http://www.cnblogs.com/haima/