文档反馈
文档反馈

一键登陆服务端API文档

接口概述

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代码举例如下 ( 其他语言示例见下方接口示例) :

import 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接口,适配各种语言。 当然我们也提供了一些简单的示例供开发者参考。网易云信服务器接口示例


一键登陆

获取手机号码

请求说明

POST https://api.netease.im/phoneauth/login/getMobile HTTP/1.1
Content-Type:application/x-www-form-urlencoded;charset=utf-8

接口描述

获取手机号码。

参数说明

参数类型必须说明
certnameString用户证书名称
tokenString运营商令牌

curl请求示例

curl -X POST -H "AppKey: go9dnk49bkd9jd9vmel1kglw0803mgq3" -H "CurTime: 1443592222" -H "CheckSum: 9e9db3b6c9abb2e1962cf3e6f7316fcc55583f86" -H "Nonce: 4tgggergigwow323t23t" -H "Content-Type: application/x-www-form-urlencoded" -d 'certname=xxxxxxxx&token=xxxxx' 'https://api.netease.im/phoneauth/login/getMobile'

返回说明

http 响应:json

"Content-Type": "application/json; charset=utf-8"
{
    "code": 200,
    "mobilePhone": "1F881288CC68352FC410E8D4A36FC6E0" // 加密手机号码
}

主要返回码

200、403、414、416、431、500

×

反馈成功

非常感谢您的反馈,我们会继续努力做得更好。