欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

E聊SDK-简介(7): API文档

程序员文章站 2022-06-05 22:02:27
...

1.说明:

教程属于官方E聊SDK-简介(7)
进入官网
进入管理台
SDK版本:v1.01
技术交流QQ群: 471688937

2.API文档说明:

为方便开发者更好地理解E聊SDK以及更快地在此基础上进行二次开发,E聊SDK提供了所用的基础API说明,在E聊SDK客户端核心代码EChatIMApis.ts 文件中,罗列了整个客户端使用到的请求API, 详细如下:

public static login: ApiCall<UserLoginForm, string> = new SocketIOApi<UserLoginForm, string>(
        Topic.CONNECTION.topic_name + "/" + Topic.CONNECTION.METHOD.AUTHORITY_REQUEST, "用户登录/请求授权", false);
    public static addOnlineMonitor:ApiCall<ClientOnlineMonitorForm, void> = new SocketIOApi<ClientOnlineMonitorForm, void>(
        Topic.APP_CLIENT.topic_name + "/" + Topic.APP_CLIENT.METHOD.ADD_ONLINE_MONITOR,
        "设置用户的在线监听", true);

    public static  sendMessage: ApiCall<MessageSendForm, void> = new HttpApi<MessageSendForm, void>(
        Topic.APP_UPSTREAM_MESSAGE.base_uri + "/" + Topic.APP_UPSTREAM_MESSAGE.METHOD.SEND,
        "APP跟IM用户发送消息", "POST",true);
    // user
    public static userAdd:ApiCall<UserAddForm, void> = new HttpApi<UserAddForm, void>(
        Topic.APP_USER.base_uri + "/" + Topic.APP_USER.METHOD.ADD,
        "添加用户", "POST", true);
    public static userUpdate:ApiCall<UserUpdateForm, void> = new HttpApi<UserUpdateForm, void>(
        Topic.APP_USER.base_uri + "/" + Topic.APP_USER.METHOD.UPDATE,
        "更新用户", "POST", true);
    public static userList:ApiCall<UserListForm, Array<UserListDTO>> = new HttpApi<UserListForm, Array<UserListDTO>>(
        Topic.APP_USER.base_uri + "/" + Topic.APP_USER.METHOD.LIST,
        "用户列表", "POST", true);
    public static userGet:ApiCall<UserGetForm, UserGetDTO> = new HttpApi<UserGetForm, UserGetDTO>(
        Topic.APP_USER.base_uri + "/" + Topic.APP_USER.METHOD.GET,
        "获取用户信息", "POST", true);
    public static userUpdateToken:ApiCall<UserUpdateTokenForm, void> = new HttpApi<UserUpdateTokenForm, void>(
        Topic.APP_USER.base_uri + "/" + Topic.APP_USER.METHOD.UPDATE_TOKEN,
        "更新用户Token", "POST", true);
    public static userRefreshToken:ApiCall<UserRefreshTokenForm, UserRefreshTokenDTO> = new HttpApi<UserRefreshTokenForm, UserRefreshTokenDTO>(
        Topic.APP_USER.base_uri + "/" + Topic.APP_USER.METHOD.REFRESH_TOKEN,
        "刷新用户Token", "POST", true);
    // history message
    public static historyListMessage:ApiCall<HistoryListForm, Array<MessageListDTO>> = new HttpApi<HistoryListForm, Array<MessageListDTO>>(
        Topic.APP_HISTORY_MESSAGE.base_uri + "/" + Topic.APP_HISTORY_MESSAGE.METHOD.LIST_MESSAGE,
        "获取用户历史信息", "POST", true);
    public static historyListSession:ApiCall<HistoryListSessionForm, Array<HistorySessionDTO>> = new HttpApi<HistoryListSessionForm, Array<HistorySessionDTO>>(
        Topic.APP_HISTORY_MESSAGE.base_uri + "/" + Topic.APP_HISTORY_MESSAGE.METHOD.LIST_SESSION,
        "获取用户历史会话", "POST", true);

    // user relation
    public static addFriend:ApiCall<UserFriendAddForm, void> = new HttpApi<UserFriendAddForm, void>(
        Topic.APP_USER_RELATION.base_uri + "/" + Topic.APP_USER_RELATION.METHOD.ADD_FRIEND,
        "添加朋友", "POST", true);
    public static delFriend:ApiCall<UserFriendDelForm, void> = new HttpApi<UserFriendDelForm, void>(
        Topic.APP_USER_RELATION.base_uri + "/" + Topic.APP_USER_RELATION.METHOD.DEL_FRIEND,
        "删除朋友", "POST", true);
    public static listFriends:ApiCall<UserFriendListForm, UserFriendListDTO> = new HttpApi<UserFriendListForm, UserFriendListDTO>(
        Topic.APP_USER_RELATION.base_uri + "/" + Topic.APP_USER_RELATION.METHOD.LIST_FRIENDS,
        "获取朋友列表", "POST", true);
    public static getFriend:ApiCall<UserFriendGetForm, UserFriendGetDTO> = new HttpApi<UserFriendGetForm, UserFriendGetDTO>(
        Topic.APP_USER_RELATION.base_uri + "/" + Topic.APP_USER_RELATION.METHOD.GET_FRIEND,
        "获取好友", "POST", true);
    public static modifyBlacklistForbid:ApiCall<UserBlacklistModifyForm, void> = new HttpApi<UserBlacklistModifyForm, void>(
        Topic.APP_USER_RELATION.base_uri + "/" + Topic.APP_USER_RELATION.METHOD.MODIFY_BLACKLIST_FORBID,
        "修改朋友黑名单/禁言", "POST", true);
    public static listBlackListForbid:ApiCall<UserBlackForbidListForm, UserBlackForbidListDTO> = new HttpApi<UserBlackForbidListForm, UserBlackForbidListDTO>(
        Topic.APP_USER_RELATION.base_uri + "/" + Topic.APP_USER_RELATION.METHOD.LIST_BLACKLIST_FORBID,
        "获取朋友黑名单/禁言列表", "POST", true);
    public static modifyAlias:ApiCall<UserFriendAliasForm, void> = new HttpApi<UserFriendAliasForm, void>(
        Topic.APP_USER_RELATION.base_uri + "/" + Topic.APP_USER_RELATION.METHOD.MODIFY_ALIAS,
        "修改朋友别名", "POST", true);

    // room
    public static addRoom:ApiCall<RoomAddForm, number> = new HttpApi<RoomAddForm, number>(
        Topic.APP_ROOM.base_uri + "/" + Topic.APP_ROOM.METHOD.ADD,
        "添加群", "POST", true);
    public static updateRoom:ApiCall<RoomUpdateForm, void> = new HttpApi<RoomUpdateForm, void>(
        Topic.APP_ROOM.base_uri + "/" + Topic.APP_ROOM.METHOD.UPDATE,
        "更新群", "POST", true);
    public static listRoom:ApiCall<RoomListForm, Array<RoomListDTO>> = new HttpApi<RoomListForm, Array<RoomListDTO>>(
        Topic.APP_ROOM.base_uri + "/" + Topic.APP_ROOM.METHOD.LIST,
        "获取群列表", "POST", true);
    public static listRoomJoin:ApiCall<RoomListJoinForm, Array<RoomListDTO>> = new HttpApi<RoomListJoinForm, Array<RoomListDTO>>(
        Topic.APP_ROOM.base_uri + "/" + Topic.APP_ROOM.METHOD.LIST_JOIN,
        "获取用户加入的群", "POST", true);
    public static delRoom:ApiCall<RoomDelForm, void> = new HttpApi<RoomDelForm, void>(
        Topic.APP_ROOM.base_uri + "/" + Topic.APP_ROOM.METHOD.DEL,
        "删除群", "POST", true);
    public static getRoom:ApiCall<RoomGetForm, RoomGetDTO> = new HttpApi<RoomGetForm, RoomGetDTO>(
        Topic.APP_ROOM.base_uri + "/" + Topic.APP_ROOM.METHOD.GET,
        "获取单个群信息", "POST", true);

    public static listRoomMember:ApiCall<RoomListForm, Array<RoomDetailListDTO>> = new HttpApi<RoomListForm, Array<RoomDetailListDTO>>(
        Topic.APP_ROOM.base_uri + "/" + Topic.APP_ROOM.METHOD.LIST_MEMBER,
        "列出群成员", "POST", true);
    public static addRoomMember:ApiCall<RoomAddUserForm, void> = new HttpApi<RoomAddUserForm, void>(
        Topic.APP_ROOM.base_uri + "/" + Topic.APP_ROOM.METHOD.ADD_USER,
        "添加群成员", "POST", true);
    public static delRoomMember:ApiCall<RoomDelUserForm, void> = new HttpApi<RoomDelUserForm, void>(
        Topic.APP_ROOM.base_uri + "/" + Topic.APP_ROOM.METHOD.DEL_USER,
        "删除群成员", "POST", true);

    public static userOnline:ApiCall<ClientUserOnlineForm, void> = new HttpApi<ClientUserOnlineForm, void>(
        Topic.APP_CLIENT.base_uri + "/" + Topic.APP_CLIENT.METHOD.USER_ONLINE,
        "列出用户的在线状态", "POST", true);

