Overview
Update time: 2023/10/25 01:06:13
API call description
In this document, all requests of calling the NetEase YunXin server interface should be verified by this rule.
API checksum verification
The following parameters should be placed in the Http Request Header
Parameter | Parameter Description |
---|---|
AppKey | Appkey assigned by the developer platform |
Nonce | Random number (maximum length 128 characters) |
CurTime | Current UTC timestamp, in seconds, since 0:0:0 a.m. on January 1, 1970 (String) |
CheckSum | SHA1(AppSecret + Nonce + CurTime), string concatenated by three parameters, SHA1 hash calculation, converted to hexadecimal characters (String, lowercase) |
CheckSum validity: for security reasons, the validity of each checkSum
is 5 minutes (calculated by CurTime
), and we recommend to generate a new checkSum
for each request. Please make sure that the server initiating the request is synchronized with the standard time, such as NTP service.
CheckSum will return a 414 error code if the verification fails. See details for the code status table.
Important tip
: All interfaces provided in this document are developer server calls, and AppSecret used to calculate CheckSum should be kept by the developer, stored and used on the application server, but should not be stored or transferred to the client, nor should it be embedded in front-end code such as webpages.
An example of java code for calculating CheckSum is as follows ( see interface example below for examples in other languages).
javaimport java.security.MessageDigest;
public class CheckSumBuilder {
// Calculate and get CheckSum
public static String getCheckSum(String appSecret, String nonce, String curTime) {
return encode("sha1", appSecret + nonce + curTime);
}
// Calculate and get md5 value
public static String getMD5(String requestBody) {
return encode("md5", requestBody);
}
private static String encode(String algorithm, String value) {
if (value == null) {
return null;
}
try {
MessageDigest messageDigest
= MessageDigest.getInstance(algorithm);
messageDigest.update(value.getBytes());
return getFormattedText(messageDigest.digest());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private static String getFormattedText(byte[] bytes) {
int len = bytes.length;
StringBuilder buf = new StringBuilder(len * 2);
for (int j = 0; j < len; j++) {
buf.append(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]);
buf.append(HEX_DIGITS[bytes[j] & 0x0f]);
}
return buf.toString();
}
private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
}
Interface description
- All interfaces of the IM server only support POST requests.
- All interfaces request Content-Type: application/x-www-form-urlencoded;charset=utf-8.
- All interfaces are returned by JSON, while UTF-8 encoding is performed.
Interface example
The NetEase YunXin server interface is a simple http interface, and supports various languages. We also provide some simple examples to the development for reference. Interface example of NetEase YunXin Server