From fa8a2bef32ffe85f6420d0f490dc81365bbba3e9 Mon Sep 17 00:00:00 2001 From: heavyrian2012 Date: Wed, 8 Feb 2023 11:13:32 +0800 Subject: [PATCH] =?UTF-8?q?channel=20api=E6=B7=BB=E5=8A=A0=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E6=98=AF=E5=90=A6=E6=98=AF=E8=AE=A2=E9=98=85=E8=80=85?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../channel/GetIsChannelSubscriberAction.java | 37 +++++++++++++++++++ .../java/cn/wildfirechat/common/APIPath.java | 1 + .../wildfirechat/sdk/ChannelServiceApi.java | 7 +++- .../main/java/cn/wildfirechat/sdk/Main.java | 12 +++++- 4 files changed, 54 insertions(+), 3 deletions(-) create mode 100755 broker/src/main/java/com/xiaoleilu/loServer/action/channel/GetIsChannelSubscriberAction.java diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/channel/GetIsChannelSubscriberAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/channel/GetIsChannelSubscriberAction.java new file mode 100755 index 00000000..7a65f8d1 --- /dev/null +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/channel/GetIsChannelSubscriberAction.java @@ -0,0 +1,37 @@ +/* + * This file is part of the Wildfire Chat package. + * (c) Heavyrain2012 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +package com.xiaoleilu.loServer.action.channel; + +import cn.wildfirechat.common.APIPath; +import cn.wildfirechat.pojos.InputChannelSubscribe; +import cn.wildfirechat.pojos.InputUserId; +import cn.wildfirechat.pojos.OutputStringList; +import com.xiaoleilu.loServer.RestResult; +import com.xiaoleilu.loServer.annotation.HttpMethod; +import com.xiaoleilu.loServer.annotation.Route; +import com.xiaoleilu.loServer.handler.Request; +import com.xiaoleilu.loServer.handler.Response; +import io.netty.handler.codec.http.FullHttpRequest; + +import java.util.ArrayList; + +@Route(APIPath.Channel_Is_Subscriber) +@HttpMethod("POST") +public class GetIsChannelSubscriberAction extends ChannelAction { + + @Override + public boolean action(Request request, Response response) { + if (request.getNettyRequest() instanceof FullHttpRequest) { + InputUserId input = getRequestBody(request.getNettyRequest(), InputUserId.class); + boolean isSubscriber = messagesStore.checkUserInChannel(input.getUserId(), channelInfo.getTargetId()); + setResponseContent(RestResult.ok(isSubscriber), response); + } + return true; + } +} diff --git a/common/src/main/java/cn/wildfirechat/common/APIPath.java b/common/src/main/java/cn/wildfirechat/common/APIPath.java index 52e73ee8..63616aee 100644 --- a/common/src/main/java/cn/wildfirechat/common/APIPath.java +++ b/common/src/main/java/cn/wildfirechat/common/APIPath.java @@ -104,6 +104,7 @@ public interface APIPath { String Channel_Message_Send = "/channel/message/send"; String Channel_Subscribe = "/channel/subscribe"; String Channel_Subscriber_List = "/channel/subscriber_list"; + String Channel_Is_Subscriber = "/channel/is_subscriber"; String Channel_Application_Get_UserInfo = "/channel/application/get_user_info"; String Robot_User_Info = "/robot/user_info"; diff --git a/sdk/src/main/java/cn/wildfirechat/sdk/ChannelServiceApi.java b/sdk/src/main/java/cn/wildfirechat/sdk/ChannelServiceApi.java index d0e26840..fd3cdddd 100644 --- a/sdk/src/main/java/cn/wildfirechat/sdk/ChannelServiceApi.java +++ b/sdk/src/main/java/cn/wildfirechat/sdk/ChannelServiceApi.java @@ -9,7 +9,6 @@ import org.apache.commons.codec.digest.DigestUtils; import java.util.List; import static cn.wildfirechat.proto.ProtoConstants.ApplicationType.ApplicationType_Channel; -import static cn.wildfirechat.proto.ProtoConstants.ApplicationType.ApplicationType_Robot; //仅专业版支持,社区版不支持 public class ChannelServiceApi { @@ -80,6 +79,12 @@ public class ChannelServiceApi { return channelHttpUtils.httpJsonPost(path, null, OutputStringList.class); } + public IMResult isSubscriber(String userId) throws Exception { + String path = APIPath.Channel_Is_Subscriber; + InputUserId input = new InputUserId(userId); + return channelHttpUtils.httpJsonPost(path, input, Boolean.class); + } + public IMResult applicationGetUserInfo(String authCode) throws Exception { String path = APIPath.Channel_Application_Get_UserInfo; InputApplicationGetUserInfo input = new InputApplicationGetUserInfo(); diff --git a/sdk/src/main/java/cn/wildfirechat/sdk/Main.java b/sdk/src/main/java/cn/wildfirechat/sdk/Main.java index 75dad928..401e6708 100644 --- a/sdk/src/main/java/cn/wildfirechat/sdk/Main.java +++ b/sdk/src/main/java/cn/wildfirechat/sdk/Main.java @@ -50,10 +50,10 @@ public class Main { //admin使用的是18080端口,超级管理接口,理论上不能对外开放端口,也不能让非内部服务知悉密钥。 - testAdmin(); +// testAdmin(); //Robot和Channel都是使用的80端口,第三方可以创建或者为第三方创建,第三方可以使用robot或者channel与IM系统进行对接。 - testRobot(); +// testRobot(); testChannel(); } @@ -1443,6 +1443,14 @@ public class Main { System.exit(-1); } + IMResult booleanIMResult = channelServiceApi.isSubscriber("userId2"); + if(booleanIMResult != null && booleanIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && booleanIMResult.getResult()) { + System.out.println("is subscriber success"); + } else { + System.out.println("is subscriber failure"); + System.exit(-1); + } + resultVoid = channelServiceApi.unsubscribe("userId2"); if (resultVoid != null && resultVoid.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { System.out.println("unsubscriber done");