所有的API接口路径都定义到一个Topic 类下,使用Topic 类下的topic_name + ‘/’ + METHOD,能快速在API文档定位到详细接口说明。

export class Topic {
    static prefix = 'topic.';
    static httpPrefix = '/v1/';

    static CONNECTION = class {
        static topic_name = Topic.prefix + "connection";
        static base_uri = Topic.httpPrefix + "connection";

        static METHOD = class {
            static AUTHORITY_REQUEST = "authority_request";
        }
    };

    static APP_USER = class {
        static topic_name = Topic.prefix + "user";
        static base_uri = Topic.httpPrefix + "user";
        static METHOD = class {
            static ADD = "add";
            static UPDATE = "update";
            static LIST = "list";
            static GET = "get";
            static UPDATE_TOKEN = "update_token";
            static REFRESH_TOKEN = "refresh_token";
        }
    };

    // 通过服务器向客户端发送消息的prefix
    static APP_UPSTREAM_MESSAGE = class {
        static topic_name = Topic.prefix + "upstream_message";
        static base_uri = Topic.httpPrefix + "upstream_message";

        static METHOD = class {
            static SEND = "send";
            static BATCH_SEND = "batch_send";
            static SEND_ACK_TO_SERVER = "sendack_toserver";
        }
    };


    // 服务器向客户端发送消息的prefix
    static APP_DOWNSTREAM_MESSAGE = class {
        static topic_name = Topic.prefix + "downstream_message";
        static base_uri = Topic.httpPrefix + "downstream_message";
        static METHOD = class {
            static SEND_MESSAGE_TO_CLIENT = "sendmessage_toclient";
            static SEND_EVENT_TO_CLIENT = "sendevent_toclient";
        }
    };


