From 68ae7dbd582155c96ec3119bd003236d2d22ab94 Mon Sep 17 00:00:00 2001 From: heavyrian2012 Date: Tue, 11 Jun 2024 09:10:17 +0800 Subject: [PATCH] =?UTF-8?q?SDK=E4=B8=AD=E5=85=B3=E4=BA=8E=E9=A2=91?= =?UTF-8?q?=E9=81=93=E7=9A=84api=E6=94=BE=E5=88=B0ChannelAdmin=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/wildfirechat/sdk/ChannelAdmin.java | 43 +++++++++ .../cn/wildfirechat/sdk/GeneralAdmin.java | 24 +++++ .../main/java/cn/wildfirechat/sdk/Main.java | 90 ++++++++++--------- 3 files changed, 115 insertions(+), 42 deletions(-) create mode 100644 sdk/src/main/java/cn/wildfirechat/sdk/ChannelAdmin.java diff --git a/sdk/src/main/java/cn/wildfirechat/sdk/ChannelAdmin.java b/sdk/src/main/java/cn/wildfirechat/sdk/ChannelAdmin.java new file mode 100644 index 00000000..8f38afaf --- /dev/null +++ b/sdk/src/main/java/cn/wildfirechat/sdk/ChannelAdmin.java @@ -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 createChannel(InputCreateChannel inputCreateChannel) throws Exception { + String path = APIPath.Create_Channel; + return AdminHttpUtils.httpJsonPost(path, inputCreateChannel, OutputCreateChannel.class); + } + + public static IMResult 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 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 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 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 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); + } +} diff --git a/sdk/src/main/java/cn/wildfirechat/sdk/GeneralAdmin.java b/sdk/src/main/java/cn/wildfirechat/sdk/GeneralAdmin.java index 957c75c7..f6ed32c3 100644 --- a/sdk/src/main/java/cn/wildfirechat/sdk/GeneralAdmin.java +++ b/sdk/src/main/java/cn/wildfirechat/sdk/GeneralAdmin.java @@ -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 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 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 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 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 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 isUserSubscribedChannel(String userId, String channelId) throws Exception { String path = APIPath.Check_User_Subscribe_Channel; InputSubscribeChannel input = new InputSubscribeChannel(channelId, userId, 0); diff --git a/sdk/src/main/java/cn/wildfirechat/sdk/Main.java b/sdk/src/main/java/cn/wildfirechat/sdk/Main.java index 66355646..33464278 100644 --- a/sdk/src/main/java/cn/wildfirechat/sdk/Main.java +++ b/sdk/src/main/java/cn/wildfirechat/sdk/Main.java @@ -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 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 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 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 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 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 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 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 resultCreateChannel = GeneralAdmin.createChannel(inputCreateChannel); + IMResult 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 {