Merge branch 'refactor_server_api' into wildfirechat
* refactor_server_api: update update update update update update
This commit is contained in:
@@ -28,7 +28,7 @@ public class UnknownErrorAction extends Action{
|
||||
|
||||
@Override
|
||||
public boolean action(Request request, Response response) {
|
||||
response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
|
||||
response.setStatus(HttpResponseStatus.NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
|
||||
@Route(APIPath.User_Status)
|
||||
@Route(APIPath.User_Update_Block_Status)
|
||||
@HttpMethod("POST")
|
||||
public class BlockUserAction extends AdminAction {
|
||||
|
||||
@@ -45,7 +45,9 @@ public class BlockUserAction extends AdminAction {
|
||||
result = RestResult.resultOf(errorCode);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
|
||||
RPCCenter.getInstance().sendRequest(null, null, RPCCenter.KICKOFF_USER_REQUEST, inputUserBlock.getUserId().getBytes(), inputUserBlock.getUserId(), TargetEntry.Type.TARGET_TYPE_USER, null, true);
|
||||
if (inputUserBlock.getStatus() != 0) {
|
||||
RPCCenter.getInstance().sendRequest(null, null, RPCCenter.KICKOFF_USER_REQUEST, inputUserBlock.getUserId().getBytes(), inputUserBlock.getUserId(), TargetEntry.Type.TARGET_TYPE_USER, null, true);
|
||||
}
|
||||
|
||||
sendResponse(response, ErrorCode.ERROR_CODE_SUCCESS, null);
|
||||
} else {
|
||||
|
||||
@@ -20,7 +20,7 @@ import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
|
||||
@Route(APIPath.User_Online_Status)
|
||||
@Route(APIPath.User_Get_Online_Status)
|
||||
@HttpMethod("POST")
|
||||
public class CheckUserOnlineAction extends AdminAction {
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ 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 cn.wildfirechat.pojos.InputDismissGroupMember;
|
||||
import cn.wildfirechat.pojos.InputDismissGroup;
|
||||
import io.moquette.persistence.RPCCenter;
|
||||
import io.moquette.persistence.TargetEntry;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
@@ -40,9 +40,9 @@ public class DismissGroupAction extends AdminAction {
|
||||
@Override
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputDismissGroupMember inputDismissGroup = getRequestBody(request.getNettyRequest(), InputDismissGroupMember.class);
|
||||
InputDismissGroup inputDismissGroup = getRequestBody(request.getNettyRequest(), InputDismissGroup.class);
|
||||
if (inputDismissGroup.isValide()) {
|
||||
RPCCenter.getInstance().sendRequest(inputDismissGroup.getOperator(), null, IMTopic.AddGroupMemberTopic, inputDismissGroup.toProtoGroupRequest().toByteArray(), inputDismissGroup.getOperator(), TargetEntry.Type.TARGET_TYPE_USER, new RPCCenter.Callback() {
|
||||
RPCCenter.getInstance().sendRequest(inputDismissGroup.getOperator(), null, IMTopic.DismissGroupTopic, inputDismissGroup.toProtoGroupRequest().toByteArray(), inputDismissGroup.getOperator(), TargetEntry.Type.TARGET_TYPE_USER, new RPCCenter.Callback() {
|
||||
@Override
|
||||
public void onSuccess(byte[] result) {
|
||||
ByteBuf byteBuf = Unpooled.buffer();
|
||||
|
||||
@@ -29,7 +29,7 @@ import win.liyufan.im.IMTopic;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@Route(APIPath.Friend_Status)
|
||||
@Route(APIPath.Friend_Update_Status)
|
||||
@HttpMethod("POST")
|
||||
public class FriendRelationAction extends AdminAction {
|
||||
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Route(APIPath.Friend_List)
|
||||
@Route(APIPath.Friend_Get_List)
|
||||
@HttpMethod("POST")
|
||||
public class FriendRelationGetAction extends AdminAction {
|
||||
|
||||
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.admin;
|
||||
|
||||
import cn.wildfirechat.common.APIPath;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.pojos.InputGetGroup;
|
||||
import cn.wildfirechat.pojos.InputGetUserInfo;
|
||||
import cn.wildfirechat.pojos.InputOutputUserInfo;
|
||||
import cn.wildfirechat.pojos.PojoGroupInfo;
|
||||
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.Group_Get_Info)
|
||||
@HttpMethod("POST")
|
||||
public class GetGroupInfoAction extends AdminAction {
|
||||
|
||||
@Override
|
||||
public boolean isTransactionAction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputGetGroup inputGetGroup = getRequestBody(request.getNettyRequest(), InputGetGroup.class);
|
||||
if (inputGetGroup != null
|
||||
&& (!StringUtil.isNullOrEmpty(inputGetGroup.getGroupId()))) {
|
||||
|
||||
WFCMessage.GroupInfo groupInfo = messagesStore.getGroupInfo(inputGetGroup.getGroupId());
|
||||
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result;
|
||||
if (groupInfo == null) {
|
||||
result = RestResult.resultOf(ErrorCode.ERROR_CODE_NOT_EXIST);
|
||||
} else {
|
||||
PojoGroupInfo pojoGroupInfo = new PojoGroupInfo();
|
||||
pojoGroupInfo.setExtra(groupInfo.getExtra());
|
||||
pojoGroupInfo.setName(groupInfo.getName());
|
||||
pojoGroupInfo.setOwner(groupInfo.getOwner());
|
||||
pojoGroupInfo.setPortrait(groupInfo.getPortrait());
|
||||
pojoGroupInfo.setTarget_id(groupInfo.getTargetId());
|
||||
pojoGroupInfo.setType(groupInfo.getType());
|
||||
result = RestResult.ok(pojoGroupInfo);
|
||||
}
|
||||
|
||||
response.setContent(new Gson().toJson(result));
|
||||
} else {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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.admin;
|
||||
|
||||
import cn.wildfirechat.common.APIPath;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.pojos.InputGetGroup;
|
||||
import cn.wildfirechat.pojos.OutputGroupMemberList;
|
||||
import cn.wildfirechat.pojos.PojoGroupInfo;
|
||||
import cn.wildfirechat.pojos.PojoGroupMember;
|
||||
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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Route(APIPath.Group_Member_List)
|
||||
@HttpMethod("POST")
|
||||
public class GetGroupMembersAction extends AdminAction {
|
||||
|
||||
@Override
|
||||
public boolean isTransactionAction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputGetGroup inputGetGroup = getRequestBody(request.getNettyRequest(), InputGetGroup.class);
|
||||
if (inputGetGroup != null
|
||||
&& (!StringUtil.isNullOrEmpty(inputGetGroup.getGroupId()))) {
|
||||
|
||||
List<WFCMessage.GroupMember> members = new ArrayList<>();
|
||||
ErrorCode errorCode = messagesStore.getGroupMembers(inputGetGroup.getGroupId(), 0, members);
|
||||
|
||||
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result;
|
||||
if (errorCode != ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
result = RestResult.resultOf(errorCode);
|
||||
} else {
|
||||
OutputGroupMemberList out = new OutputGroupMemberList();
|
||||
out.setMembers(new ArrayList<>());
|
||||
for (WFCMessage.GroupMember member : members) {
|
||||
PojoGroupMember pm = new PojoGroupMember();
|
||||
pm.setMember_id(member.getMemberId());
|
||||
pm.setAlias(member.getAlias());
|
||||
pm.setType(member.getType());
|
||||
out.getMembers().add(pm);
|
||||
}
|
||||
result = RestResult.ok(out);
|
||||
}
|
||||
|
||||
response.setContent(new Gson().toJson(result));
|
||||
} else {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ import win.liyufan.im.IMTopic;
|
||||
import java.util.Base64;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@Route(APIPath.Get_User_Token)
|
||||
@Route(APIPath.User_Get_Token)
|
||||
@HttpMethod("POST")
|
||||
public class GetIMTokenAction extends AdminAction {
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
|
||||
@Route(APIPath.Get_User_Info)
|
||||
@Route(APIPath.User_Get_Info)
|
||||
@HttpMethod("POST")
|
||||
public class GetUserAction extends AdminAction {
|
||||
|
||||
@@ -37,7 +37,7 @@ public class GetUserAction extends AdminAction {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputGetUserInfo inputUserId = getRequestBody(request.getNettyRequest(), InputGetUserInfo.class);
|
||||
if (inputUserId != null
|
||||
&& (!StringUtil.isNullOrEmpty(inputUserId.getUserId()) || !StringUtil.isNullOrEmpty(inputUserId.getName()))) {
|
||||
&& (!StringUtil.isNullOrEmpty(inputUserId.getUserId()) || !StringUtil.isNullOrEmpty(inputUserId.getName()) || !StringUtil.isNullOrEmpty(inputUserId.getMobile()))) {
|
||||
|
||||
WFCMessage.User user = null;
|
||||
if(!StringUtil.isNullOrEmpty(inputUserId.getUserId())) {
|
||||
|
||||
+5
-2
@@ -9,6 +9,7 @@
|
||||
package com.xiaoleilu.loServer.action.admin;
|
||||
|
||||
import cn.wildfirechat.common.APIPath;
|
||||
import cn.wildfirechat.pojos.OutputUserBlockStatusList;
|
||||
import com.google.gson.Gson;
|
||||
import com.xiaoleilu.loServer.RestResult;
|
||||
import com.xiaoleilu.loServer.annotation.HttpMethod;
|
||||
@@ -18,7 +19,7 @@ import com.xiaoleilu.loServer.handler.Response;
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
|
||||
@Route(APIPath.User_Status_List)
|
||||
@Route(APIPath.User_Get_Blocked_List)
|
||||
@HttpMethod("POST")
|
||||
public class GetUserBlockListAction extends AdminAction {
|
||||
|
||||
@@ -31,7 +32,9 @@ public class GetUserBlockListAction extends AdminAction {
|
||||
public boolean action(Request request, Response response) {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
response.setStatus(HttpResponseStatus.OK);
|
||||
RestResult result = RestResult.ok(messagesStore.getUserStatusList());
|
||||
OutputUserBlockStatusList list = new OutputUserBlockStatusList();
|
||||
list.setStatusList(messagesStore.getUserStatusList());
|
||||
RestResult result = RestResult.ok(list);
|
||||
response.setContent(new Gson().toJson(result));
|
||||
}
|
||||
return true;
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
|
||||
@Route(APIPath.User_Check_Status)
|
||||
@Route(APIPath.User_Check_Block_Status)
|
||||
@HttpMethod("POST")
|
||||
public class GetUserBlockStatusAction extends AdminAction {
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import win.liyufan.im.IMTopic;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@Route(APIPath.Group_Owner)
|
||||
@Route(APIPath.Group_Transfer)
|
||||
@HttpMethod("POST")
|
||||
public class TransferGroupAction extends AdminAction {
|
||||
|
||||
@@ -42,7 +42,7 @@ public class TransferGroupAction extends AdminAction {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputTransferGroup inputDismissGroup = getRequestBody(request.getNettyRequest(), InputTransferGroup.class);
|
||||
if (inputDismissGroup.isValide()) {
|
||||
RPCCenter.getInstance().sendRequest(inputDismissGroup.getOperator(), null, IMTopic.AddGroupMemberTopic, inputDismissGroup.toProtoGroupRequest().toByteArray(), inputDismissGroup.getOperator(), TargetEntry.Type.TARGET_TYPE_USER, new RPCCenter.Callback() {
|
||||
RPCCenter.getInstance().sendRequest(inputDismissGroup.getOperator(), null, IMTopic.TransferGroupTopic, inputDismissGroup.toProtoGroupRequest().toByteArray(), inputDismissGroup.getOperator(), TargetEntry.Type.TARGET_TYPE_USER, new RPCCenter.Callback() {
|
||||
@Override
|
||||
public void onSuccess(byte[] result) {
|
||||
ByteBuf byteBuf = Unpooled.buffer();
|
||||
|
||||
@@ -32,7 +32,7 @@ public class GetUserAction extends RobotAction {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputGetUserInfo inputUserId = getRequestBody(request.getNettyRequest(), InputGetUserInfo.class);
|
||||
if (inputUserId != null
|
||||
&& (!StringUtil.isNullOrEmpty(inputUserId.getUserId()) || !StringUtil.isNullOrEmpty(inputUserId.getName()))) {
|
||||
&& (!StringUtil.isNullOrEmpty(inputUserId.getUserId()) || !StringUtil.isNullOrEmpty(inputUserId.getName()) || !StringUtil.isNullOrEmpty(inputUserId.getMobile()))) {
|
||||
|
||||
WFCMessage.User user = null;
|
||||
if(!StringUtil.isNullOrEmpty(inputUserId.getUserId())) {
|
||||
|
||||
@@ -10,6 +10,7 @@ package io.moquette.imhandler;
|
||||
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import cn.wildfirechat.pojos.GroupNotificationBinaryContent;
|
||||
import com.hazelcast.util.StringUtil;
|
||||
import io.moquette.spi.impl.Qos1PublishHandler;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
@@ -19,6 +20,13 @@ import win.liyufan.im.IMTopic;
|
||||
public class CreateGroupHandler extends GroupHandler<WFCMessage.CreateGroupRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.CreateGroupRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
|
||||
if (!StringUtil.isNullOrEmpty(request.getGroup().getGroupInfo().getTargetId())) {
|
||||
WFCMessage.GroupInfo existGroupInfo = m_messagesStore.getGroupInfo(request.getGroup().getGroupInfo().getTargetId());
|
||||
if (existGroupInfo != null) {
|
||||
return ErrorCode.ERROR_CODE_GROUP_ALREADY_EXIST;
|
||||
}
|
||||
}
|
||||
WFCMessage.GroupInfo groupInfo = m_messagesStore.createGroup(fromUser, request.getGroup().getGroupInfo(), request.getGroup().getMembersList());
|
||||
if (groupInfo != null) {
|
||||
if(request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
|
||||
|
||||
@@ -24,9 +24,9 @@ public class DismissGroupHandler extends GroupHandler<WFCMessage.DismissGroupReq
|
||||
WFCMessage.GroupInfo groupInfo = m_messagesStore.getGroupInfo(request.getGroupId());
|
||||
ErrorCode errorCode;
|
||||
if (groupInfo == null) {
|
||||
errorCode = m_messagesStore.dismissGroup(fromUser, request.getGroupId());
|
||||
errorCode = m_messagesStore.dismissGroup(fromUser, request.getGroupId(), isAdmin);
|
||||
|
||||
} else if ((groupInfo.getType() == ProtoConstants.GroupType.GroupType_Normal || groupInfo.getType() == ProtoConstants.GroupType.GroupType_Restricted)
|
||||
} else if (isAdmin || (groupInfo.getType() == ProtoConstants.GroupType.GroupType_Normal || groupInfo.getType() == ProtoConstants.GroupType.GroupType_Restricted)
|
||||
&& groupInfo.getOwner() != null && groupInfo.getOwner().equals(fromUser)) {
|
||||
|
||||
//send notify message first, then dismiss group
|
||||
@@ -36,7 +36,7 @@ public class DismissGroupHandler extends GroupHandler<WFCMessage.DismissGroupReq
|
||||
WFCMessage.MessageContent content = new GroupNotificationBinaryContent(groupInfo.getTargetId(), fromUser, null, "").getDismissGroupNotifyContent();
|
||||
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), content);
|
||||
}
|
||||
errorCode = m_messagesStore.dismissGroup(fromUser, request.getGroupId());
|
||||
errorCode = m_messagesStore.dismissGroup(fromUser, request.getGroupId(), isAdmin);
|
||||
} else {
|
||||
errorCode = ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS;
|
||||
public class TransferGroupHandler extends GroupHandler<WFCMessage.TransferGroupRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.TransferGroupRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
ErrorCode errorCode = m_messagesStore.transferGroup(fromUser, request.getGroupId(), request.getNewOwner());
|
||||
ErrorCode errorCode = m_messagesStore.transferGroup(fromUser, request.getGroupId(), request.getNewOwner(), isAdmin);
|
||||
if (errorCode == ERROR_CODE_SUCCESS) {
|
||||
if (request.hasNotifyContent() && request.getNotifyContent().getType() > 0) {
|
||||
sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), request.getNotifyContent());
|
||||
|
||||
@@ -749,7 +749,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorCode dismissGroup(String operator, String groupId) {
|
||||
public ErrorCode dismissGroup(String operator, String groupId, boolean isAdmin) {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
IMap<String, WFCMessage.GroupInfo> mIMap = hzInstance.getMap(GROUPS_MAP);
|
||||
|
||||
@@ -762,9 +762,9 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
return ErrorCode.ERROR_CODE_NOT_EXIST;
|
||||
}
|
||||
|
||||
if (groupInfo.getType() == ProtoConstants.GroupType.GroupType_Free ||
|
||||
if (!isAdmin && (groupInfo.getType() == ProtoConstants.GroupType.GroupType_Free ||
|
||||
(groupInfo.getType() == ProtoConstants.GroupType.GroupType_Restricted || groupInfo.getType() == ProtoConstants.GroupType.GroupType_Normal)
|
||||
&& (groupInfo.getOwner() == null || !groupInfo.getOwner().equals(operator))) {
|
||||
&& (groupInfo.getOwner() == null || !groupInfo.getOwner().equals(operator)))) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
|
||||
@@ -913,7 +913,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
|
||||
|
||||
@Override
|
||||
public ErrorCode transferGroup(String operator, String groupId, String newOwner) {
|
||||
public ErrorCode transferGroup(String operator, String groupId, String newOwner, boolean isAdmin) {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
IMap<String, WFCMessage.GroupInfo> mIMap = hzInstance.getMap(GROUPS_MAP);
|
||||
|
||||
@@ -924,7 +924,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
return ErrorCode.ERROR_CODE_NOT_EXIST;
|
||||
}
|
||||
|
||||
if ((groupInfo.getType() == ProtoConstants.GroupType.GroupType_Restricted || groupInfo.getType() == ProtoConstants.GroupType.GroupType_Normal)
|
||||
if (!isAdmin && (groupInfo.getType() == ProtoConstants.GroupType.GroupType_Restricted || groupInfo.getType() == ProtoConstants.GroupType.GroupType_Normal)
|
||||
&& (groupInfo.getOwner() == null || !groupInfo.getOwner().equals(operator))) {
|
||||
return ErrorCode.ERROR_CODE_NOT_RIGHT;
|
||||
}
|
||||
|
||||
@@ -104,13 +104,13 @@ public interface IMessagesStore {
|
||||
ErrorCode addGroupMembers(String operator, String groupId, List<WFCMessage.GroupMember> memberList);
|
||||
ErrorCode kickoffGroupMembers(String operator, String groupId, List<String> memberList);
|
||||
ErrorCode quitGroup(String operator, String groupId);
|
||||
ErrorCode dismissGroup(String operator, String groupId);
|
||||
ErrorCode dismissGroup(String operator, String groupId, boolean isAdmin);
|
||||
ErrorCode modifyGroupInfo(String operator, String groupId, int modifyType, String value);
|
||||
ErrorCode modifyGroupAlias(String operator, String groupId, String alias);
|
||||
List<WFCMessage.GroupInfo> getGroupInfos(List<WFCMessage.UserRequest> requests);
|
||||
WFCMessage.GroupInfo getGroupInfo(String groupId);
|
||||
ErrorCode getGroupMembers(String groupId, long maxDt, List<WFCMessage.GroupMember> members);
|
||||
ErrorCode transferGroup(String operator, String groupId, String newOwner);
|
||||
ErrorCode transferGroup(String operator, String groupId, String newOwner, boolean isAdmin);
|
||||
boolean isMemberInGroup(String member, String groupId);
|
||||
boolean isForbiddenInGroup(String member, String groupId);
|
||||
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ import io.netty.util.internal.StringUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class InputDismissGroupMember extends InputGroupBase {
|
||||
public class InputDismissGroup extends InputGroupBase {
|
||||
private String group_id;
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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 cn.wildfirechat.pojos;
|
||||
|
||||
public class InputGetGroup {
|
||||
private String groupId;
|
||||
|
||||
public String getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId(String groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
}
|
||||
@@ -13,9 +13,10 @@ public class InputGetUserInfo {
|
||||
private String name;
|
||||
private String mobile;
|
||||
|
||||
public InputGetUserInfo(String userId, String name) {
|
||||
public InputGetUserInfo(String userId, String name, String mobile) {
|
||||
this.userId = userId;
|
||||
this.name = name;
|
||||
this.mobile = mobile;
|
||||
}
|
||||
|
||||
public String getMobile() {
|
||||
|
||||
@@ -20,6 +20,10 @@ public class InputGroupBase {
|
||||
return operator;
|
||||
}
|
||||
|
||||
public void setOperator(String operator) {
|
||||
this.operator = operator;
|
||||
}
|
||||
|
||||
public List<Integer> getTo_lines() {
|
||||
return to_lines;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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 cn.wildfirechat.pojos;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OutputGroupMemberList {
|
||||
private List<PojoGroupMember> members;
|
||||
|
||||
public List<PojoGroupMember> getMembers() {
|
||||
return members;
|
||||
}
|
||||
|
||||
public void setMembers(List<PojoGroupMember> members) {
|
||||
this.members = members;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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 cn.wildfirechat.pojos;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OutputUserBlockStatusList {
|
||||
private List<InputOutputUserBlockStatus> statusList;
|
||||
|
||||
public List<InputOutputUserBlockStatus> getStatusList() {
|
||||
return statusList;
|
||||
}
|
||||
|
||||
public void setStatusList(List<InputOutputUserBlockStatus> statusList) {
|
||||
this.statusList = statusList;
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,6 @@ package cn.wildfirechat.common;
|
||||
|
||||
public interface APIPath {
|
||||
String Create_Chatroom = "/admin/chatroom/create";
|
||||
String Create_Group = "/admin/group/create";
|
||||
String Create_Robot = "/admin/robot/create";
|
||||
String Create_User = "/admin/user/create";
|
||||
|
||||
String Chatroom_Destroy = "/admin/chatroom/del";
|
||||
String Chatroom_Info = "/admin/chatroom/info";
|
||||
|
||||
@@ -14,24 +10,29 @@ public interface APIPath {
|
||||
String Sensitive_Del = "/admin/sensitive/del";
|
||||
String Sensitive_Query = "/admin/sensitive/query";
|
||||
|
||||
String Get_User_Token = "/admin/user/token";
|
||||
String User_Status = "/admin/user/status";
|
||||
String Get_User_Info = "/admin/user/info";
|
||||
String User_Status_List = "/admin/user/statuslist";
|
||||
String User_Check_Status = "/admin/user/checkstatus";
|
||||
String User_Online_Status = "/admin/user/onlinestatus";
|
||||
String Create_User = "/admin/user/create";
|
||||
String Create_Robot = "/admin/robot/create";
|
||||
String User_Get_Token = "/admin/user/get_token";
|
||||
String User_Update_Block_Status = "/admin/user/update_block_status";
|
||||
String User_Get_Info = "/admin/user/get_info";
|
||||
String User_Get_Blocked_List = "/admin/user/get_blocked_list";
|
||||
String User_Check_Block_Status = "/admin/user/check_block_status";
|
||||
String User_Get_Online_Status = "/admin/user/onlinestatus";
|
||||
|
||||
|
||||
String Friend_Status = "/admin/friend/status";
|
||||
String Friend_List = "/admin/friend/list";
|
||||
String Friend_Update_Status = "/admin/friend/status";
|
||||
String Friend_Get_List = "/admin/friend/list";
|
||||
|
||||
String Msg_Send = "/admin/message/send";
|
||||
String Msg_Recall = "/admin/message/recall";
|
||||
|
||||
String Create_Group = "/admin/group/create";
|
||||
String Group_Dismiss = "/admin/group/del";
|
||||
String Group_Transfer = "/admin/group/transfer";
|
||||
String Group_Get_Info = "/admin/group/get_info";
|
||||
String Group_Member_List = "/admin/group/member/list";
|
||||
String Group_Member_Add = "/admin/group/member/add";
|
||||
String Group_Member_Kickoff = "/admin/group/member/del";
|
||||
String Group_Owner = "/admin/group/owner";
|
||||
|
||||
|
||||
String Channel_Message_Send = "/channel/message/send";
|
||||
|
||||
@@ -68,7 +68,7 @@ public enum ErrorCode {
|
||||
|
||||
public static ErrorCode fromCode(int code) {
|
||||
for (ErrorCode errorCode : ErrorCode.values()) {
|
||||
if(errorCode.code == code) {
|
||||
if(errorCode.code == (code&0xff)) {
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +97,12 @@
|
||||
<destName>sdk-${project.version}.jar</destName>
|
||||
</file>
|
||||
|
||||
<file>
|
||||
<source>../sdk/sdk_readme.txt</source>
|
||||
<outputDirectory>server_sdk/</outputDirectory>
|
||||
<destName>sdk_readme.txt</destName>
|
||||
</file>
|
||||
|
||||
<file>
|
||||
<source>../common/target/common-${project.version}.jar</source>
|
||||
<outputDirectory>server_sdk/</outputDirectory>
|
||||
|
||||
@@ -63,9 +63,11 @@ media.server.use_qiniu 0
|
||||
#Media_Type_FAVORITE = 6
|
||||
|
||||
# qiniu media server configuration
|
||||
## 上传地址,不同的区域,上传地址也不同,请注意现在正确的地址
|
||||
qiniu.server_url http://up.qbox.me
|
||||
qiniu.access_key tU3vdBK5BL5j4N7jI5N5uZgq_HQDo170w5C9Amnn
|
||||
qiniu.secret_key YfQIJdgp5YGhwEw14vGpaD2HJZsuJldWtqens7i5
|
||||
## bucket名字及Domain
|
||||
qiniu.bucket_general_name media
|
||||
qiniu.bucket_general_domain http://cdn.wildfirechat.cn
|
||||
qiniu.bucket_image_name media
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
SDK使用说明:
|
||||
1. 把common.jar和sdk.jar 放到lib目录下(如没有需要手动建)。
|
||||
2. 添加下属依赖,注意本地jar包的路径。
|
||||
3. 修改build plugin,把common和sdk打包进去。
|
||||
4. 使用方法请查看sdk.jar/cn.wildfirechat.sdk/Main.class(没有混淆,可以看到源码)
|
||||
|
||||
<!--# 需要添加如下依赖-->
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-httpclient</groupId>
|
||||
<artifactId>commons-httpclient</artifactId>
|
||||
<version>3.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>1.11</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java</artifactId>
|
||||
<version>2.5.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.wildfirechat</groupId>
|
||||
<artifactId>sdk</artifactId>
|
||||
<version>0.20</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/src/lib/sdk-0.20.jar</systemPath>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.wildfirechat</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>0.20</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/src/lib/common-0.20.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<!--# 由于添加了本地jar包,需要打包时把sdk和common打进去,下面是springboot项目添加includeSystemScope部分,其它类型项目请百度。 -->
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<includeSystemScope>true</includeSystemScope>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
@@ -1,11 +1,19 @@
|
||||
package cn.wildfirechat.sdk;
|
||||
|
||||
import cn.wildfirechat.common.APIPath;
|
||||
import cn.wildfirechat.pojos.*;
|
||||
import cn.wildfirechat.sdk.model.*;
|
||||
import cn.wildfirechat.sdk.utilities.AdminHttpUtils;
|
||||
import cn.wildfirechat.sdk.utilities.ChannelHttpUtils;
|
||||
import cn.wildfirechat.sdk.utilities.RobotHttpUtils;
|
||||
|
||||
public class ChatConfig {
|
||||
public static void init(String url, String secret) {
|
||||
HttpUtils.init(url, secret);
|
||||
public static void initAdmin(String url, String secret) {
|
||||
AdminHttpUtils.init(url, secret);
|
||||
}
|
||||
|
||||
public static void initRobot(String url, String robotId, String secret) {
|
||||
RobotHttpUtils.init(url, robotId, secret);
|
||||
}
|
||||
|
||||
public static void initChannel(String url, String channelId, String secret) {
|
||||
ChannelHttpUtils.init(url, channelId, secret);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
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 ChatroomAdmin {
|
||||
public static IMResult<OutputCreateChatroom> createChatroom(InputCreateChatroom input) throws Exception {
|
||||
String path = APIPath.Create_Chatroom;
|
||||
return AdminHttpUtils.httpJsonPost(path, input, OutputCreateChatroom.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> destroyChatroom(String chatroomId) throws Exception {
|
||||
String path = APIPath.Chatroom_Destroy;
|
||||
InputDestoryChatroom input = new InputDestoryChatroom();
|
||||
input.setChatroomId(chatroomId);
|
||||
return AdminHttpUtils.httpJsonPost(path, input, Void.class);
|
||||
}
|
||||
|
||||
public static IMResult<OutputGetChatroomInfo> getChatroomInfo(String chatroomId) throws Exception {
|
||||
String path = APIPath.Chatroom_Info;
|
||||
InputGetChatroomInfo input = new InputGetChatroomInfo(chatroomId);
|
||||
return AdminHttpUtils.httpJsonPost(path, input, OutputGetChatroomInfo.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
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 FriendAdmin {
|
||||
public static IMResult<Void> updateFriendStatus(String userId, String targetId, int status) throws Exception {
|
||||
String path = APIPath.Friend_Update_Status;
|
||||
InputFriendRequest input = new InputFriendRequest();
|
||||
input.setUserId(userId);
|
||||
input.setFriendUid(targetId);
|
||||
input.setStatus(status);
|
||||
return AdminHttpUtils.httpJsonPost(path, input, Void.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> getFriendStatusList(String userId, int status) throws Exception {
|
||||
String path = APIPath.Friend_Get_List;
|
||||
InputGetFriendList input = new InputGetFriendList();
|
||||
input.setUserId(userId);
|
||||
input.setStatus(0);
|
||||
return AdminHttpUtils.httpJsonPost(path, input, Void.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GroupAdmin {
|
||||
public static IMResult<OutputCreateGroupResult> createGroup(String operator, PojoGroupInfo group_info, List<PojoGroupMember> members, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
String path = APIPath.Create_Group;
|
||||
PojoGroup pojoGroup = new PojoGroup();
|
||||
pojoGroup.setGroup_info(group_info);
|
||||
pojoGroup.setMembers(members);
|
||||
InputCreateGroup createGroup = new InputCreateGroup();
|
||||
createGroup.setGroup(pojoGroup);
|
||||
createGroup.setOperator(operator);
|
||||
createGroup.setTo_lines(to_lines);
|
||||
createGroup.setNotify_message(notify_message);
|
||||
|
||||
return AdminHttpUtils.httpJsonPost(path, createGroup, OutputCreateGroupResult.class);
|
||||
}
|
||||
|
||||
public static IMResult<PojoGroupInfo> getGroupInfo(String groupId) throws Exception {
|
||||
String path = APIPath.Group_Get_Info;
|
||||
InputGetGroup input = new InputGetGroup();
|
||||
input.setGroupId(groupId);
|
||||
|
||||
return AdminHttpUtils.httpJsonPost(path, input, PojoGroupInfo.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> dismissGroup(String operator, String groupId, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
String path = APIPath.Group_Dismiss;
|
||||
InputDismissGroup dismissGroup = new InputDismissGroup();
|
||||
dismissGroup.setOperator(operator);
|
||||
dismissGroup.setGroup_id(groupId);
|
||||
dismissGroup.setTo_lines(to_lines);
|
||||
dismissGroup.setNotify_message(notify_message);
|
||||
return AdminHttpUtils.httpJsonPost(path, dismissGroup, Void.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> transferGroup(String operator, String groupId, String newOwner, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
String path = APIPath.Group_Transfer;
|
||||
InputTransferGroup transferGroup = new InputTransferGroup();
|
||||
transferGroup.setGroup_id(groupId);
|
||||
transferGroup.setNew_owner(newOwner);
|
||||
transferGroup.setOperator(operator);
|
||||
transferGroup.setTo_lines(to_lines);
|
||||
transferGroup.setNotify_message(notify_message);
|
||||
return AdminHttpUtils.httpJsonPost(path, transferGroup, Void.class);
|
||||
}
|
||||
|
||||
|
||||
public static IMResult<OutputGroupMemberList> getGroupMembers(String groupId) throws Exception {
|
||||
String path = APIPath.Group_Member_List;
|
||||
InputGetGroup input = new InputGetGroup();
|
||||
input.setGroupId(groupId);
|
||||
return AdminHttpUtils.httpJsonPost(path, input, OutputGroupMemberList.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> addGroupMembers(String operator, String groupId, List<String> groupMemberIds, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
String path = APIPath.Group_Member_Add;
|
||||
InputAddGroupMember addGroupMember = new InputAddGroupMember();
|
||||
addGroupMember.setGroup_id(groupId);
|
||||
List<PojoGroupMember> members = new ArrayList<>();
|
||||
for (String mid : groupMemberIds) {
|
||||
PojoGroupMember m = new PojoGroupMember();
|
||||
m.setMember_id(mid);
|
||||
members.add(m);
|
||||
}
|
||||
addGroupMember.setMembers(members);
|
||||
addGroupMember.setOperator(operator);
|
||||
addGroupMember.setTo_lines(to_lines);
|
||||
addGroupMember.setNotify_message(notify_message);
|
||||
return AdminHttpUtils.httpJsonPost(path, addGroupMember, Void.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> kickoffGroupMembers(String operator, String groupId, List<String> groupMemberIds, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
String path = APIPath.Group_Member_Kickoff;
|
||||
InputKickoffGroupMember kickoffGroupMember = new InputKickoffGroupMember();
|
||||
kickoffGroupMember.setGroup_id(groupId);
|
||||
kickoffGroupMember.setMembers(groupMemberIds);
|
||||
kickoffGroupMember.setOperator(operator);
|
||||
kickoffGroupMember.setTo_lines(to_lines);
|
||||
kickoffGroupMember.setNotify_message(notify_message);
|
||||
return AdminHttpUtils.httpJsonPost(path, kickoffGroupMember, Void.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,296 @@
|
||||
package cn.wildfirechat.sdk;
|
||||
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.pojos.*;
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import cn.wildfirechat.sdk.model.IMResult;
|
||||
import cn.wildfirechat.sdk.utilities.AdminHttpUtils;
|
||||
import cn.wildfirechat.sdk.utilities.RobotHttpUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) throws Exception {
|
||||
//初始化服务API
|
||||
AdminHttpUtils.init("http://localhost:18080", "123456");
|
||||
|
||||
//***********************************************
|
||||
//**** 用户相关的API
|
||||
//***********************************************
|
||||
InputOutputUserInfo userInfo = new InputOutputUserInfo();
|
||||
userInfo.setUserId("userId1");
|
||||
userInfo.setName("user1");
|
||||
userInfo.setMobile("13900000000");
|
||||
userInfo.setDisplayName("user 1");
|
||||
|
||||
IMResult<OutputCreateUser> resultCreateUser = UserAdmin.createUser(userInfo);
|
||||
if (resultCreateUser != null && resultCreateUser.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("Create user " + resultCreateUser.getResult().getName() + " success");
|
||||
} else {
|
||||
System.out.println("Create user failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
InputCreateRobot createRobot = new InputCreateRobot();
|
||||
createRobot.setUserId("robot1");
|
||||
createRobot.setName("robot1");
|
||||
createRobot.setDisplayName("机器人");
|
||||
createRobot.setSecret("123456");
|
||||
createRobot.setCallback("http://127.0.0.1:8883/robot/recvmsg");
|
||||
IMResult<OutputCreateRobot> resultCreateRobot = UserAdmin.createRobot(createRobot);
|
||||
if (resultCreateRobot != null && resultCreateRobot.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("Create robot " + resultCreateRobot.getResult().getUserId() + " success");
|
||||
} else {
|
||||
System.out.println("Create robot failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<InputOutputUserInfo> resultGetUserInfo1 = UserAdmin.getUserByName(userInfo.getName());
|
||||
if (resultGetUserInfo1 != null && resultGetUserInfo1.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
if (userInfo.getUserId().equals(resultGetUserInfo1.getResult().getUserId())
|
||||
&& userInfo.getName().equals(resultGetUserInfo1.getResult().getName())
|
||||
&& userInfo.getMobile().equals(resultGetUserInfo1.getResult().getMobile())
|
||||
&& userInfo.getDisplayName().equals(resultGetUserInfo1.getResult().getDisplayName())) {
|
||||
System.out.println("get user info success");
|
||||
} else {
|
||||
System.out.println("get user info by name failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
} else {
|
||||
System.out.println("get user info by name failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<InputOutputUserInfo> resultGetUserInfo2 = UserAdmin.getUserByMobile(userInfo.getMobile());
|
||||
if (resultGetUserInfo2 != null && resultGetUserInfo2.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
if (userInfo.getUserId().equals(resultGetUserInfo2.getResult().getUserId())
|
||||
&& userInfo.getName().equals(resultGetUserInfo2.getResult().getName())
|
||||
&& userInfo.getMobile().equals(resultGetUserInfo2.getResult().getMobile())
|
||||
&& userInfo.getDisplayName().equals(resultGetUserInfo2.getResult().getDisplayName())) {
|
||||
System.out.println("get user info success");
|
||||
} else {
|
||||
System.out.println("get user info by mobile failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
} else {
|
||||
System.out.println("get user info by mobile failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<InputOutputUserInfo> resultGetUserInfo3 = UserAdmin.getUserByUserId(userInfo.getUserId());
|
||||
if (resultGetUserInfo3 != null && resultGetUserInfo3.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
if (userInfo.getUserId().equals(resultGetUserInfo3.getResult().getUserId())
|
||||
&& userInfo.getName().equals(resultGetUserInfo3.getResult().getName())
|
||||
&& userInfo.getMobile().equals(resultGetUserInfo3.getResult().getMobile())
|
||||
&& userInfo.getDisplayName().equals(resultGetUserInfo3.getResult().getDisplayName())) {
|
||||
System.out.println("get user info success");
|
||||
} else {
|
||||
System.out.println("get user info by userId failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
} else {
|
||||
System.out.println("get user info by userId failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<OutputGetIMTokenData> resultGetToken = UserAdmin.getUserToken(userInfo.getUserId(), "client111");
|
||||
if (resultGetToken != null && resultGetToken.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("get token success: " + resultGetToken.getResult().getToken());
|
||||
} else {
|
||||
System.out.println("get user token failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<Void> resultVoid =UserAdmin.updateUserBlockStatus(userInfo.getUserId(), 1);
|
||||
if (resultVoid != null && resultVoid.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("block user done");
|
||||
} else {
|
||||
System.out.println("block user failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<OutputUserStatus> resultCheckUserStatus = UserAdmin.checkUserBlockStatus(userInfo.getUserId());
|
||||
if (resultCheckUserStatus != null && resultCheckUserStatus.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
if (resultCheckUserStatus.getResult().getStatus() == 1) {
|
||||
System.out.println("check user status success");
|
||||
} else {
|
||||
System.out.println("user status not correct");
|
||||
System.exit(-1);
|
||||
}
|
||||
} else {
|
||||
System.out.println("block user failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<OutputUserBlockStatusList> resultBlockStatusList = UserAdmin.getBlockedList();
|
||||
if (resultBlockStatusList != null && resultBlockStatusList.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
boolean success = false;
|
||||
for (InputOutputUserBlockStatus blockStatus : resultBlockStatusList.getResult().getStatusList()) {
|
||||
if (blockStatus.getUserId().equals(userInfo.getUserId()) && blockStatus.getStatus() == 1) {
|
||||
System.out.println("get block list done");
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!success) {
|
||||
System.out.println("block user status is not expected");
|
||||
System.exit(-1);
|
||||
}
|
||||
} else {
|
||||
System.out.println("block user failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
|
||||
//***********************************************
|
||||
//**** 群组相关功能
|
||||
//***********************************************
|
||||
IMResult<Void> voidIMResult1 = GroupAdmin.dismissGroup("user1", "groupId1", null, null);
|
||||
|
||||
PojoGroupInfo groupInfo = new PojoGroupInfo();
|
||||
groupInfo.setTarget_id("groupId1");
|
||||
groupInfo.setOwner("user1");
|
||||
groupInfo.setName("test_group");
|
||||
groupInfo.setExtra("hello extra");
|
||||
groupInfo.setPortrait("http://portrait");
|
||||
List<PojoGroupMember> members = new ArrayList<>();
|
||||
PojoGroupMember member1 = new PojoGroupMember();
|
||||
member1.setMember_id(groupInfo.getOwner());
|
||||
members.add(member1);
|
||||
|
||||
PojoGroupMember member2 = new PojoGroupMember();
|
||||
member2.setMember_id("user2");
|
||||
members.add(member2);
|
||||
|
||||
PojoGroupMember member3 = new PojoGroupMember();
|
||||
member3.setMember_id("user3");
|
||||
members.add(member3);
|
||||
|
||||
IMResult<OutputCreateGroupResult> resultCreateGroup = GroupAdmin.createGroup(groupInfo.getOwner(), groupInfo, members, null, null);
|
||||
if (resultCreateGroup != null && resultCreateGroup.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("create group success");
|
||||
} else {
|
||||
System.out.println("create group failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<PojoGroupInfo> resultGetGroupInfo = GroupAdmin.getGroupInfo(groupInfo.getTarget_id());
|
||||
if (resultGetGroupInfo != null && resultGetGroupInfo.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
if (groupInfo.getExtra().equals(resultGetGroupInfo.getResult().getExtra())
|
||||
&& groupInfo.getName().equals(resultGetGroupInfo.getResult().getName())
|
||||
&& groupInfo.getOwner().equals(resultGetGroupInfo.getResult().getOwner())) {
|
||||
System.out.println("get group success");
|
||||
} else {
|
||||
System.out.println("group info is not expected");
|
||||
System.exit(-1);
|
||||
}
|
||||
} else {
|
||||
System.out.println("create group failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<Void> voidIMResult = GroupAdmin.transferGroup(groupInfo.getOwner(), groupInfo.getTarget_id(), "user2", null, null);
|
||||
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("transfer success");
|
||||
} else {
|
||||
System.out.println("create group failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
resultGetGroupInfo = GroupAdmin.getGroupInfo(groupInfo.getTarget_id());
|
||||
if (resultGetGroupInfo != null && resultGetGroupInfo.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
if ("user2".equals(resultGetGroupInfo.getResult().getOwner())) {
|
||||
groupInfo.setOwner("user2");
|
||||
} else {
|
||||
System.out.println("group info is not expected");
|
||||
System.exit(-1);
|
||||
}
|
||||
} else {
|
||||
System.out.println("create group failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<OutputGroupMemberList> resultGetMembers = GroupAdmin.getGroupMembers(groupInfo.getTarget_id());
|
||||
if (resultGetMembers != null && resultGetMembers.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("get group member success");
|
||||
} else {
|
||||
System.out.println("create group failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
voidIMResult = GroupAdmin.addGroupMembers("user1", groupInfo.getTarget_id(), Arrays.asList("use4", "user5"), null, null);
|
||||
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("add group member success");
|
||||
} else {
|
||||
System.out.println("add group member failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
voidIMResult = GroupAdmin.kickoffGroupMembers("user1", groupInfo.getTarget_id(), Arrays.asList("use2", "user3"), null, null);
|
||||
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("kickoff group member success");
|
||||
} else {
|
||||
System.out.println("kickoff group member failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
//***********************************************
|
||||
//**** 消息相关功能
|
||||
//***********************************************
|
||||
Conversation conversation = new Conversation();
|
||||
conversation.setTarget("user2");
|
||||
conversation.setType(ProtoConstants.ConversationType.ConversationType_Private);
|
||||
MessagePayload payload = new MessagePayload();
|
||||
payload.setType(1);
|
||||
payload.setSearchableContent("hello world");
|
||||
|
||||
IMResult<SendMessageResult> resultSendMessage = MessageAdmin.sendMessage("user1", conversation, payload);
|
||||
if (resultSendMessage != null && resultSendMessage.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("send message success");
|
||||
} else {
|
||||
System.out.println("send message failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
|
||||
voidIMResult = MessageAdmin.recallMessage("user1", resultSendMessage.getResult().getMessageUid());
|
||||
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("recall message success");
|
||||
} else {
|
||||
System.out.println("recall message failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//初始化机器人API
|
||||
RobotHttpUtils.init("http://localhost:18080", "robot1", "123456");
|
||||
//***********************************************
|
||||
//**** 机器人API
|
||||
//***********************************************
|
||||
conversation = new Conversation();
|
||||
conversation.setTarget("user2");
|
||||
conversation.setType(ProtoConstants.ConversationType.ConversationType_Private);
|
||||
payload = new MessagePayload();
|
||||
payload.setType(1);
|
||||
payload.setSearchableContent("hello world");
|
||||
|
||||
IMResult<SendMessageResult> resultRobotSendMessage = RobotService.sendMessage("robot1", conversation, payload);
|
||||
if (resultRobotSendMessage != null && resultRobotSendMessage.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("robot send message success");
|
||||
} else {
|
||||
System.out.println("robot send message failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<InputOutputUserInfo> resultRobotGetUserInfo = RobotService.getUserInfo("user1");
|
||||
if (resultRobotGetUserInfo != null && resultRobotGetUserInfo.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("robot get user info success");
|
||||
} else {
|
||||
System.out.println("robot get user info by userId failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
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 MessageAdmin {
|
||||
public static IMResult<SendMessageResult> sendMessage(String sender, Conversation conversation, MessagePayload payload) throws Exception {
|
||||
String path = APIPath.Msg_Send;
|
||||
SendMessageData messageData = new SendMessageData();
|
||||
messageData.setSender(sender);
|
||||
messageData.setConv(conversation);
|
||||
messageData.setPayload(payload);
|
||||
return AdminHttpUtils.httpJsonPost(path, messageData, SendMessageResult.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> recallMessage(String operator, long messageUid) throws Exception {
|
||||
String path = APIPath.Msg_Recall;
|
||||
RecallMessageData messageData = new RecallMessageData();
|
||||
messageData.setOperator(operator);
|
||||
messageData.setMessageUid(messageUid);
|
||||
return AdminHttpUtils.httpJsonPost(path, messageData, Void.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
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;
|
||||
import cn.wildfirechat.sdk.utilities.RobotHttpUtils;
|
||||
|
||||
public class RobotService {
|
||||
public static IMResult<SendMessageResult> sendMessage(String sender, Conversation conversation, MessagePayload payload) throws Exception {
|
||||
String path = APIPath.Robot_Message_Send;
|
||||
SendMessageData messageData = new SendMessageData();
|
||||
messageData.setSender(sender);
|
||||
messageData.setConv(conversation);
|
||||
messageData.setPayload(payload);
|
||||
return RobotHttpUtils.httpJsonPost(path, messageData, SendMessageResult.class);
|
||||
}
|
||||
|
||||
public static IMResult<InputOutputUserInfo> getUserInfo(String userId) throws Exception {
|
||||
String path = APIPath.Robot_User_Info;
|
||||
InputGetUserInfo getUserInfo = new InputGetUserInfo(userId, null, null);
|
||||
return RobotHttpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
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;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SensitiveAdmin {
|
||||
public static IMResult<Void> addSensitives(List<String> sensitives) throws Exception {
|
||||
String path = APIPath.Sensitive_Add;
|
||||
InputOutputSensitiveWords input = new InputOutputSensitiveWords();
|
||||
input.setWords(sensitives);
|
||||
return AdminHttpUtils.httpJsonPost(path, input, Void.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> removeSensitives(List<String> sensitives) throws Exception {
|
||||
String path = APIPath.Sensitive_Del;
|
||||
InputOutputSensitiveWords input = new InputOutputSensitiveWords();
|
||||
input.setWords(sensitives);
|
||||
return AdminHttpUtils.httpJsonPost(path, input, Void.class);
|
||||
}
|
||||
|
||||
public static IMResult<InputOutputSensitiveWords> getSensitives(List<String> sensitives) throws Exception {
|
||||
String path = APIPath.Sensitive_Query;
|
||||
return AdminHttpUtils.httpJsonPost(path, null, InputOutputSensitiveWords.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,22 +3,68 @@ 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 UserAdmin {
|
||||
public static IMResult<InputOutputUserInfo> getUserByName(String mobile) throws Exception {
|
||||
String path = APIPath.Get_User_Info;
|
||||
InputGetUserInfo getUserInfo = new InputGetUserInfo(null, mobile);
|
||||
return HttpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
|
||||
public static IMResult<InputOutputUserInfo> getUserByName(String name) throws Exception {
|
||||
String path = APIPath.User_Get_Info;
|
||||
InputGetUserInfo getUserInfo = new InputGetUserInfo(null, name, null);
|
||||
return AdminHttpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
|
||||
}
|
||||
|
||||
public static IMResult<InputOutputUserInfo> getUserByUserId(String userId) throws Exception {
|
||||
String path = APIPath.User_Get_Info;
|
||||
InputGetUserInfo getUserInfo = new InputGetUserInfo(userId, null, null);
|
||||
return AdminHttpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
|
||||
}
|
||||
|
||||
public static IMResult<InputOutputUserInfo> getUserByMobile(String mobile) throws Exception {
|
||||
String path = APIPath.User_Get_Info;
|
||||
InputGetUserInfo getUserInfo = new InputGetUserInfo(null, null, mobile);
|
||||
return AdminHttpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
|
||||
}
|
||||
|
||||
public static IMResult<OutputCreateUser> createUser(InputOutputUserInfo user) throws Exception {
|
||||
String path = APIPath.Create_User;
|
||||
return HttpUtils.httpJsonPost(path, user, OutputCreateUser.class);
|
||||
return AdminHttpUtils.httpJsonPost(path, user, OutputCreateUser.class);
|
||||
}
|
||||
|
||||
public static IMResult<OutputCreateRobot> createRobot(InputCreateRobot robot) throws Exception {
|
||||
String path = APIPath.Create_Robot;
|
||||
return AdminHttpUtils.httpJsonPost(path, robot, OutputCreateRobot.class);
|
||||
}
|
||||
|
||||
public static IMResult<OutputGetIMTokenData> getUserToken(String userId, String clientId) throws Exception {
|
||||
String path = APIPath.Get_User_Token;
|
||||
String path = APIPath.User_Get_Token;
|
||||
InputGetToken getToken = new InputGetToken(userId, clientId);
|
||||
return HttpUtils.httpJsonPost(path, getToken, OutputGetIMTokenData.class);
|
||||
return AdminHttpUtils.httpJsonPost(path, getToken, OutputGetIMTokenData.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> updateUserBlockStatus(String userId, int block) throws Exception {
|
||||
String path = APIPath.User_Update_Block_Status;
|
||||
InputOutputUserBlockStatus blockStatus = new InputOutputUserBlockStatus(userId, block);
|
||||
return AdminHttpUtils.httpJsonPost(path, blockStatus, Void.class);
|
||||
}
|
||||
|
||||
public static IMResult<OutputUserStatus> checkUserBlockStatus(String userId) throws Exception {
|
||||
String path = APIPath.User_Check_Block_Status;
|
||||
InputGetUserInfo getUserInfo = new InputGetUserInfo(userId, null, null);
|
||||
return AdminHttpUtils.httpJsonPost(path, getUserInfo, OutputUserStatus.class);
|
||||
}
|
||||
|
||||
public static IMResult<OutputUserBlockStatusList> getBlockedList() throws Exception {
|
||||
String path = APIPath.User_Get_Blocked_List;
|
||||
return AdminHttpUtils.httpJsonPost(path, null, OutputUserBlockStatusList.class);
|
||||
}
|
||||
|
||||
//not implement
|
||||
// public static IMResult<OutputUserBlockStatusList> getUserOnlineStatus(String userId) throws Exception {
|
||||
// String path = APIPath.User_Get_Online_Status;
|
||||
// InputGetUserInfo inputGetUserInfo = new InputGetUserInfo(userId, null);
|
||||
// return AdminHttpUtils.httpJsonPost(path, null, OutputUserBlockStatusList.class);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
package cn.wildfirechat.sdk.model;
|
||||
|
||||
public class SendMessageResult {
|
||||
private long messageUid;
|
||||
private long timestamp;
|
||||
|
||||
public SendMessageResult() {
|
||||
}
|
||||
|
||||
public SendMessageResult(long messageUid, long timestamp) {
|
||||
this.messageUid = messageUid;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public long getMessageUid() {
|
||||
return messageUid;
|
||||
}
|
||||
|
||||
public void setMessageUid(long messageUid) {
|
||||
this.messageUid = messageUid;
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
}
|
||||
+9
-6
@@ -1,4 +1,4 @@
|
||||
package cn.wildfirechat.sdk;
|
||||
package cn.wildfirechat.sdk.utilities;
|
||||
|
||||
import cn.wildfirechat.sdk.model.IMResult;
|
||||
import com.google.gson.Gson;
|
||||
@@ -19,18 +19,18 @@ import java.lang.reflect.Type;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
|
||||
public class HttpUtils {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(HttpUtils.class);
|
||||
public class AdminHttpUtils {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AdminHttpUtils.class);
|
||||
|
||||
private static String adminUrl;
|
||||
private static String adminSecret;
|
||||
|
||||
static void init(String url, String secret) {
|
||||
public static void init(String url, String secret) {
|
||||
adminUrl = url;
|
||||
adminSecret = secret;
|
||||
}
|
||||
|
||||
static <T> IMResult<T> httpJsonPost(String path, Object object, Class<T> clazz) throws Exception{
|
||||
public static <T> IMResult<T> httpJsonPost(String path, Object object, Class<T> clazz) throws Exception{
|
||||
if (isNullOrEmpty(adminUrl) || isNullOrEmpty(path)) {
|
||||
LOG.error("Not init IM SDK correctly. Do you forget init it?");
|
||||
throw new Exception("SDK url or secret lack!");
|
||||
@@ -54,7 +54,10 @@ public class HttpUtils {
|
||||
post.setHeader("timestamp", "" + timestamp);
|
||||
post.setHeader("sign", sign);
|
||||
|
||||
String jsonStr = new Gson().toJson(object);
|
||||
String jsonStr = "";
|
||||
if (object != null) {
|
||||
jsonStr = new Gson().toJson(object);
|
||||
}
|
||||
LOG.info("http request content: {}", jsonStr);
|
||||
|
||||
StringEntity entity = new StringEntity(jsonStr, Charset.forName("UTF-8"));
|
||||
@@ -0,0 +1,114 @@
|
||||
package cn.wildfirechat.sdk.utilities;
|
||||
|
||||
import cn.wildfirechat.sdk.model.IMResult;
|
||||
import com.google.gson.Gson;
|
||||
import ikidou.reflect.TypeBuilder;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
|
||||
public class ChannelHttpUtils {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ChannelHttpUtils.class);
|
||||
|
||||
private static String url;
|
||||
private static String channelId;
|
||||
private static String channelSecret;
|
||||
|
||||
public static void init(String url, String channelId, String secret) {
|
||||
ChannelHttpUtils.url = url;
|
||||
ChannelHttpUtils.channelId = channelId;
|
||||
ChannelHttpUtils.channelSecret = secret;
|
||||
}
|
||||
|
||||
public static <T> IMResult<T> httpJsonPost(String path, Object object, Class<T> clazz) throws Exception{
|
||||
if (isNullOrEmpty(url) || isNullOrEmpty(path)) {
|
||||
LOG.error("Not init IM SDK correctly. Do you forget init it?");
|
||||
throw new Exception("SDK url or secret lack!");
|
||||
}
|
||||
|
||||
String url = ChannelHttpUtils.url + path;
|
||||
HttpPost post = null;
|
||||
try {
|
||||
HttpClient httpClient = HttpClientBuilder.create().build();
|
||||
|
||||
int nonce = (int)(Math.random() * 100000 + 3);
|
||||
long timestamp = System.currentTimeMillis();
|
||||
String str = nonce + "|" + channelSecret + "|" + timestamp;
|
||||
String sign = DigestUtils.sha1Hex(str);
|
||||
|
||||
|
||||
post = new HttpPost(url);
|
||||
post.setHeader("Content-type", "application/json; charset=utf-8");
|
||||
post.setHeader("Connection", "Keep-Alive");
|
||||
post.setHeader("nonce", nonce + "");
|
||||
post.setHeader("timestamp", "" + timestamp);
|
||||
post.setHeader("sign", sign);
|
||||
|
||||
String jsonStr = null;
|
||||
if (object != null) {
|
||||
jsonStr = new Gson().toJson(object);
|
||||
}
|
||||
LOG.info("http request content: {}", jsonStr);
|
||||
|
||||
StringEntity entity = new StringEntity(jsonStr, Charset.forName("UTF-8"));
|
||||
entity.setContentEncoding("UTF-8");
|
||||
entity.setContentType("application/json");
|
||||
post.setEntity(entity);
|
||||
HttpResponse response = httpClient.execute(post);
|
||||
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if(statusCode != HttpStatus.SC_OK){
|
||||
LOG.info("Request error: "+statusCode);
|
||||
throw new Exception("Http request error with code:" + statusCode);
|
||||
}else{
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity()
|
||||
.getContent(),"utf-8"));
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String line;
|
||||
String NL = System.getProperty("line.separator");
|
||||
while ((line = in.readLine()) != null) {
|
||||
sb.append(line + NL);
|
||||
}
|
||||
|
||||
in.close();
|
||||
|
||||
String content = sb.toString();
|
||||
LOG.info("http request response content: {}", content);
|
||||
|
||||
return fromJsonObject(content, clazz);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}finally{
|
||||
if(post != null){
|
||||
post.releaseConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> IMResult<T> fromJsonObject(String content, Class<T> clazz) {
|
||||
Type type = TypeBuilder
|
||||
.newInstance(IMResult.class)
|
||||
.addTypeParam(clazz)
|
||||
.build();
|
||||
return new Gson().fromJson(content, type);
|
||||
}
|
||||
|
||||
private static boolean isNullOrEmpty(String str) {
|
||||
return str == null || str.isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package cn.wildfirechat.sdk.utilities;
|
||||
|
||||
import cn.wildfirechat.sdk.model.IMResult;
|
||||
import com.google.gson.Gson;
|
||||
import ikidou.reflect.TypeBuilder;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
|
||||
public class RobotHttpUtils {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RobotHttpUtils.class);
|
||||
|
||||
private static String url;
|
||||
private static String robotId;
|
||||
private static String robotSecret;
|
||||
|
||||
public static void init(String url, String robotId, String secret) {
|
||||
RobotHttpUtils.url = url;
|
||||
RobotHttpUtils.robotId = robotId;
|
||||
RobotHttpUtils.robotSecret = secret;
|
||||
}
|
||||
|
||||
public static <T> IMResult<T> httpJsonPost(String path, Object object, Class<T> clazz) throws Exception{
|
||||
if (isNullOrEmpty(url) || isNullOrEmpty(path)) {
|
||||
LOG.error("Not init IM SDK correctly. Do you forget init it?");
|
||||
throw new Exception("SDK url or secret lack!");
|
||||
}
|
||||
|
||||
String url = RobotHttpUtils.url + path;
|
||||
HttpPost post = null;
|
||||
try {
|
||||
HttpClient httpClient = HttpClientBuilder.create().build();
|
||||
|
||||
int nonce = (int)(Math.random() * 100000 + 3);
|
||||
long timestamp = System.currentTimeMillis();
|
||||
String str = nonce + "|" + robotSecret + "|" + timestamp;
|
||||
String sign = DigestUtils.sha1Hex(str);
|
||||
|
||||
|
||||
post = new HttpPost(url);
|
||||
post.setHeader("Content-type", "application/json; charset=utf-8");
|
||||
post.setHeader("Connection", "Keep-Alive");
|
||||
post.setHeader("nonce", nonce + "");
|
||||
post.setHeader("timestamp", "" + timestamp);
|
||||
post.setHeader("rid", robotId);
|
||||
post.setHeader("sign", sign);
|
||||
|
||||
String jsonStr = null;
|
||||
if (object != null) {
|
||||
jsonStr = new Gson().toJson(object);
|
||||
}
|
||||
LOG.info("http request content: {}", jsonStr);
|
||||
|
||||
StringEntity entity = new StringEntity(jsonStr, Charset.forName("UTF-8"));
|
||||
entity.setContentEncoding("UTF-8");
|
||||
entity.setContentType("application/json");
|
||||
post.setEntity(entity);
|
||||
HttpResponse response = httpClient.execute(post);
|
||||
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if(statusCode != HttpStatus.SC_OK){
|
||||
LOG.info("Request error: "+statusCode);
|
||||
throw new Exception("Http request error with code:" + statusCode);
|
||||
}else{
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity()
|
||||
.getContent(),"utf-8"));
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String line;
|
||||
String NL = System.getProperty("line.separator");
|
||||
while ((line = in.readLine()) != null) {
|
||||
sb.append(line + NL);
|
||||
}
|
||||
|
||||
in.close();
|
||||
|
||||
String content = sb.toString();
|
||||
LOG.info("http request response content: {}", content);
|
||||
|
||||
return fromJsonObject(content, clazz);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}finally{
|
||||
if(post != null){
|
||||
post.releaseConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> IMResult<T> fromJsonObject(String content, Class<T> clazz) {
|
||||
Type type = TypeBuilder
|
||||
.newInstance(IMResult.class)
|
||||
.addTypeParam(clazz)
|
||||
.build();
|
||||
return new Gson().fromJson(content, type);
|
||||
}
|
||||
|
||||
private static boolean isNullOrEmpty(String str) {
|
||||
return str == null || str.isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user