    static APP_CLIENT = class {
        static topic_name = Topic.prefix + "client";
        static base_uri = Topic.httpPrefix + "client";
        static METHOD = class {
            static USER_ONLINE = "user_online"; // 列出用户的在线状态
            static ADD_ONLINE_MONITOR = "add_online_monitor";// 设置用户的在线监听
        }
    };

    static APP_ROOM = class {
        static topic_name = Topic.prefix + "room";
        static base_uri = Topic.httpPrefix + "room";
        static METHOD = class {
            static ADD = "add"; // 添加群
            static UPDATE = "update"; // 更新群信息
            static LIST = "list"; // 列出群信息
            static DEL = "del"; // 删除群
            static GET = "get"; // 获取单个群信息
            static LIST_JOIN = "list_join"; // 列出当前用户加入的群
            static LIST_MEMBER = "list_member"; // 列出群信息/群成员
            static ADD_USER = "add_user"; // 添加群用户
            static DEL_USER = "del_user"; // 删除群用户
        }
    };


    static APP_USER_RELATION = class {
        static topic_name = Topic.prefix + "user_relation";
        static base_uri = Topic.httpPrefix + "user_relation";
        static METHOD = class {
            static ADD_FRIEND = "add_friend"; // 添加好友
            static DEL_FRIEND = "del_friend"; // 删除好友
            static LIST_FRIENDS = "list_friends"; // 列出好友列表
            static GET_FRIEND = "get_friend"; // 获取好友
            static MODIFY_BLACKLIST_FORBID = "add_blacklist";// 添加/移除黑名单, 添加/移除黑禁言
            static LIST_BLACKLIST_FORBID = "list_blacklists"; // 列出黑名单, 禁言列表
            static MODIFY_ALIAS = "modify_alias";// 修改IM好友别名
        }
    };

    // 通过服务器向客户端发送消息的prefix
    static APP_HISTORY_MESSAGE = class {
        static topic_name = Topic.prefix + "history";
        static base_uri = Topic.httpPrefix + "history";
        static METHOD = class {
            static LIST_MESSAGE = "list_message"; // 列出历史消息
            static LIST_SESSION = "list_session"; // 列出用户历史会话列表
        }
    }
}

E聊SDK同时支持以socket.io 方式的通讯(使用SocketIOApi)和HttpApi方式的通讯(使用HttpApi), 使用的HttpApi接口请求信息与返回信息详细列表如下, 为保证实时信及减少错漏, Http API文档使用swagger-ui 文档直接生成(请使用Topic 类下的topic_name + ‘/’ + METHOD进行快捷搜索)。
详见: HTTP API文档