添加机器人的朋友圈接口

This commit is contained in:
heavyrian2012
2024-11-03 10:06:10 +08:00
parent f3f08b3026
commit 1b8cf3e5f9
18 changed files with 469 additions and 14 deletions
@@ -1,6 +1,10 @@
package cn.wildfirechat.sdk;
import cn.wildfirechat.common.ErrorCode;
import cn.wildfirechat.pojos.moments.CommentPojo;
import cn.wildfirechat.pojos.moments.FeedPojo;
import cn.wildfirechat.pojos.moments.FeedsPojo;
import cn.wildfirechat.pojos.moments.MomentProfilePojo;
import cn.wildfirechat.proto.WFCMessage;
import cn.wildfirechat.sdk.messagecontent.*;
import cn.wildfirechat.pojos.*;
@@ -19,6 +23,7 @@ import static cn.wildfirechat.proto.ProtoConstants.SystemSettingType.Group_Max_M
public class Main {
private static boolean commercialServer = false;
private static boolean advanceVoip = false;
private static boolean robotMomentsEnabled = false;
//管理端口是8080
private static String AdminUrl = "http://localhost:18080";
private static String AdminSecret = "123456";
@@ -1575,8 +1580,6 @@ public class Main {
System.out.println(config);
}
//仅专业版支持
if (commercialServer) {
//开启群成员禁言
@@ -1643,6 +1646,82 @@ public class Main {
System.exit(-1);
}
//仅专业版支持,且服务器端支持朋友圈
if (robotMomentsEnabled) {
IMResult<FeedPojo> postResult = robotService.postMomentsFeed(ProtoConstants.MomentsContentType.Moments_Content_Text_Type, "hello from robot", null, null, null, null, null);
if (postResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("post moments feed success");
} else {
System.out.println("post moments feed failure:" + postResult.getErrorCode().code);
System.exit(-1);
}
IMResult<FeedsPojo> pullResult = robotService.getMomentsFeeds(0, 10, null);
if (pullResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("pull moments feeds success");
} else {
System.out.println("pull moments feeds failure:" + pullResult.getErrorCode().code);
System.exit(-1);
}
if(!pullResult.getResult().feeds.isEmpty()) {
IMResult<FeedPojo> feedResult = robotService.getMomentsFeed(pullResult.getResult().feeds.get(0).feedId);
if (feedResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("pull moments one feed success");
} else {
System.out.println("pull moments one feed failure:" + feedResult.getErrorCode().code);
System.exit(-1);
}
}
IMResult<CommentPojo> commentThumbUpResult = robotService.postMomentsComment(postResult.result.feedId, 0, ProtoConstants.MomentsCommentType.Moments_Comment_Thumbup_Type, null, null, null);
if (commentThumbUpResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("post moments thumb up success");
} else {
System.out.println("post moments thumb up failure:" + commentThumbUpResult.getErrorCode().code);
System.exit(-1);
}
IMResult<CommentPojo> commentTextResult = robotService.postMomentsComment(postResult.result.feedId, 0, ProtoConstants.MomentsCommentType.Moments_Comment_Text_Type, "comment hello", null, null);
if (commentTextResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("post moments comment text success");
} else {
System.out.println("post moments comment text failure:" + commentTextResult.getErrorCode().code);
System.exit(-1);
}
IMResult<Void> deleteCommentThumbUpResult = robotService.deleteMomentsComment(postResult.result.feedId, commentThumbUpResult.result.commentId);
if (deleteCommentThumbUpResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("delete moments thumb up success");
} else {
System.out.println("delete moments thumb up failure:" + deleteCommentThumbUpResult.getErrorCode().code);
System.exit(-1);
}
IMResult<Void> deleteCommentTextResult = robotService.deleteMomentsComment(postResult.result.feedId, commentTextResult.result.commentId);
if (deleteCommentTextResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("delete moments comment text success");
} else {
System.out.println("delete moments comment text failure:" + deleteCommentTextResult.getErrorCode().code);
System.exit(-1);
}
IMResult<Void> deleteFeedResult = robotService.deleteMomentsFeed(postResult.result.feedId);
if (deleteFeedResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("delete moments feed success");
} else {
System.out.println("delete moments feed failure:" + deleteFeedResult.getErrorCode().code);
System.exit(-1);
}
IMResult<MomentProfilePojo> profileResult = robotService.getUserMomentsProfile(robotId);
if (profileResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("get user moments profile success");
} else {
System.out.println("get user moments profile failure:" + profileResult.getErrorCode().code);
System.exit(-1);
}
}
}
//***测试频道API功能,仅专业版支持***
@@ -1,7 +1,9 @@
package cn.wildfirechat.sdk;
import cn.wildfirechat.common.APIPath;
import cn.wildfirechat.common.ErrorCode;
import cn.wildfirechat.pojos.*;
import cn.wildfirechat.pojos.moments.*;
import cn.wildfirechat.sdk.model.IMResult;
import cn.wildfirechat.sdk.utilities.RobotHttpUtils;
import org.apache.commons.codec.digest.DigestUtils;
@@ -96,7 +98,7 @@ public class RobotService {
return robotHttpUtils.httpJsonPost(path, pojo, Void.class);
}
public IMResult<OutputCreateGroupResult> createGroup(PojoGroupInfo group_info, List<PojoGroupMember> members, String member_extra, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
public IMResult<OutputCreateGroupResult> createGroup(PojoGroupInfo group_info, List<PojoGroupMember> members, String member_extra, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
String path = APIPath.Robot_Create_Group;
PojoGroup pojoGroup = new PojoGroup();
pojoGroup.setGroup_info(group_info);
@@ -118,7 +120,7 @@ public class RobotService {
return robotHttpUtils.httpJsonPost(path, input, PojoGroupInfo.class);
}
public 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);
@@ -127,7 +129,7 @@ public class RobotService {
return robotHttpUtils.httpJsonPost(path, dismissGroup, Void.class);
}
public 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);
@@ -137,7 +139,7 @@ public class RobotService {
return robotHttpUtils.httpJsonPost(path, transferGroup, Void.class);
}
public 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);
@@ -164,7 +166,7 @@ public class RobotService {
return robotHttpUtils.httpJsonPost(path, input, PojoGroupMember.class);
}
public IMResult<Void> addGroupMembers(String groupId, List<PojoGroupMember> groupMembers, String member_extra, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
public IMResult<Void> addGroupMembers(String groupId, List<PojoGroupMember> groupMembers, String member_extra, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
String path = APIPath.Robot_Group_Member_Add;
InputAddGroupMember addGroupMember = new InputAddGroupMember();
addGroupMember.setGroup_id(groupId);
@@ -175,7 +177,7 @@ public class RobotService {
return robotHttpUtils.httpJsonPost(path, addGroupMember, Void.class);
}
public 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);
@@ -186,7 +188,7 @@ public class RobotService {
return robotHttpUtils.httpJsonPost(path, addGroupMember, Void.class);
}
public 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);
@@ -197,7 +199,7 @@ public class RobotService {
return robotHttpUtils.httpJsonPost(path, addGroupMember, Void.class);
}
public 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);
@@ -208,7 +210,7 @@ public class RobotService {
return robotHttpUtils.httpJsonPost(path, addGroupMember, Void.class);
}
public 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);
@@ -218,7 +220,7 @@ public class RobotService {
return robotHttpUtils.httpJsonPost(path, kickoffGroupMember, Void.class);
}
public 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);
@@ -227,7 +229,7 @@ public class RobotService {
return robotHttpUtils.httpJsonPost(path, quitGroup, Void.class);
}
public 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);
@@ -238,7 +240,7 @@ public class RobotService {
return robotHttpUtils.httpJsonPost(path, input, Void.class);
}
public IMResult<Void> setGroupMemberExtra(String groupId, String memberId, String extra, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
public IMResult<Void> setGroupMemberExtra(String groupId, String memberId, String extra, List<Integer> to_lines, MessagePayload notify_message) throws Exception {
String path = APIPath.Robot_Group_Set_Member_Extra;
InputSetGroupMemberExtra input = new InputSetGroupMemberExtra();
input.setGroup_id(groupId);
@@ -276,4 +278,130 @@ public class RobotService {
return robotHttpUtils.httpJsonPost(path, input, String.class);
}
public IMResult<FeedPojo> postMomentsFeed(int/*MomentsContentType*/ type, String text, List<MediaEntry> medias, List<String> toUsers, List<String> excludeUsers, List<String> mentionedUsers, String extra) throws Exception {
String path = APIPath.Robot_Moments_Post_Feed;
FeedPojo feedPojo = new FeedPojo();
feedPojo.type = type;
feedPojo.text = text;
feedPojo.medias = medias;
feedPojo.to = toUsers;
feedPojo.ex = excludeUsers;
feedPojo.mu = mentionedUsers;
feedPojo.extra = extra;
IMResult<PostFeedResult> imResult = robotHttpUtils.httpJsonPost(path, feedPojo, PostFeedResult.class);
IMResult<FeedPojo> feedResult = new IMResult<>();
if(imResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
feedPojo.feedId = imResult.result.id;
feedPojo.timestamp = imResult.result.timestamp;
feedResult.setCode(ErrorCode.ERROR_CODE_SUCCESS.getCode());
feedResult.setResult(feedPojo);
} else {
feedResult.setCode(imResult.getCode());
feedResult.setMsg(imResult.getMsg());
}
return feedResult;
}
public IMResult<FeedsPojo> getMomentsFeeds(long feedId, int count, String user) throws Exception {
String path = APIPath.Robot_Moments_Pull_Feeds;
PullFeedRequestPojo requestPojo = new PullFeedRequestPojo();
requestPojo.feedId = feedId;
requestPojo.count = count;
requestPojo.user = user;
return robotHttpUtils.httpJsonPost(path, requestPojo, FeedsPojo.class);
}
public IMResult<FeedPojo> getMomentsFeed(long feedId) throws Exception {
String path = APIPath.Robot_Moments_Fetch_Feed;
PullOneFeedRequestPojo requestPojo = new PullOneFeedRequestPojo();
requestPojo.feedId = feedId;
return robotHttpUtils.httpJsonPost(path, requestPojo, FeedPojo.class);
}
public IMResult<Void> deleteMomentsFeed(long feedId) throws Exception {
String path = APIPath.Robot_Moments_Recall_Feed;
IdPojo requestPojo = new IdPojo();
requestPojo.id = feedId;
return robotHttpUtils.httpJsonPost(path, requestPojo, Void.class);
}
public IMResult<CommentPojo> postMomentsComment(long feedId, long replyId, int/*MomentsCommentType*/ type, String text, String replyTo, String extra) throws Exception {
String path = APIPath.Robot_Moments_Post_Comment;
CommentPojo commentPojo = new CommentPojo();
commentPojo.type = type;
commentPojo.text = text;
commentPojo.replyId = replyId;
commentPojo.feedId = feedId;
commentPojo.replyTo = replyTo;
commentPojo.extra = extra;
IMResult<PostFeedResult> imResult = robotHttpUtils.httpJsonPost(path, commentPojo, PostFeedResult.class);
IMResult<CommentPojo> feedResult = new IMResult<>();
if(imResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
commentPojo.commentId = imResult.result.id;
commentPojo.timestamp = imResult.result.timestamp;
feedResult.setCode(ErrorCode.ERROR_CODE_SUCCESS.getCode());
feedResult.setResult(commentPojo);
} else {
feedResult.setCode(imResult.getCode());
feedResult.setMsg(imResult.getMsg());
}
return feedResult;
}
public IMResult<Void> deleteMomentsComment(long feedId, long commentId) throws Exception {
String path = APIPath.Robot_Moments_Recall_Comment;
IdPojo requestPojo = new IdPojo();
requestPojo.id = commentId;
requestPojo.id2 = feedId;
return robotHttpUtils.httpJsonPost(path, requestPojo, Void.class);
}
public IMResult<MomentProfilePojo> getUserMomentsProfile(String userId) throws Exception {
String path = APIPath.Robot_Moments_Fetch_Profiles;
PullProfileRequestPojo requestPojo = new PullProfileRequestPojo();
requestPojo.u = userId;
return robotHttpUtils.httpJsonPost(path, requestPojo, MomentProfilePojo.class);
}
public IMResult<Void> updateMomentsBackgroundUrl(String url) throws Exception {
String path = APIPath.Robot_Moments_Update_Profiles_Value;
PushProfileValueRequestPojo requestPojo = new PushProfileValueRequestPojo();
requestPojo.t = 0;
requestPojo.v = url;
return robotHttpUtils.httpJsonPost(path, requestPojo, Void.class);
}
public IMResult<Void> updateMomentsStrangerVisibleCount(int count) throws Exception {
String path = APIPath.Robot_Moments_Update_Profiles_Value;
PushProfileValueRequestPojo requestPojo = new PushProfileValueRequestPojo();
requestPojo.t = 1;
requestPojo.i = count;
return robotHttpUtils.httpJsonPost(path, requestPojo, Void.class);
}
public IMResult<Void> updateMomentsVisibleScope(int/*MomentsVisibleScope*/ scope) throws Exception {
String path = APIPath.Robot_Moments_Update_Profiles_Value;
PushProfileValueRequestPojo requestPojo = new PushProfileValueRequestPojo();
requestPojo.t = 2;
requestPojo.i = scope;
return robotHttpUtils.httpJsonPost(path, requestPojo, Void.class);
}
public IMResult<Void> updateMomentsBlackList(List<String> addList, List<String> removeList) throws Exception {
String path = APIPath.Robot_Moments_Update_Profiles_List_Value;
PushProfileListRequestPojo requestPojo = new PushProfileListRequestPojo();
requestPojo.b = false;
requestPojo.al = addList;
requestPojo.rl = removeList;
return robotHttpUtils.httpJsonPost(path, requestPojo, Void.class);
}
public IMResult<Void> updateMomentsBlockList(List<String> addList, List<String> removeList) throws Exception {
String path = APIPath.Robot_Moments_Update_Profiles_List_Value;
PushProfileListRequestPojo requestPojo = new PushProfileListRequestPojo();
requestPojo.b = true;
requestPojo.al = addList;
requestPojo.rl = removeList;
return robotHttpUtils.httpJsonPost(path, requestPojo, Void.class);
}
}