SDK支持多个机器人账户
This commit is contained in:
@@ -9,7 +9,7 @@ import java.util.List;
|
||||
|
||||
//仅专业版支持,社区版不支持
|
||||
public class ChannelServiceApi {
|
||||
private ChannelHttpUtils httpUtils;
|
||||
private final ChannelHttpUtils httpUtils;
|
||||
|
||||
public ChannelServiceApi(String imurl, String channelId, String secret) {
|
||||
httpUtils = new ChannelHttpUtils(imurl, channelId, secret);
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package cn.wildfirechat.sdk;
|
||||
|
||||
import cn.wildfirechat.sdk.utilities.AdminHttpUtils;
|
||||
import cn.wildfirechat.sdk.utilities.ChannelHttpUtils;
|
||||
import cn.wildfirechat.sdk.utilities.RobotHttpUtils;
|
||||
|
||||
public class ChatConfig {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -852,13 +852,14 @@ public class Main {
|
||||
static void testRobot() throws Exception {
|
||||
//初始化机器人API,注意端口是80,不是18080
|
||||
String robotId = "robot1";
|
||||
RobotHttpUtils.init("http://localhost", robotId, "123456");
|
||||
|
||||
RobotService robotService = new RobotService("http://localhost", robotId, "123456");
|
||||
|
||||
//***********************************************
|
||||
//**** 机器人API
|
||||
//***********************************************
|
||||
|
||||
IMResult<InputOutputUserInfo> userInfoIMResult = RobotService.getProfile(robotId);
|
||||
IMResult<InputOutputUserInfo> userInfoIMResult = robotService.getProfile(robotId);
|
||||
if(userInfoIMResult != null && userInfoIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("get profile success");
|
||||
} else {
|
||||
@@ -867,14 +868,14 @@ public class Main {
|
||||
}
|
||||
|
||||
String displayName = "testrobot"+System.currentTimeMillis();
|
||||
IMResult<Void> voidIMResult1 = RobotService.updateProfile(Modify_DisplayName, displayName);
|
||||
IMResult<Void> voidIMResult1 = robotService.updateProfile(Modify_DisplayName, displayName);
|
||||
if(voidIMResult1 != null && voidIMResult1.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("modify profile success");
|
||||
} else {
|
||||
System.out.println("modify profile failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
userInfoIMResult = RobotService.getProfile(robotId);
|
||||
userInfoIMResult = robotService.getProfile(robotId);
|
||||
if(userInfoIMResult != null && userInfoIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && displayName.equals(userInfoIMResult.getResult().getDisplayName())) {
|
||||
System.out.println("get profile success");
|
||||
} else {
|
||||
@@ -883,7 +884,7 @@ public class Main {
|
||||
}
|
||||
|
||||
String robotCallback = "http://hellow123";
|
||||
voidIMResult1 = RobotService.setCallback(robotCallback);
|
||||
voidIMResult1 = robotService.setCallback(robotCallback);
|
||||
if(voidIMResult1 != null && voidIMResult1.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("set callback success");
|
||||
} else {
|
||||
@@ -891,7 +892,7 @@ public class Main {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<RobotCallbackPojo> callbackPojoIMResult = RobotService.getCallback();
|
||||
IMResult<RobotCallbackPojo> callbackPojoIMResult = robotService.getCallback();
|
||||
if(callbackPojoIMResult != null && callbackPojoIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && robotCallback.equals(callbackPojoIMResult.getResult().getUrl())) {
|
||||
System.out.println("get callback success");
|
||||
} else {
|
||||
@@ -899,7 +900,7 @@ public class Main {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
voidIMResult1 = RobotService.deleteCallback();
|
||||
voidIMResult1 = robotService.deleteCallback();
|
||||
if(voidIMResult1 != null && voidIMResult1.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("delete callback success");
|
||||
} else {
|
||||
@@ -907,7 +908,7 @@ public class Main {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
callbackPojoIMResult = RobotService.getCallback();
|
||||
callbackPojoIMResult = robotService.getCallback();
|
||||
if(callbackPojoIMResult != null && callbackPojoIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && StringUtil.isNullOrEmpty(callbackPojoIMResult.getResult().getUrl())) {
|
||||
System.out.println("get callback success");
|
||||
} else {
|
||||
@@ -922,7 +923,7 @@ public class Main {
|
||||
payload.setType(1);
|
||||
payload.setSearchableContent("hello world");
|
||||
|
||||
IMResult<SendMessageResult> resultRobotSendMessage = RobotService.sendMessage("robot1", conversation, payload);
|
||||
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 {
|
||||
@@ -930,7 +931,7 @@ public class Main {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<InputOutputUserInfo> resultRobotGetUserInfo = RobotService.getUserInfo("userId1");
|
||||
IMResult<InputOutputUserInfo> resultRobotGetUserInfo = robotService.getUserInfo("userId1");
|
||||
if (resultRobotGetUserInfo != null && resultRobotGetUserInfo.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("robot get user info success");
|
||||
} else {
|
||||
@@ -959,7 +960,7 @@ public class Main {
|
||||
member3.setMember_id("user3");
|
||||
members.add(member3);
|
||||
|
||||
IMResult<OutputCreateGroupResult> resultCreateGroup = RobotService.createGroup(groupInfo, members, null, null);
|
||||
IMResult<OutputCreateGroupResult> resultCreateGroup = robotService.createGroup(groupInfo, members, null, null);
|
||||
if (resultCreateGroup != null && resultCreateGroup.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("create group success");
|
||||
} else {
|
||||
@@ -967,7 +968,7 @@ public class Main {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<PojoGroupInfo> resultGetGroupInfo = RobotService.getGroupInfo(groupInfo.getTarget_id());
|
||||
IMResult<PojoGroupInfo> resultGetGroupInfo = robotService.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())
|
||||
@@ -982,7 +983,7 @@ public class Main {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<Void> voidIMResult = RobotService.modifyGroupInfo(groupInfo.getTarget_id(), ProtoConstants.ModifyGroupInfoType.Modify_Group_Name,"HelloWorld", null, null);
|
||||
IMResult<Void> voidIMResult = robotService.modifyGroupInfo(groupInfo.getTarget_id(), ProtoConstants.ModifyGroupInfoType.Modify_Group_Name,"HelloWorld", null, null);
|
||||
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("modify group success");
|
||||
} else {
|
||||
@@ -991,7 +992,7 @@ public class Main {
|
||||
}
|
||||
|
||||
|
||||
IMResult<OutputGroupMemberList> resultGetMembers = RobotService.getGroupMembers(groupInfo.getTarget_id());
|
||||
IMResult<OutputGroupMemberList> resultGetMembers = robotService.getGroupMembers(groupInfo.getTarget_id());
|
||||
if (resultGetMembers != null && resultGetMembers.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("get group member success");
|
||||
} else {
|
||||
@@ -1003,7 +1004,7 @@ public class Main {
|
||||
m.setMember_id("user1");
|
||||
m.setAlias("hello user1");
|
||||
|
||||
voidIMResult = RobotService.addGroupMembers(groupInfo.getTarget_id(), Arrays.asList(m), null, null);
|
||||
voidIMResult = robotService.addGroupMembers(groupInfo.getTarget_id(), Arrays.asList(m), null, null);
|
||||
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("add group member success");
|
||||
} else {
|
||||
@@ -1011,7 +1012,7 @@ public class Main {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
voidIMResult = RobotService.kickoffGroupMembers(groupInfo.getTarget_id(), Arrays.asList("user3"), null, null);
|
||||
voidIMResult = robotService.kickoffGroupMembers(groupInfo.getTarget_id(), Arrays.asList("user3"), null, null);
|
||||
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("kickoff group member success");
|
||||
} else {
|
||||
@@ -1019,7 +1020,7 @@ public class Main {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
voidIMResult = RobotService.setGroupMemberAlias(groupInfo.getTarget_id(), "user3", "test user3", null, null);
|
||||
voidIMResult = robotService.setGroupMemberAlias(groupInfo.getTarget_id(), "user3", "test user3", null, null);
|
||||
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("set group member alias success");
|
||||
} else {
|
||||
@@ -1028,7 +1029,7 @@ public class Main {
|
||||
}
|
||||
|
||||
if(commercialServer) {
|
||||
voidIMResult = RobotService.setGroupManager(groupInfo.getTarget_id(), Arrays.asList("user4", "user5"), true, null, null);
|
||||
voidIMResult = robotService.setGroupManager(groupInfo.getTarget_id(), Arrays.asList("user4", "user5"), true, null, null);
|
||||
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("set group manager success");
|
||||
} else {
|
||||
@@ -1036,7 +1037,7 @@ public class Main {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
voidIMResult = RobotService.setGroupManager(groupInfo.getTarget_id(), Arrays.asList("user4", "user5"), false, null, null);
|
||||
voidIMResult = robotService.setGroupManager(groupInfo.getTarget_id(), Arrays.asList("user4", "user5"), false, null, null);
|
||||
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("cancel group manager success");
|
||||
} else {
|
||||
@@ -1050,7 +1051,7 @@ public class Main {
|
||||
//仅专业版支持
|
||||
if (commercialServer) {
|
||||
//开启群成员禁言
|
||||
voidIMResult = RobotService.muteGroupMember(groupInfo.getTarget_id(), Arrays.asList("user5"), true, null, null);
|
||||
voidIMResult = robotService.muteGroupMember(groupInfo.getTarget_id(), Arrays.asList("user5"), true, null, null);
|
||||
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("mute group member success");
|
||||
} else {
|
||||
@@ -1058,7 +1059,7 @@ public class Main {
|
||||
System.exit(-1);
|
||||
}
|
||||
//关闭群成员禁言
|
||||
voidIMResult = RobotService.muteGroupMember(groupInfo.getTarget_id(), Arrays.asList("user5"), false, null, null);
|
||||
voidIMResult = robotService.muteGroupMember(groupInfo.getTarget_id(), Arrays.asList("user5"), false, null, null);
|
||||
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("unmute group member success");
|
||||
} else {
|
||||
@@ -1067,7 +1068,7 @@ public class Main {
|
||||
}
|
||||
|
||||
//开启群成员白名单,当群全局禁言时,白名单用户可以发言
|
||||
voidIMResult = RobotService.allowGroupMember(groupInfo.getTarget_id(), Arrays.asList("user5"), true, null, null);
|
||||
voidIMResult = robotService.allowGroupMember(groupInfo.getTarget_id(), Arrays.asList("user5"), true, null, null);
|
||||
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("allow group member success");
|
||||
} else {
|
||||
@@ -1076,7 +1077,7 @@ public class Main {
|
||||
}
|
||||
|
||||
//关闭群成员白名单
|
||||
voidIMResult = RobotService.allowGroupMember(groupInfo.getTarget_id(), Arrays.asList("user5"), false, null, null);
|
||||
voidIMResult = robotService.allowGroupMember(groupInfo.getTarget_id(), Arrays.asList("user5"), false, null, null);
|
||||
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("unallow group member success");
|
||||
} else {
|
||||
@@ -1084,7 +1085,7 @@ public class Main {
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
voidIMResult = RobotService.transferGroup(groupInfo.getTarget_id(), "user2", null, null);
|
||||
voidIMResult = robotService.transferGroup(groupInfo.getTarget_id(), "user2", null, null);
|
||||
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("transfer success");
|
||||
} else {
|
||||
@@ -1092,7 +1093,7 @@ public class Main {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
resultGetGroupInfo = RobotService.getGroupInfo(groupInfo.getTarget_id());
|
||||
resultGetGroupInfo = robotService.getGroupInfo(groupInfo.getTarget_id());
|
||||
if (resultGetGroupInfo != null && resultGetGroupInfo.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
if ("user2".equals(resultGetGroupInfo.getResult().getOwner())) {
|
||||
groupInfo.setOwner("user2");
|
||||
@@ -1105,7 +1106,7 @@ public class Main {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
voidIMResult = RobotService.quitGroup(groupInfo.getTarget_id(), null, null);
|
||||
voidIMResult = robotService.quitGroup(groupInfo.getTarget_id(), null, null);
|
||||
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("quit group success");
|
||||
} else {
|
||||
|
||||
@@ -9,64 +9,70 @@ import cn.wildfirechat.sdk.utilities.RobotHttpUtils;
|
||||
import java.util.List;
|
||||
|
||||
public class RobotService {
|
||||
public static IMResult<SendMessageResult> sendMessage(String sender, Conversation conversation, MessagePayload payload) throws Exception {
|
||||
private final RobotHttpUtils robotHttpUtils;
|
||||
|
||||
public RobotService(String url, String robotId, String robotSecret) {
|
||||
robotHttpUtils = new RobotHttpUtils(url, robotId, robotSecret);
|
||||
}
|
||||
|
||||
public 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);
|
||||
return robotHttpUtils.httpJsonPost(path, messageData, SendMessageResult.class);
|
||||
}
|
||||
|
||||
public static IMResult<InputOutputUserInfo> getUserInfo(String userId) throws Exception {
|
||||
public 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);
|
||||
return robotHttpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
|
||||
}
|
||||
|
||||
public static IMResult<InputOutputUserInfo> getUserInfoByMobile(String phone) throws Exception {
|
||||
public IMResult<InputOutputUserInfo> getUserInfoByMobile(String phone) throws Exception {
|
||||
String path = APIPath.Robot_User_Info;
|
||||
InputGetUserInfo getUserInfo = new InputGetUserInfo(null, null, phone);
|
||||
return RobotHttpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
|
||||
return robotHttpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
|
||||
}
|
||||
|
||||
public static IMResult<InputOutputUserInfo> getUserInfoByName(String userName) throws Exception {
|
||||
public IMResult<InputOutputUserInfo> getUserInfoByName(String userName) throws Exception {
|
||||
String path = APIPath.Robot_User_Info;
|
||||
InputGetUserInfo getUserInfo = new InputGetUserInfo(null, userName, null);
|
||||
return RobotHttpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
|
||||
return robotHttpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> setCallback(String url) throws Exception {
|
||||
public IMResult<Void> setCallback(String url) throws Exception {
|
||||
String path = APIPath.Robot_Set_Callback;
|
||||
RobotCallbackPojo pojo = new RobotCallbackPojo();
|
||||
pojo.setUrl(url);
|
||||
return RobotHttpUtils.httpJsonPost(path, pojo, Void.class);
|
||||
return robotHttpUtils.httpJsonPost(path, pojo, Void.class);
|
||||
}
|
||||
|
||||
public static IMResult<RobotCallbackPojo> getCallback() throws Exception {
|
||||
public IMResult<RobotCallbackPojo> getCallback() throws Exception {
|
||||
String path = APIPath.Robot_Get_Callback;
|
||||
return RobotHttpUtils.httpJsonPost(path, null, RobotCallbackPojo.class);
|
||||
return robotHttpUtils.httpJsonPost(path, null, RobotCallbackPojo.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> deleteCallback() throws Exception {
|
||||
public IMResult<Void> deleteCallback() throws Exception {
|
||||
String path = APIPath.Robot_Delete_Callback;
|
||||
return RobotHttpUtils.httpJsonPost(path, null, Void.class);
|
||||
return robotHttpUtils.httpJsonPost(path, null, Void.class);
|
||||
}
|
||||
|
||||
public static IMResult<InputOutputUserInfo> getProfile(String robotId) throws Exception {
|
||||
public IMResult<InputOutputUserInfo> getProfile(String robotId) throws Exception {
|
||||
return getUserInfo(robotId);
|
||||
}
|
||||
|
||||
/*
|
||||
type可选范围为MyInfoType,注意不能修改电话号码,如果要修改电话号码请使用adminapi进行修改
|
||||
*/
|
||||
public static IMResult<Void> updateProfile(int/*MyInfoType*/ type, String value) throws Exception {
|
||||
public IMResult<Void> updateProfile(int/*MyInfoType*/ type, String value) throws Exception {
|
||||
String path = APIPath.Robot_Update_Profile;
|
||||
IntStringPairPojo pojo = new IntStringPairPojo(type, value);
|
||||
return RobotHttpUtils.httpJsonPost(path, pojo, Void.class);
|
||||
return robotHttpUtils.httpJsonPost(path, pojo, Void.class);
|
||||
}
|
||||
|
||||
public static IMResult<OutputCreateGroupResult> createGroup(PojoGroupInfo group_info, List<PojoGroupMember> members, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
public IMResult<OutputCreateGroupResult> createGroup(PojoGroupInfo group_info, List<PojoGroupMember> members, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
String path = APIPath.Robot_Create_Group;
|
||||
PojoGroup pojoGroup = new PojoGroup();
|
||||
pojoGroup.setGroup_info(group_info);
|
||||
@@ -76,37 +82,37 @@ public class RobotService {
|
||||
createGroup.setTo_lines(to_lines);
|
||||
createGroup.setNotify_message(notify_message);
|
||||
|
||||
return RobotHttpUtils.httpJsonPost(path, createGroup, OutputCreateGroupResult.class);
|
||||
return robotHttpUtils.httpJsonPost(path, createGroup, OutputCreateGroupResult.class);
|
||||
}
|
||||
|
||||
public static IMResult<PojoGroupInfo> getGroupInfo(String groupId) throws Exception {
|
||||
public IMResult<PojoGroupInfo> getGroupInfo(String groupId) throws Exception {
|
||||
String path = APIPath.Robot_Group_Get_Info;
|
||||
InputGetGroup input = new InputGetGroup();
|
||||
input.setGroupId(groupId);
|
||||
|
||||
return RobotHttpUtils.httpJsonPost(path, input, PojoGroupInfo.class);
|
||||
return robotHttpUtils.httpJsonPost(path, input, PojoGroupInfo.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> dismissGroup(String groupId, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
public IMResult<Void> dismissGroup(String groupId, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
String path = APIPath.Robot_Group_Dismiss;
|
||||
InputDismissGroup dismissGroup = new InputDismissGroup();
|
||||
dismissGroup.setGroup_id(groupId);
|
||||
dismissGroup.setTo_lines(to_lines);
|
||||
dismissGroup.setNotify_message(notify_message);
|
||||
return RobotHttpUtils.httpJsonPost(path, dismissGroup, Void.class);
|
||||
return robotHttpUtils.httpJsonPost(path, dismissGroup, Void.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> transferGroup(String groupId, String newOwner, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
public IMResult<Void> transferGroup(String groupId, String newOwner, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
String path = APIPath.Robot_Group_Transfer;
|
||||
InputTransferGroup transferGroup = new InputTransferGroup();
|
||||
transferGroup.setGroup_id(groupId);
|
||||
transferGroup.setNew_owner(newOwner);
|
||||
transferGroup.setTo_lines(to_lines);
|
||||
transferGroup.setNotify_message(notify_message);
|
||||
return RobotHttpUtils.httpJsonPost(path, transferGroup, Void.class);
|
||||
return robotHttpUtils.httpJsonPost(path, transferGroup, Void.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> modifyGroupInfo(String groupId, /*ModifyGroupInfoType*/int type, String value, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
public IMResult<Void> modifyGroupInfo(String groupId, /*ModifyGroupInfoType*/int type, String value, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
String path = APIPath.Robot_Group_Modify_Info;
|
||||
InputModifyGroupInfo modifyGroupInfo = new InputModifyGroupInfo();
|
||||
modifyGroupInfo.setGroup_id(groupId);
|
||||
@@ -114,28 +120,28 @@ public class RobotService {
|
||||
modifyGroupInfo.setType(type);
|
||||
modifyGroupInfo.setValue(value);
|
||||
modifyGroupInfo.setNotify_message(notify_message);
|
||||
return RobotHttpUtils.httpJsonPost(path, modifyGroupInfo, Void.class);
|
||||
return robotHttpUtils.httpJsonPost(path, modifyGroupInfo, Void.class);
|
||||
}
|
||||
|
||||
|
||||
public static IMResult<OutputGroupMemberList> getGroupMembers(String groupId) throws Exception {
|
||||
public IMResult<OutputGroupMemberList> getGroupMembers(String groupId) throws Exception {
|
||||
String path = APIPath.Robot_Group_Member_List;
|
||||
InputGetGroup input = new InputGetGroup();
|
||||
input.setGroupId(groupId);
|
||||
return RobotHttpUtils.httpJsonPost(path, input, OutputGroupMemberList.class);
|
||||
return robotHttpUtils.httpJsonPost(path, input, OutputGroupMemberList.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> addGroupMembers(String groupId, List<PojoGroupMember> groupMembers, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
public IMResult<Void> addGroupMembers(String groupId, List<PojoGroupMember> groupMembers, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
String path = APIPath.Robot_Group_Member_Add;
|
||||
InputAddGroupMember addGroupMember = new InputAddGroupMember();
|
||||
addGroupMember.setGroup_id(groupId);
|
||||
addGroupMember.setMembers(groupMembers);
|
||||
addGroupMember.setTo_lines(to_lines);
|
||||
addGroupMember.setNotify_message(notify_message);
|
||||
return RobotHttpUtils.httpJsonPost(path, addGroupMember, Void.class);
|
||||
return robotHttpUtils.httpJsonPost(path, addGroupMember, Void.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> setGroupManager(String groupId, List<String> groupMemberIds, boolean isManager, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
public IMResult<Void> setGroupManager(String groupId, List<String> groupMemberIds, boolean isManager, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
String path = APIPath.Robot_Group_Set_Manager;
|
||||
InputSetGroupManager addGroupMember = new InputSetGroupManager();
|
||||
addGroupMember.setGroup_id(groupId);
|
||||
@@ -143,10 +149,10 @@ public class RobotService {
|
||||
addGroupMember.setIs_manager(isManager);
|
||||
addGroupMember.setTo_lines(to_lines);
|
||||
addGroupMember.setNotify_message(notify_message);
|
||||
return RobotHttpUtils.httpJsonPost(path, addGroupMember, Void.class);
|
||||
return robotHttpUtils.httpJsonPost(path, addGroupMember, Void.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> muteGroupMember(String groupId, List<String> groupMemberIds, boolean isMute, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
public IMResult<Void> muteGroupMember(String groupId, List<String> groupMemberIds, boolean isMute, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
String path = APIPath.Robot_Group_Mute_Member;
|
||||
InputMuteGroupMember addGroupMember = new InputMuteGroupMember();
|
||||
addGroupMember.setGroup_id(groupId);
|
||||
@@ -154,10 +160,10 @@ public class RobotService {
|
||||
addGroupMember.setIs_manager(isMute);
|
||||
addGroupMember.setTo_lines(to_lines);
|
||||
addGroupMember.setNotify_message(notify_message);
|
||||
return RobotHttpUtils.httpJsonPost(path, addGroupMember, Void.class);
|
||||
return robotHttpUtils.httpJsonPost(path, addGroupMember, Void.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> allowGroupMember(String groupId, List<String> groupMemberIds, boolean isAllow, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
public IMResult<Void> allowGroupMember(String groupId, List<String> groupMemberIds, boolean isAllow, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
String path = APIPath.Robot_Group_Allow_Member;
|
||||
InputMuteGroupMember addGroupMember = new InputMuteGroupMember();
|
||||
addGroupMember.setGroup_id(groupId);
|
||||
@@ -165,29 +171,29 @@ public class RobotService {
|
||||
addGroupMember.setIs_manager(isAllow);
|
||||
addGroupMember.setTo_lines(to_lines);
|
||||
addGroupMember.setNotify_message(notify_message);
|
||||
return RobotHttpUtils.httpJsonPost(path, addGroupMember, Void.class);
|
||||
return robotHttpUtils.httpJsonPost(path, addGroupMember, Void.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> kickoffGroupMembers(String groupId, List<String> groupMemberIds, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
public IMResult<Void> kickoffGroupMembers(String groupId, List<String> groupMemberIds, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
String path = APIPath.Robot_Group_Member_Kickoff;
|
||||
InputKickoffGroupMember kickoffGroupMember = new InputKickoffGroupMember();
|
||||
kickoffGroupMember.setGroup_id(groupId);
|
||||
kickoffGroupMember.setMembers(groupMemberIds);
|
||||
kickoffGroupMember.setTo_lines(to_lines);
|
||||
kickoffGroupMember.setNotify_message(notify_message);
|
||||
return RobotHttpUtils.httpJsonPost(path, kickoffGroupMember, Void.class);
|
||||
return robotHttpUtils.httpJsonPost(path, kickoffGroupMember, Void.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> quitGroup(String groupId, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
public IMResult<Void> quitGroup(String groupId, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
String path = APIPath.Robot_Group_Member_Quit;
|
||||
InputQuitGroup quitGroup = new InputQuitGroup();
|
||||
quitGroup.setGroup_id(groupId);
|
||||
quitGroup.setTo_lines(to_lines);
|
||||
quitGroup.setNotify_message(notify_message);
|
||||
return RobotHttpUtils.httpJsonPost(path, quitGroup, Void.class);
|
||||
return robotHttpUtils.httpJsonPost(path, quitGroup, Void.class);
|
||||
}
|
||||
|
||||
public static IMResult<Void> setGroupMemberAlias(String groupId, String memberId, String alias, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
public IMResult<Void> setGroupMemberAlias(String groupId, String memberId, String alias, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
|
||||
String path = APIPath.Robot_Group_Set_Member_Alias;
|
||||
InputSetGroupMemberAlias input = new InputSetGroupMemberAlias();
|
||||
input.setGroup_id(groupId);
|
||||
@@ -195,6 +201,6 @@ public class RobotService {
|
||||
input.setAlias(alias);
|
||||
input.setTo_lines(to_lines);
|
||||
input.setNotify_message(notify_message);
|
||||
return RobotHttpUtils.httpJsonPost(path, input, Void.class);
|
||||
return robotHttpUtils.httpJsonPost(path, input, Void.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,23 +23,24 @@ 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;
|
||||
private final String url;
|
||||
private final String robotId;
|
||||
private final String robotSecret;
|
||||
|
||||
public static void init(String url, String robotId, String secret) {
|
||||
RobotHttpUtils.url = url;
|
||||
RobotHttpUtils.robotId = robotId;
|
||||
RobotHttpUtils.robotSecret = secret;
|
||||
public RobotHttpUtils(String url, String robotId, String robotSecret) {
|
||||
this.url = url;
|
||||
this.robotId = robotId;
|
||||
this.robotSecret = robotSecret;
|
||||
}
|
||||
|
||||
public static <T> IMResult<T> httpJsonPost(String path, Object object, Class<T> clazz) throws Exception{
|
||||
|
||||
public <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;
|
||||
String url = this.url + path;
|
||||
HttpPost post = null;
|
||||
try {
|
||||
HttpClient httpClient = HttpClientBuilder.create().build();
|
||||
|
||||
Reference in New Issue
Block a user