add application token
This commit is contained in:
@@ -108,6 +108,8 @@ message.global_mute_exception_types 401,402,403,404,405,407,408,410,411
|
||||
## 当为true时,不转发server api发送的消息;当为false时,转发server api发送的消息。
|
||||
message.no_forward_admin_message false
|
||||
|
||||
## 应用密钥
|
||||
application.secret_key 123456
|
||||
|
||||
##禁止搜索用户
|
||||
friend.disable_search false
|
||||
|
||||
Executable
+58
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <[email protected]>
|
||||
*
|
||||
* 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.common.ErrorCode;
|
||||
import cn.wildfirechat.pojos.InputVerifyApplicationUserInfo;
|
||||
import cn.wildfirechat.pojos.OutputVerifyApplicationUserInfo;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import com.google.gson.Gson;
|
||||
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 io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
|
||||
@Route(APIPath.Channel_Verify_Application_UserInfo)
|
||||
@HttpMethod("POST")
|
||||
public class VerifyApplicationUserInfoAction extends ChannelAction {
|
||||
|
||||
@Override
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputVerifyApplicationUserInfo inputUserToken = getRequestBody(request.getNettyRequest(), InputVerifyApplicationUserInfo.class);
|
||||
RestResult result;
|
||||
if (inputUserToken == null || StringUtil.isNullOrEmpty(inputUserToken.getToken())) {
|
||||
result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER);
|
||||
} else {
|
||||
String userId = messagesStore.verifyApplicationToken(inputUserToken.getToken(), channelInfo.getTargetId());
|
||||
if(userId != null) {
|
||||
OutputVerifyApplicationUserInfo outputVerifyApplicationUser = new OutputVerifyApplicationUserInfo();
|
||||
outputVerifyApplicationUser.setUserId(userId);
|
||||
WFCMessage.User user = messagesStore.getUserInfo(userId);
|
||||
if(user != null) {
|
||||
outputVerifyApplicationUser.setDisplayName(user.getDisplayName());
|
||||
outputVerifyApplicationUser.setPortraitUrl(user.getPortrait());
|
||||
}
|
||||
result = RestResult.ok(outputVerifyApplicationUser);
|
||||
} else {
|
||||
result = RestResult.resultOf(ErrorCode.ERROR_CODE_APPLICATION_TOKEN_ERROR_OR_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -176,6 +176,8 @@ public final class BrokerConstants {
|
||||
public static final String MESSAGES_RECALL_TIME_LIMIT = "message.recall_time_limit";
|
||||
public static final String MESSAGES_DISABLE_GROUP_MANAGER_RECALL = "message.disable_group_manager_recall";
|
||||
|
||||
public static final String APPLICATION_SECRET_KEY = "application.secret_key";
|
||||
|
||||
public static final String HTTP_ADMIN_RATE_LIMIT = "http.admin.rate_limit";
|
||||
public static final String HTTP_ROBOT_RATE_LIMIT = "http.robot.rate_limit";
|
||||
public static final String HTTP_CHANNEL_RATE_LIMIT = "http.channel.rate_limit";
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <[email protected]>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package io.moquette.imhandler;
|
||||
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import io.moquette.spi.impl.Qos1PublishHandler;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import win.liyufan.im.IMTopic;
|
||||
|
||||
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS;
|
||||
|
||||
@Handler(IMTopic.GetApplicationTokenRequestTopic)
|
||||
public class GetApplicationTokenHandler extends IMHandler<WFCMessage.IDBuf> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, ProtoConstants.RequestSourceType requestSourceType, WFCMessage.IDBuf request, Qos1PublishHandler.IMCallback callback) {
|
||||
String token = m_messagesStore.getApplicationToken(fromUser, request.getId());
|
||||
byte[] data = WFCMessage.IDBuf.newBuilder().setId(token).build().toByteArray();
|
||||
ackPayload.ensureWritable(data.length).writeBytes(data);
|
||||
return ERROR_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ import io.moquette.server.Constants;
|
||||
import io.moquette.server.Server;
|
||||
import io.moquette.spi.IMatchingCondition;
|
||||
import io.moquette.spi.IMessagesStore;
|
||||
import io.moquette.spi.impl.security.AES;
|
||||
import io.moquette.spi.security.Tokenor;
|
||||
import io.moquette.spi.impl.subscriptions.Topic;
|
||||
import io.netty.handler.codec.mqtt.MqttVersion;
|
||||
@@ -61,6 +62,7 @@ import static cn.wildfirechat.proto.ProtoConstants.PersistFlag.Transparent;
|
||||
import static cn.wildfirechat.proto.ProtoConstants.Platform.*;
|
||||
import static cn.wildfirechat.proto.ProtoConstants.UpdateUserInfoMask.*;
|
||||
import static io.moquette.BrokerConstants.*;
|
||||
import static io.moquette.BrokerConstants.APPLICATION_SECRET_KEY;
|
||||
import static io.moquette.server.Constants.MAX_CHATROOM_MESSAGE_QUEUE;
|
||||
import static io.moquette.server.Constants.MAX_MESSAGE_QUEUE;
|
||||
import static cn.wildfirechat.pojos.MyInfoType.*;
|
||||
@@ -164,6 +166,8 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
|
||||
private Set<Integer> mUserHideProperties = new HashSet<>();
|
||||
|
||||
private String mApplicationSecretKey;
|
||||
|
||||
MemoryMessagesStore(Server server, DatabaseStore databaseStore) {
|
||||
m_Server = server;
|
||||
this.databaseStore = databaseStore;
|
||||
@@ -442,6 +446,15 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
mApplicationSecretKey = server.getConfig().getProperty(APPLICATION_SECRET_KEY, "wfcapp1290secretkey");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
while (StringUtil.isNullOrEmpty(mApplicationSecretKey) || mApplicationSecretKey.length() < 16) {
|
||||
mApplicationSecretKey += "w";
|
||||
mApplicationSecretKey += mApplicationSecretKey;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3301,6 +3314,36 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getApplicationToken(String fromUser, String applicationId) {
|
||||
byte[] token = AES.AESEncrypt(fromUser + "?|?" + System.currentTimeMillis() + "?|?" + applicationId, mApplicationSecretKey);
|
||||
return new String(Base64.getEncoder().encode(token));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String verifyApplicationToken(String token, String applicationId) {
|
||||
byte[] data = Base64.getDecoder().decode(token);
|
||||
data = AES.AESDecrypt(data, mApplicationSecretKey, true);
|
||||
|
||||
if (data == null || data.length == 0) {
|
||||
return null;
|
||||
} else {
|
||||
String str = new String(data);
|
||||
String[] strArr = str.split("\\?\\|\\?");
|
||||
if (strArr.length == 3) {
|
||||
if (applicationId.equals(strArr[2])) {
|
||||
long timestamp= Long.parseLong(strArr[1]);
|
||||
if(System.currentTimeMillis() - timestamp > 60*1000) {
|
||||
return null;
|
||||
}
|
||||
return strArr[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isNewFriendWelcomeMessage() {
|
||||
return mFriendNewWelcomeMessage;
|
||||
|
||||
@@ -193,6 +193,10 @@ public interface IMessagesStore {
|
||||
|
||||
boolean checkChatroomParticipantIdelTime(MemorySessionStore.Session session);
|
||||
|
||||
|
||||
String getApplicationToken(String fromUser, String applicationId);
|
||||
String verifyApplicationToken(String token, String applicationId);
|
||||
|
||||
ErrorCode getUserSettings(String userId, long version, WFCMessage.GetUserSettingResult.Builder builder);
|
||||
WFCMessage.UserSettingEntry getUserSetting(String userId, int scope, String key);
|
||||
List<WFCMessage.UserSettingEntry> getUserSetting(String userId, int scope);
|
||||
|
||||
@@ -83,4 +83,6 @@ public interface IMTopic {
|
||||
String KickoffPCClientTopic = "KPCC";
|
||||
|
||||
String ClearSessionTopic = "CST";
|
||||
|
||||
String GetApplicationTokenRequestTopic = "ATR";
|
||||
}
|
||||
|
||||
@@ -91,17 +91,15 @@ public interface APIPath {
|
||||
String Channel_Message_Send = "/channel/message/send";
|
||||
String Channel_Subscribe = "/channel/subscribe";
|
||||
String Channel_Subscriber_List = "/channel/subscriber_list";
|
||||
String Channel_Verify_Application_UserInfo = "/channel/user/verify";
|
||||
|
||||
String Robot_User_Info = "/robot/user_info";
|
||||
String Robot_Message_Send = "/robot/message/send";
|
||||
|
||||
String Robot_Set_Callback = "/robot/set_callback";
|
||||
String Robot_Get_Callback = "/robot/get_callback";
|
||||
String Robot_Delete_Callback = "/robot/delete_callback";
|
||||
String Robot_Update_Profile = "/robot/update_profile";
|
||||
|
||||
String Robot_Verify_Application_User = "/robot/user/verify";
|
||||
|
||||
String Robot_Verify_Application_UserInfo = "/robot/user/verify";
|
||||
String Robot_Group_Member_Add = "/robot/group/member/add";
|
||||
String Robot_Group_Allow_Member = "/robot/group/manager/allow";
|
||||
String Robot_Create_Group = "/robot/group/create";
|
||||
|
||||
@@ -50,6 +50,7 @@ public enum ErrorCode {
|
||||
ERROR_CODE_CONFERENCE_ROOM_NOT_EXIST(60, "conference room not exist"),
|
||||
ERROR_CODE_CONFERENCE_SERVICE_NOT_AVAILABLE(61, "conference service not available"),
|
||||
|
||||
ERROR_CODE_APPLICATION_TOKEN_ERROR_OR_TIMEOUT(70, "application token error or timeout"),
|
||||
|
||||
ERROR_CODE_SECRET_CHAT_ACCEPTED_BY_OTHER_CLIENT(81, "secret chat accepted by other client"),
|
||||
ERROR_CODE_SECRET_CHAT_SESSION_NOT_EXIST(82, "secret chat session not exist"),
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@
|
||||
|
||||
package cn.wildfirechat.pojos;
|
||||
|
||||
public class InputVerifyApplicationUser {
|
||||
public class InputVerifyApplicationUserInfo {
|
||||
private String token;
|
||||
|
||||
public String getToken() {
|
||||
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <heavyrain.lee@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package cn.wildfirechat.pojos;
|
||||
|
||||
public class OutputVerifyApplicationUser {
|
||||
private String userId;
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <heavyrain.lee@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package cn.wildfirechat.pojos;
|
||||
|
||||
public class OutputVerifyApplicationUserInfo {
|
||||
private String userId;
|
||||
private String displayName;
|
||||
private String portraitUrl;
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public void setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public String getPortraitUrl() {
|
||||
return portraitUrl;
|
||||
}
|
||||
|
||||
public void setPortraitUrl(String portraitUrl) {
|
||||
this.portraitUrl = portraitUrl;
|
||||
}
|
||||
}
|
||||
@@ -103,6 +103,8 @@ message.global_mute_exception_types 401,402,403,404,405,407,408,410,411
|
||||
## 当为true时,不转发server api发送的消息;当为false时,转发server api发送的消息。
|
||||
message.no_forward_admin_message false
|
||||
|
||||
## 应用密钥
|
||||
application.secret_key 123456
|
||||
|
||||
##禁止搜索用户
|
||||
friend.disable_search false
|
||||
|
||||
@@ -9,28 +9,28 @@ import java.util.List;
|
||||
|
||||
//仅专业版支持,社区版不支持
|
||||
public class ChannelServiceApi {
|
||||
private final ChannelHttpUtils httpUtils;
|
||||
private final ChannelHttpUtils channelHttpUtils;
|
||||
|
||||
public ChannelServiceApi(String imurl, String channelId, String secret) {
|
||||
httpUtils = new ChannelHttpUtils(imurl, channelId, secret);
|
||||
channelHttpUtils = new ChannelHttpUtils(imurl, channelId, secret);
|
||||
}
|
||||
|
||||
public IMResult<InputOutputUserInfo> getUserInfo(String userId) throws Exception {
|
||||
String path = APIPath.Channel_User_Info;
|
||||
InputGetUserInfo getUserInfo = new InputGetUserInfo(userId, null, null);
|
||||
return httpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
|
||||
return channelHttpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
|
||||
}
|
||||
|
||||
public IMResult<InputOutputUserInfo> getUserInfoByName(String userName) throws Exception {
|
||||
String path = APIPath.Channel_User_Info;
|
||||
InputGetUserInfo getUserInfo = new InputGetUserInfo(null, userName, null);
|
||||
return httpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
|
||||
return channelHttpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
|
||||
}
|
||||
|
||||
public IMResult<InputOutputUserInfo> getUserInfoByMobile(String mobile) throws Exception {
|
||||
String path = APIPath.Channel_User_Info;
|
||||
InputGetUserInfo getUserInfo = new InputGetUserInfo(null, null, mobile);
|
||||
return httpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
|
||||
return channelHttpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
|
||||
}
|
||||
|
||||
public IMResult<Void> modifyChannelInfo(/*ProtoConstants.ModifyChannelInfoType*/int type, String value) throws Exception {
|
||||
@@ -38,12 +38,12 @@ public class ChannelServiceApi {
|
||||
InputModifyChannelInfo modifyChannelInfo = new InputModifyChannelInfo();
|
||||
modifyChannelInfo.setType(type);
|
||||
modifyChannelInfo.setValue(value);
|
||||
return httpUtils.httpJsonPost(path, modifyChannelInfo, Void.class);
|
||||
return channelHttpUtils.httpJsonPost(path, modifyChannelInfo, Void.class);
|
||||
}
|
||||
|
||||
public IMResult<OutputGetChannelInfo> getChannelInfo() throws Exception {
|
||||
String path = APIPath.Channel_Get_Profile;
|
||||
return httpUtils.httpJsonPost(path, null, OutputGetChannelInfo.class);
|
||||
return channelHttpUtils.httpJsonPost(path, null, OutputGetChannelInfo.class);
|
||||
}
|
||||
|
||||
public IMResult<SendMessageResult> sendMessage(int line, List<String> targets, MessagePayload payload) throws Exception {
|
||||
@@ -52,7 +52,7 @@ public class ChannelServiceApi {
|
||||
messageData.setLine(0);
|
||||
messageData.setTargets(targets);
|
||||
messageData.setPayload(payload);
|
||||
return httpUtils.httpJsonPost(path, messageData, SendMessageResult.class);
|
||||
return channelHttpUtils.httpJsonPost(path, messageData, SendMessageResult.class);
|
||||
}
|
||||
|
||||
public IMResult<Void> subscribe(String userId) throws Exception {
|
||||
@@ -60,7 +60,7 @@ public class ChannelServiceApi {
|
||||
InputChannelSubscribe input = new InputChannelSubscribe();
|
||||
input.setTarget(userId);
|
||||
input.setSubscribe(1);
|
||||
return httpUtils.httpJsonPost(path, input, Void.class);
|
||||
return channelHttpUtils.httpJsonPost(path, input, Void.class);
|
||||
}
|
||||
|
||||
public IMResult<Void> unsubscribe(String userId) throws Exception {
|
||||
@@ -68,12 +68,20 @@ public class ChannelServiceApi {
|
||||
InputChannelSubscribe input = new InputChannelSubscribe();
|
||||
input.setTarget(userId);
|
||||
input.setSubscribe(0);
|
||||
return httpUtils.httpJsonPost(path, input, Void.class);
|
||||
return channelHttpUtils.httpJsonPost(path, input, Void.class);
|
||||
}
|
||||
|
||||
public IMResult<OutputStringList> getSubscriberList() throws Exception {
|
||||
String path = APIPath.Channel_Subscriber_List;
|
||||
return httpUtils.httpJsonPost(path, null, OutputStringList.class);
|
||||
return channelHttpUtils.httpJsonPost(path, null, OutputStringList.class);
|
||||
}
|
||||
|
||||
|
||||
public IMResult<OutputVerifyApplicationUserInfo> verifyApplicationUserInfo(String token) throws Exception {
|
||||
String path = APIPath.Channel_Verify_Application_UserInfo;
|
||||
InputVerifyApplicationUserInfo input = new InputVerifyApplicationUserInfo();
|
||||
input.setToken(token);
|
||||
return channelHttpUtils.httpJsonPost(path, input, OutputVerifyApplicationUserInfo.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1328,58 +1328,54 @@ public class Main {
|
||||
ChannelServiceApi channelServiceApi = new ChannelServiceApi(IMUrl, resultCreateChannel.getResult().getTargetId(), secret);
|
||||
|
||||
|
||||
|
||||
if (commercialServer) {
|
||||
//3. 测试channel api功能
|
||||
IMResult<Void> resultVoid = channelServiceApi.subscribe("userId2");
|
||||
if (resultVoid != null && resultVoid.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("subscribe success");
|
||||
} else {
|
||||
System.out.println("subscribe failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
resultVoid = channelServiceApi.subscribe("userId3");
|
||||
if (resultVoid != null && resultVoid.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("subscribe done");
|
||||
} else {
|
||||
System.out.println("subscribe failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<OutputStringList> resultStringList = channelServiceApi.getSubscriberList();
|
||||
if (resultStringList != null && resultStringList.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && resultStringList.getResult().getList().contains("userId2") && resultStringList.getResult().getList().contains("userId3")) {
|
||||
System.out.println("get subscriber done");
|
||||
} else {
|
||||
System.out.println("get subscriber failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
resultVoid = channelServiceApi.unsubscribe("userId2");
|
||||
if (resultVoid != null && resultVoid.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("unsubscriber done");
|
||||
} else {
|
||||
System.out.println("unsubscriber failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
resultStringList = channelServiceApi.getSubscriberList();
|
||||
if (resultStringList != null && resultStringList.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && resultStringList.getResult().getList().contains("userId3") && !resultStringList.getResult().getList().contains("userId2")) {
|
||||
System.out.println("get subscriber done");
|
||||
} else {
|
||||
System.out.println("get subscriber failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<InputOutputUserInfo> resultGetUserInfo1 = channelServiceApi.getUserInfo("userId3");
|
||||
if (resultGetUserInfo1 != null && resultGetUserInfo1.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("get user info success");
|
||||
} else {
|
||||
System.out.println("get user info failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
//3. 测试channel api功能
|
||||
IMResult<Void> resultVoid = channelServiceApi.subscribe("userId2");
|
||||
if (resultVoid != null && resultVoid.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("subscribe success");
|
||||
} else {
|
||||
System.out.println("subscribe failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
resultVoid = channelServiceApi.subscribe("userId3");
|
||||
if (resultVoid != null && resultVoid.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("subscribe done");
|
||||
} else {
|
||||
System.out.println("subscribe failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<OutputStringList> resultStringList = channelServiceApi.getSubscriberList();
|
||||
if (resultStringList != null && resultStringList.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && resultStringList.getResult().getList().contains("userId2") && resultStringList.getResult().getList().contains("userId3")) {
|
||||
System.out.println("get subscriber done");
|
||||
} else {
|
||||
System.out.println("get subscriber failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
resultVoid = channelServiceApi.unsubscribe("userId2");
|
||||
if (resultVoid != null && resultVoid.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("unsubscriber done");
|
||||
} else {
|
||||
System.out.println("unsubscriber failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
resultStringList = channelServiceApi.getSubscriberList();
|
||||
if (resultStringList != null && resultStringList.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && resultStringList.getResult().getList().contains("userId3") && !resultStringList.getResult().getList().contains("userId2")) {
|
||||
System.out.println("get subscriber done");
|
||||
} else {
|
||||
System.out.println("get subscriber failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<InputOutputUserInfo> resultGetUserInfo1 = channelServiceApi.getUserInfo("userId3");
|
||||
if (resultGetUserInfo1 != null && resultGetUserInfo1.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("get user info success");
|
||||
} else {
|
||||
System.out.println("get user info failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
MessagePayload payload = new MessagePayload();
|
||||
payload.setType(1);
|
||||
@@ -1403,22 +1399,20 @@ public class Main {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
if (commercialServer) {
|
||||
IMResult<Void> voidIMResult = channelServiceApi.modifyChannelInfo(ProtoConstants.ModifyChannelInfoType.Modify_Channel_Desc, "this is a test channel, update at:" + new Date().toString());
|
||||
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("modify channel profile success");
|
||||
} else {
|
||||
System.out.println("modify channel profile failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
IMResult<Void> voidIMResult = channelServiceApi.modifyChannelInfo(ProtoConstants.ModifyChannelInfoType.Modify_Channel_Desc, "this is a test channel, update at:" + new Date().toString());
|
||||
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("modify channel profile success");
|
||||
} else {
|
||||
System.out.println("modify channel profile failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<OutputGetChannelInfo> outputGetChannelInfoIMResult = channelServiceApi.getChannelInfo();
|
||||
if (outputGetChannelInfoIMResult != null && outputGetChannelInfoIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("get channel info success");
|
||||
} else {
|
||||
System.out.println("get channel info failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
IMResult<OutputGetChannelInfo> outputGetChannelInfoIMResult = channelServiceApi.getChannelInfo();
|
||||
if (outputGetChannelInfoIMResult != null && outputGetChannelInfoIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("get channel info success");
|
||||
} else {
|
||||
System.out.println("get channel info failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
static void testSensitiveApi() throws Exception {
|
||||
|
||||
@@ -4,7 +4,6 @@ import cn.wildfirechat.common.APIPath;
|
||||
import cn.wildfirechat.pojos.*;
|
||||
import cn.wildfirechat.sdk.model.IMResult;
|
||||
import cn.wildfirechat.sdk.utilities.RobotHttpUtils;
|
||||
import cn.wildfirechat.sdk.utilities.RobotHttpUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -214,4 +213,13 @@ public class RobotService {
|
||||
input.setNotify_message(notify_message);
|
||||
return robotHttpUtils.httpJsonPost(path, input, Void.class);
|
||||
}
|
||||
|
||||
public IMResult<OutputVerifyApplicationUserInfo> verifyApplicationUserInfo(String token) throws Exception {
|
||||
String path = APIPath.Robot_Verify_Application_UserInfo;
|
||||
InputVerifyApplicationUserInfo input = new InputVerifyApplicationUserInfo();
|
||||
input.setToken(token);
|
||||
return robotHttpUtils.httpJsonPost(path, input, OutputVerifyApplicationUserInfo.class);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user