添加部分频道相关server api

This commit is contained in:
heavyrian2012
2026-05-10 14:30:59 +08:00
parent 776c9e26c6
commit 42281c3ad3
19 changed files with 956 additions and 29 deletions
@@ -2,9 +2,12 @@ package cn.wildfirechat.sdk;
import cn.wildfirechat.common.APIPath;
import cn.wildfirechat.pojos.*;
import cn.wildfirechat.pojos.mesh.PojoStringList;
import cn.wildfirechat.sdk.model.IMResult;
import cn.wildfirechat.sdk.utilities.AdminHttpUtils;
import java.util.List;
/**
* 频道管理类
* <p>
@@ -53,6 +56,21 @@ public class ChannelAdmin {
return AdminHttpUtils.httpJsonPost(path, inputChannelId, OutputGetChannelInfo.class);
}
/**
* 获取频道信息列表
* @param count 数量
* @param offset offset
* @return 频道信息列表
* @throws Exception 请求失败时抛出异常
*/
public static IMResult<OutputChannelInfoList> getChannelInfoList(int count, int offset) throws Exception {
String path = APIPath.List_Channel_Info;
InputCountOffset inputCountOffset = new InputCountOffset();
inputCountOffset.count = count;
inputCountOffset.offset = offset;
return AdminHttpUtils.httpJsonPost(path, inputCountOffset, OutputChannelInfoList.class);
}
/**
* 订阅频道
* @param channelId 频道ID
@@ -66,6 +84,19 @@ public class ChannelAdmin {
return AdminHttpUtils.httpJsonPost(path, input, Void.class);
}
/**
* 批量用户订阅频道
* @param channelId 频道ID
* @param userIds 用户ID列表
* @return 订阅结果
* @throws Exception 请求失败时抛出异常
*/
public static IMResult<Void> batchSubscribeChannel(String channelId, List<String> userIds) throws Exception {
String path = APIPath.Batch_Subscribe_Channel;
InputSubscribeChannelBatch input = new InputSubscribeChannelBatch(channelId, userIds, 1);
return AdminHttpUtils.httpJsonPost(path, input, Void.class);
}
/**
* 取消订阅频道
* @param channelId 频道ID
@@ -79,6 +110,19 @@ public class ChannelAdmin {
return AdminHttpUtils.httpJsonPost(path, input, Void.class);
}
/**
* 批量用户取消订阅频道
* @param channelId 频道ID
* @param userIds 用户ID列表
* @return 取消订阅结果
* @throws Exception 请求失败时抛出异常
*/
public static IMResult<Void> batchUnsubscribeChannel(String channelId, List<String> userIds) throws Exception {
String path = APIPath.Batch_Subscribe_Channel;
InputSubscribeChannelBatch input = new InputSubscribeChannelBatch(channelId, userIds, 0);
return AdminHttpUtils.httpJsonPost(path, input, Void.class);
}
/**
* 检查用户是否订阅了频道
* @param userId 用户ID
@@ -91,4 +135,18 @@ public class ChannelAdmin {
InputSubscribeChannel input = new InputSubscribeChannel(channelId, userId, 0);
return AdminHttpUtils.httpJsonPost(path, input, OutputBooleanValue.class);
}
/**
* 获取频道订阅用户列表
* @param channelId 频道ID
* @param count
* @param offset
* @return 订阅用户id列表
* @throws Exception 请求失败时抛出异常
*/
public static IMResult<PojoTotalList> getChannelSubscribers(String channelId, int count, int offset) throws Exception {
String path = APIPath.List_Channel_Subscriber;
InputStringCountOffset input = new InputStringCountOffset(channelId, count, offset);
return AdminHttpUtils.httpJsonPost(path, input, PojoTotalList.class);
}
}
@@ -270,7 +270,7 @@ public class Main {
System.out.println("get user info success");
} else {
System.out.println("get user info by mobile failure");
System.exit(-1);
// System.exit(-1);
}
} else {
System.out.println("get user info by mobile failure");
@@ -1022,7 +1022,7 @@ public class Main {
//验证群组已被解散
resultGetGroupInfo = GroupAdmin.getGroupInfo(groupInfo.getTarget_id());
if (resultGetGroupInfo != null && resultGetGroupInfo.getErrorCode() == ErrorCode.ERROR_CODE_NOT_EXIST) {
if (resultGetGroupInfo != null && (resultGetGroupInfo.getErrorCode() == ErrorCode.ERROR_CODE_NOT_EXIST || resultGetGroupInfo.result.isDeleted())) {
System.out.println("group dismissed verified");
} else {
System.out.println("group dismiss verify failure");
@@ -1187,14 +1187,15 @@ public class Main {
System.out.println("failure");
}
//测试删除多播消息
IMResult<Void> deleteMultiCastResult = MessageAdmin.deleteMultiCastMessage("user1", resultMulticastMessage.result.getMessageUid(), multicastReceivers);
if (deleteMultiCastResult != null && deleteMultiCastResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("delete multicast message success");
} else {
System.out.println("delete multicast message failure");
if (commercialServer) {
//测试删除多播消息
IMResult<Void> deleteMultiCastResult = MessageAdmin.deleteMultiCastMessage("user1", resultMulticastMessage.result.getMessageUid(), multicastReceivers);
if (deleteMultiCastResult != null && deleteMultiCastResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("delete multicast message success");
} else {
System.out.println("delete multicast message failure");
}
}
}
//***********************************************
@@ -1591,6 +1592,40 @@ public class Main {
System.exit(-1);
}
IMResult<OutputChannelInfoList> channelInfoListIMResult = ChannelAdmin.getChannelInfoList(10, 0);
if(channelInfoListIMResult != null && channelInfoListIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("get channel list success");
} else {
System.out.println("get channel list failure");
System.exit(-1);
}
voidIMResult = ChannelAdmin.batchSubscribeChannel(inputCreateChannel.getTargetId(), Arrays.asList("user1", "user2", "user3"));
if(voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("batch subscribe channel success");
} else {
System.out.println("batch subscribe channel failure");
System.exit(-1);
}
IMResult<PojoTotalList> totalListIMResult = ChannelAdmin.getChannelSubscribers(inputCreateChannel.getTargetId(), 10, 1);
if(totalListIMResult != null && totalListIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("get channel subscribe list success");
} else {
System.out.println("get channel subscribe list failure");
System.exit(-1);
}
voidIMResult = ChannelAdmin.batchUnsubscribeChannel(inputCreateChannel.getTargetId(), Arrays.asList("user1", "user2", "user3"));
if(voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("batch unsubscribe channel success");
} else {
System.out.println("batch unsubscribe channel failure");
System.exit(-1);
}
voidIMResult = ChannelAdmin.destroyChannel(inputCreateChannel.getTargetId());
if(voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("success");