服务端
服务端API文档

接口概述

更新时间: 2022/06/22 03:21:31

接口概述

  • API调用说明:
  • 接口文档中“voip-host”为案列域名,真实的域名为:https://uc-api.netease.im
  • 本文档中,所有调用网易呼叫中心服务端接口的请求都需要按此规则校验
  • checkSum需要的字段,这几个字段(AppKey,Nonce,CurTime,CheckSum)都需要携带到HTTP请求头里面
  • 所有接口没有特殊说明,默认Content-Type为:application/json;charset=utf-8;

API checksum校验

参数名称 参数说明
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状态表。

  • 所有接口均使用 Content-Type = application/json;charset=UTF-8 格式

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

  • 计算CheckSum的java代码举例如下

import java.security.MessageDigest;
/**
 * 计算CheckSum方法
 */
public class CheckSumBuilder {

    private static Logger logger = LoggerFactory.getLogger(CheckSumBuilder.class);

    private static final String SHA1 = "sha1";

    private static final String MD5 = "md5";

    private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

    /**
     * 计算并获取CheckSum
     *
     * @param appSecret
     * @param nonce
     * @param curTime
     * @return
     */
    public static String getCheckSum(String appSecret, String nonce, String curTime) {
        return encode(SHA1, appSecret + nonce + curTime);
    }

    /**
     * 计算并获取md5值
     *
     * @param requestBody
     * @return
     */
    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 (byte aByte : bytes) {
            buf.append(HEX_DIGITS[(aByte >> 4) & 0x0f]);
            buf.append(HEX_DIGITS[aByte & 0x0f]);
        }
        return buf.toString();
    }

    public static void main(String[] args) {
        String a = getCheckSum("c9df0b60c1ba", "123456789", "1624965937");
        System.out.println(a);
    }

}

  • 生成随机数"Nonce"
    public static String randomStrBylen(int length) {
        String base = "abcdefghijklmnopqrstuvwxyz0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }

  • 生成时间戳"CurTime",单位秒
public static Long getCurrentSeconds() {
        return System.currentTimeMillis()/1000;
}

此文档是否对你有帮助?
有帮助
去反馈
  • 接口概述
  • API checksum校验