SDK中关于频道的api放到ChannelAdmin方法中

This commit is contained in:
heavyrian2012
2024-06-11 09:10:17 +08:00
parent 10fce4baad
commit 68ae7dbd58
3 changed files with 115 additions and 42 deletions
@@ -0,0 +1,43 @@
package cn.wildfirechat.sdk;
import cn.wildfirechat.common.APIPath;
import cn.wildfirechat.pojos.*;
import cn.wildfirechat.sdk.model.IMResult;
import cn.wildfirechat.sdk.utilities.AdminHttpUtils;
public class ChannelAdmin {
public static IMResult<OutputCreateChannel> createChannel(InputCreateChannel inputCreateChannel) throws Exception {
String path = APIPath.Create_Channel;
return AdminHttpUtils.httpJsonPost(path, inputCreateChannel, OutputCreateChannel.class);
}
public static IMResult<Void> destroyChannel(String channelId) throws Exception {
String path = APIPath.Destroy_Channel;
InputChannelId inputChannelId = new InputChannelId(channelId);
return AdminHttpUtils.httpJsonPost(path, inputChannelId, Void.class);
}
public static IMResult<OutputGetChannelInfo> getChannelInfo(String channelId) throws Exception {
String path = APIPath.Get_Channel_Info;
InputChannelId inputChannelId = new InputChannelId(channelId);
return AdminHttpUtils.httpJsonPost(path, inputChannelId, OutputGetChannelInfo.class);
}
public static IMResult<Void> subscribeChannel(String channelId, String userId) throws Exception {
String path = APIPath.Subscribe_Channel;
InputSubscribeChannel input = new InputSubscribeChannel(channelId, userId, 1);
return AdminHttpUtils.httpJsonPost(path, input, Void.class);
}
public static IMResult<Void> unsubscribeChannel(String channelId, String userId) throws Exception {
String path = APIPath.Subscribe_Channel;
InputSubscribeChannel input = new InputSubscribeChannel(channelId, userId, 0);
return AdminHttpUtils.httpJsonPost(path, input, Void.class);
}
public static IMResult<OutputBooleanValue> isUserSubscribedChannel(String userId, String channelId) throws Exception {
String path = APIPath.Check_User_Subscribe_Channel;
InputSubscribeChannel input = new InputSubscribeChannel(channelId, userId, 0);
return AdminHttpUtils.httpJsonPost(path, input, OutputBooleanValue.class);
}
}
@@ -22,35 +22,59 @@ public class GeneralAdmin {
return AdminHttpUtils.httpJsonPost(path, input, Void.class);
}
/**
* @deprecated 请使用 {@link cn.wildfirechat.sdk.ChannelAdmin#createChannel(InputCreateChannel inputCreateChannel)} 代替此方法,因为它将在未来的版本中被移除。
*/
@Deprecated
public static IMResult<OutputCreateChannel> createChannel(InputCreateChannel inputCreateChannel) throws Exception {
String path = APIPath.Create_Channel;
return AdminHttpUtils.httpJsonPost(path, inputCreateChannel, OutputCreateChannel.class);
}
/**
* @deprecated 请使用 {@link cn.wildfirechat.sdk.ChannelAdmin#destroyChannel(String channelId)} 代替此方法,因为它将在未来的版本中被移除。
*/
@Deprecated
public static IMResult<Void> destroyChannel(String channelId) throws Exception {
String path = APIPath.Destroy_Channel;
InputChannelId inputChannelId = new InputChannelId(channelId);
return AdminHttpUtils.httpJsonPost(path, inputChannelId, Void.class);
}
/**
* @deprecated 请使用 {@link cn.wildfirechat.sdk.ChannelAdmin#getChannelInfo(String channelId)} 代替此方法,因为它将在未来的版本中被移除。
*/
@Deprecated
public static IMResult<OutputGetChannelInfo> getChannelInfo(String channelId) throws Exception {
String path = APIPath.Get_Channel_Info;
InputChannelId inputChannelId = new InputChannelId(channelId);
return AdminHttpUtils.httpJsonPost(path, inputChannelId, OutputGetChannelInfo.class);
}
/**
* @deprecated 请使用 {@link cn.wildfirechat.sdk.ChannelAdmin#subscribeChannel(String userId, String channelId)} 代替此方法,因为它将在未来的版本中被移除。
*/
@Deprecated
public static IMResult<Void> subscribeChannel(String channelId, String userId) throws Exception {
String path = APIPath.Subscribe_Channel;
InputSubscribeChannel input = new InputSubscribeChannel(channelId, userId, 1);
return AdminHttpUtils.httpJsonPost(path, input, Void.class);
}
/**
* @deprecated 请使用 {@link cn.wildfirechat.sdk.ChannelAdmin#unsubscribeChannel(String userId, String channelId)} 代替此方法,因为它将在未来的版本中被移除。
*/
@Deprecated
public static IMResult<Void> unsubscribeChannel(String channelId, String userId) throws Exception {
String path = APIPath.Subscribe_Channel;
InputSubscribeChannel input = new InputSubscribeChannel(channelId, userId, 0);
return AdminHttpUtils.httpJsonPost(path, input, Void.class);
}
/**
* @deprecated 请使用 {@link cn.wildfirechat.sdk.ChannelAdmin#isUserSubscribedChannel(String userId, String channelId)} 代替此方法,因为它将在未来的版本中被移除。
*/
@Deprecated
public static IMResult<OutputBooleanValue> isUserSubscribedChannel(String userId, String channelId) throws Exception {
String path = APIPath.Check_User_Subscribe_Channel;
InputSubscribeChannel input = new InputSubscribeChannel(channelId, userId, 0);
+48 -42
View File
@@ -68,6 +68,7 @@ public class Main {
testGroup();
testChatroom();
testMessage();
testChannelApi();
testGeneralApi();
testSensitiveApi();
if (commercialServer) {
@@ -880,6 +881,51 @@ public class Main {
}
}
//***********************************************
//**** 测试频道功能
//***********************************************
static void testChannelApi() throws Exception {
String channelName = "MyChannel";
String channelOwner = "user1";
InputCreateChannel inputCreateChannel = new InputCreateChannel();
inputCreateChannel.setName(channelName);
inputCreateChannel.setOwner(channelOwner);
IMResult<OutputCreateChannel> resultCreateChannel = ChannelAdmin.createChannel(inputCreateChannel);
if (resultCreateChannel != null && resultCreateChannel.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("success");
inputCreateChannel.setTargetId(resultCreateChannel.result.getTargetId());
} else {
System.out.println("create channel failure");
System.exit(-1);
}
IMResult<OutputGetChannelInfo> resultGetChannel = ChannelAdmin.getChannelInfo(inputCreateChannel.getTargetId());
if(resultGetChannel != null && resultGetChannel.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS
&& resultGetChannel.getResult().getName().equals(channelName)
&& resultGetChannel.getResult().getOwner().equals(channelOwner)) {
System.out.println("success");
} else {
System.out.println("get channel failure");
System.exit(-1);
}
IMResult<Void> voidIMResult = ChannelAdmin.destroyChannel(inputCreateChannel.getTargetId());
if(voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("success");
} else {
System.out.println("destroy channel failure");
System.exit(-1);
}
resultGetChannel = ChannelAdmin.getChannelInfo(inputCreateChannel.getTargetId());
if(resultGetChannel != null && resultGetChannel.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && (resultGetChannel.getResult().getState() & ProtoConstants.ChannelState.Channel_State_Mask_Deleted) > 0) {
System.out.println("success");
} else {
System.out.println("get channel failure");
System.exit(-1);
}
}
//***********************************************
//**** 一些其它的功能,比如创建频道,更新用户设置等
//***********************************************
@@ -908,46 +954,6 @@ public class Main {
System.exit(-1);
}
String channelName = "MyChannel";
String channelOwner = "user1";
InputCreateChannel inputCreateChannel = new InputCreateChannel();
inputCreateChannel.setName(channelName);
inputCreateChannel.setOwner(channelOwner);
IMResult<OutputCreateChannel> resultCreateChannel = GeneralAdmin.createChannel(inputCreateChannel);
if (resultCreateChannel != null && resultCreateChannel.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("success");
inputCreateChannel.setTargetId(resultCreateChannel.result.getTargetId());
} else {
System.out.println("create channel failure");
System.exit(-1);
}
IMResult<OutputGetChannelInfo> resultGetChannel = GeneralAdmin.getChannelInfo(inputCreateChannel.getTargetId());
if(resultGetChannel != null && resultGetChannel.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS
&& resultGetChannel.getResult().getName().equals(channelName)
&& resultGetChannel.getResult().getOwner().equals(channelOwner)) {
System.out.println("success");
} else {
System.out.println("get channel failure");
System.exit(-1);
}
IMResult<Void> voidIMResult = GeneralAdmin.destroyChannel(inputCreateChannel.getTargetId());
if(voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("success");
} else {
System.out.println("destroy channel failure");
System.exit(-1);
}
resultGetChannel = GeneralAdmin.getChannelInfo(inputCreateChannel.getTargetId());
if(resultGetChannel != null && resultGetChannel.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && (resultGetChannel.getResult().getState() & ProtoConstants.ChannelState.Channel_State_Mask_Deleted) > 0) {
System.out.println("success");
} else {
System.out.println("get channel failure");
System.exit(-1);
}
IMResult<HealthCheckResult> health = GeneralAdmin.healthCheck();
if(health != null && health.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println(health.result);
@@ -1506,7 +1512,7 @@ public class Main {
inputCreateChannel.setAuto(1);
inputCreateChannel.setCallback("http://192.168.1.81:8088/wf/channelId123");
inputCreateChannel.setState(Channel_State_Mask_FullInfo | Channel_State_Mask_Unsubscribed_User_Access | Channel_State_Mask_Active_Subscribe | Channel_State_Mask_Message_Unsubscribed);
IMResult<OutputCreateChannel> resultCreateChannel = GeneralAdmin.createChannel(inputCreateChannel);
IMResult<OutputCreateChannel> resultCreateChannel = ChannelAdmin.createChannel(inputCreateChannel);
if (resultCreateChannel != null && resultCreateChannel.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("create channel success");
} else {
@@ -1536,7 +1542,7 @@ public class Main {
System.exit(-1);
}
resultVoid = GeneralAdmin.subscribeChannel(channelId, "userId4");
resultVoid = ChannelAdmin.subscribeChannel(channelId, "userId4");
if (resultVoid != null && resultVoid.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("subscribe done");
} else {