接口概述

API调用说明

本文档中,所有调用网易云信服务端接口的请求都需要按此规则校验。

API checksum校验

以下参数需要放在Http Request Header中

参数 参数说明
AppKey 开发者平台分配的appkey
Nonce 随机数(最大长度128个字符)
CurTime 当前UTC时间戳,从1970年1月1日0点0 分0 秒开始到现在的秒数(String)
CheckSum SHA1(AppSecret + Nonce + CurTime),三个参数拼接的字符串,进行SHA1哈希计算,转化成16进制字符(String,小写)

CheckSum有效期:出于安全性考虑,每个checkSum的有效期为5分钟(用CurTime计算),建议每次请求都生成新的checkSum,同时请确认发起请求的服务器是与标准时间同步的,比如有NTP服务。

CheckSum检验失败时会返回414错误码,具体参看code状态表。

重要提示: 本文档中提供的所有接口均面向开发者服务器端调用,用于计算CheckSum的AppSecret开发者应妥善保管,可在应用的服务器端存储和使用,但不应存储或传递到客户端,也不应在网页等前端代码中嵌入。

计算CheckSum的java代码举例如下 ( 其他语言示例见下方接口示例) :

javaimport java.security.MessageDigest;

public class CheckSumBuilder {
    // 计算并获取CheckSum
    public static String getCheckSum(String appSecret, String nonce, String curTime) {
        return encode("sha1", appSecret + nonce + curTime);
    }
    
    // 计算并获取md5值
    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' };
}

接口说明

  1. IM服务端所有接口都只支持POST请求;
  2. 所有接口请求Content-Type类型为:application/x-www-form-urlencoded;charset=utf-8;
  3. 所有接口返回类型为JSON,同时进行UTF-8编码。

接口示例

网易云信服务端接口是简单的http接口,适配各种语言。 当然我们也提供了一些简单的示例供开发者参考。网易云信服务器接口示例

此文档是否对你有帮助?
有帮助
去反馈
  • 接口概述
  • API调用说明
  • API checksum校验
  • 接口说明
  • 接口示例