### Run the server Source: https://github.com/wildfirechat/im-server/blob/wildfirechat/README.md Starts the Wildfire IM server after extracting the distribution archive and configuring wildfirechat.conf. ```bash ./bin/wildfirechat.sh ``` -------------------------------- ### Robot Service Example: get profile, send message, get user info Source: https://github.com/wildfirechat/im-server/blob/wildfirechat/sdk/README.md Initializes a RobotService with the server URL, robot ID, and secret, then retrieves the robot profile, sends a text message to a user, and fetches user information. Requires a valid robot account. ```java import cn.wildfirechat.sdk.RobotService; import cn.wildfirechat.sdk.messagecontent.TextMessageContent; public class RobotExample { public static void main(String[] args) throws Exception { // 初始化机器人服务 RobotService robot = new RobotService("http://localhost", "robot1", "123456"); // 获取机器人信息 IMResult profile = robot.getProfile(); if (profile.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { System.out.println("机器人名称: " + profile.getResult().getDisplayName()); } // 发送消息给用户 TextMessageContent content = new TextMessageContent("Hello from robot!"); IMResult result = robot.sendMessage("user1", content); if (result.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { System.out.println("机器人消息发送成功"); } // 获取用户信息 IMResult userInfo = robot.getUserInfo("user1"); if (userInfo.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { System.out.println("用户显示名: " + userInfo.getResult().getDisplayName()); } } } ``` -------------------------------- ### Admin API Quick Start: create user, get token, send message Source: https://github.com/wildfirechat/im-server/blob/wildfirechat/sdk/README.md Initializes AdminConfig with the server URL and admin secret, then creates a user, retrieves a user token, and sends a private text message. Requires the server running at http://localhost:18080 and the admin secret '123456'. ```java import cn.wildfirechat.sdk.AdminConfig; import cn.wildfirechat.sdk.UserAdmin; import cn.wildfirechat.sdk.MessageAdmin; import cn.wildfirechat.pojos.InputOutputUserInfo; import cn.wildfirechat.pojos.Conversation; import cn.wildfirechat.sdk.messagecontent.TextMessageContent; import cn.wildfirechat.proto.ProtoConstants; import cn.wildfirechat.sdk.model.IMResult; public class QuickStart { public static void main(String[] args) throws Exception { // 初始化配置 AdminConfig.initAdmin("http://localhost:18080", "123456"); // 创建用户 InputOutputUserInfo user = new InputOutputUserInfo(); user.setUserId("user1"); user.setName("user1"); user.setDisplayName("Test User"); user.setMobile("13900000000"); IMResult result = UserAdmin.createUser(user); if (result.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { System.out.println("创建用户成功: " + result.getResult().getUserId()); } // 获取用户 Token IMResult tokenResult = UserAdmin.getUserToken( "user1", "client1", ProtoConstants.Platform.Platform_Android ); if (tokenResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { System.out.println("Token: " + tokenResult.getResult().getToken()); } // 发送消息 Conversation conversation = new Conversation(); conversation.setType(ProtoConstants.ConversationType.ConversationType_Private); conversation.setTarget("user2"); conversation.setLine(0); TextMessageContent content = new TextMessageContent("Hello, World!"); MessagePayload payload = content.encode(); IMResult msgResult = MessageAdmin.sendMessage("user1", conversation, payload); if (msgResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { System.out.println("消息发送成功,ID: " + msgResult.getResult().getMessageUid()); } } } ``` -------------------------------- ### Channel Service Example: broadcast, subscribe, get subscribers Source: https://github.com/wildfirechat/im-server/blob/wildfirechat/sdk/README.md Initializes a ChannelServiceApi with the server URL, channel ID, and secret, then broadcasts a text message, subscribes a user, and retrieves the subscriber list. The subscriber list retrieval is a commercial version feature. ```java import cn.wildfirechat.sdk.ChannelServiceApi; import cn.wildfirechat.sdk.messagecontent.TextMessageContent; public class ChannelExample { public static void main(String[] args) throws Exception { // 初始化频道服务 ChannelServiceApi channel = new ChannelServiceApi("http://localhost", "channel1", "secret"); // 发送广播消息给订阅者 TextMessageContent content = new TextMessageContent("Channel broadcast message"); IMResult result = channel.broadcastMessage(content); if (result.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { System.out.println("频道广播消息发送成功"); } // 用户订阅频道 IMResult subscribeResult = channel.subscribe("user1"); if (subscribeResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { System.out.println("订阅成功"); } // 获取频道订阅者(商业版功能) IMResult subscribers = channel.getSubscriberList(); if (subscribers.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { System.out.println("订阅者数量: " + subscribers.getResult().getList().size()); } } } ``` -------------------------------- ### SDK command-line usage and parameters Source: https://github.com/wildfirechat/im-server/blob/wildfirechat/sdk/README.md Shows the command-line usage and parameter descriptions for running the SDK jar, including admin URL, admin secret, IM URL, commercial server flag, and advanced VoIP flag. ```text Usage: java -jar sdk.jar adminUrl adminSecret imUrl commercialServer advanceVoip 参数说明: adminUrl - 管理API地址,如 http://localhost:18080 adminSecret - 管理员密钥 imUrl - IM服务地址(机器人/频道使用),如 http://localhost commercialServer - 是否为商业版服务器 (true/false) advanceVoip - 是否启用高级音视频功能 (true/false) ``` -------------------------------- ### Compile and run SDK tests with Maven Source: https://github.com/wildfirechat/im-server/blob/wildfirechat/sdk/README.md Compile the SDK with Maven, then run the test main class with either default configuration or custom arguments specifying admin URL, secret, IM URL, commercial server flag, and advanced VoIP flag. ```bash # 编译 mvn compile # 运行测试(使用默认配置) mvn exec:java -Dexec.mainClass="cn.wildfirechat.sdk.Main" # 运行测试(自定义配置) mvn exec:java -Dexec.mainClass="cn.wildfirechat.sdk.Main" \ -Dexec.args="http://your-server:18080 your-secret http://your-server false false" ``` -------------------------------- ### 安装 deb 包 (Ubuntu/Debian) Source: https://github.com/wildfirechat/im-server/blob/wildfirechat/systemd/README.md 在 Debian 系 Linux 系统(如 Ubuntu)中使用 apt 命令本地安装 im-server.deb 包。注意使用 ./ 路径,若使用 dpkg -i 将不会安装依赖。 ```shell sudo apt install ./im-server.deb ``` -------------------------------- ### systemd 服务管理命令 Source: https://github.com/wildfirechat/im-server/blob/wildfirechat/systemd/README.md 管理 im-server systemd 服务的常用命令,包括刷新配置、启动、停止、重启、查看状态、设置开机自启动、禁止开机自启动和查看控制台日志。 ```shell sudo systemctl daemon-reload ``` ```shell sudo systemctl start im-server ``` ```shell sudo systemctl stop im-server ``` ```shell sudo systemctl restart im-server ``` ```shell sudo systemctl status im-server ``` ```shell sudo systemctl enable im-server ``` ```shell sudo systemctl disable im-server ``` ```shell journalctl -f -u im-server ``` -------------------------------- ### Run checker.jar to verify IM service deployment Source: https://github.com/wildfirechat/im-server/blob/wildfirechat/distribution/src/main/checker/README.md Executes the checker with the service URL, admin password, and host parameters. The check produces garbage data, so stop the IM service and delete its database afterward. Passing this API check does not guarantee full deployment success. ```shell java -jar checker.jar http://127.0.0.1:18080 123456 http://127.0.0.1 false false ``` -------------------------------- ### Import Docker Image Source: https://github.com/wildfirechat/im-server/blob/wildfirechat/docker/README.md Imports the im-server Docker image from the tar file im-server.tar. ```bash sudo docker load -i im-server.tar ``` -------------------------------- ### Build Docker Image Source: https://github.com/wildfirechat/im-server/blob/wildfirechat/docker/README.md Builds the Docker image named im-server from the docker directory. Requires the compiled package to be present in that directory. ```bash sudo docker build -t im-server . ``` -------------------------------- ### Run IM Server Container Source: https://github.com/wildfirechat/im-server/blob/wildfirechat/docker/README.md Runs the im-server container with required volume mounts for config, logs, H2 database, and media storage. The config path must be an absolute path; the H2 database, logs, and media directories need write permissions. JVM heap sizes are set via environment variables, and ports 80, 1883, 8083, 8084, and 18080 are exposed. ```bash sudo docker run -it --name im-server -v $PATH_TO_CONFIG:/opt/im-server/config -v $PATH_TO_LOGS:/opt/im-server/logs -v $PATH_TO_H2DB:/opt/im-server/h2db -v $PATH_TO_MEDIA:/opt/im-server/media -e JVM_XMX=256M -e JVM_XMS=256M -p 80:80 -p 1883:1883 -p 8083:8083 -p 8084:8084 -p 18080:18080 im-server ``` -------------------------------- ### Maven 依赖配置:添加 SDK 和必需依赖 Source: https://github.com/wildfirechat/im-server/blob/wildfirechat/sdk/README.md Maven 依赖配置,包含必需依赖和本地 SDK JAR。必需依赖包括 Gson、commons-httpclient、httpclient、commons-codec、protobuf-java 和 json-simple。SDK JAR 和 common JAR 以 system scope 引入,路径为 ${project.basedir}/lib/。Spring Boot 项目需添加 includeSystemScope 配置。 ```xml com.google.code.gson gson 2.8.9 commons-httpclient commons-httpclient 3.1 org.apache.httpcomponents httpclient 4.5.13 commons-codec commons-codec 1.15 com.google.protobuf protobuf-java 2.5.0 com.googlecode.json-simple json-simple 1.1.1 cn.wildfirechat sdk 1.2.2 system ${project.basedir}/lib/sdk.jar cn.wildfirechat common 1.2.2 system ${project.basedir}/lib/common.jar org.springframework.boot spring-boot-maven-plugin true ```