diff --git a/src/main/java/io/github/doocs/im/core/Sns.java b/src/main/java/io/github/doocs/im/core/Sns.java index dcd222e..6d76159 100644 --- a/src/main/java/io/github/doocs/im/core/Sns.java +++ b/src/main/java/io/github/doocs/im/core/Sns.java @@ -18,6 +18,7 @@ public class Sns { * 关系链管理服务名 */ public static final String SERVICE_NAME = "sns"; + public static final String SERVICE_NAME_FOLLOW = "follow"; /** * 关系链管理相关命令字 @@ -37,6 +38,11 @@ public class Sns { public static final String GROUP_ADD_COMMAND = "group_add"; public static final String GROUP_DELETE_COMMAND = "group_delete"; public static final String GROUP_GET_COMMAND = "group_get"; + public static final String FOLLOW_ADD_COMMAND = "follow_add"; + public static final String FOLLOW_DELETE_COMMAND = "follow_delete"; + public static final String FOLLOW_GET_COMMAND = "follow_get"; + public static final String FOLLOW_CHECK_COMMAND = "follow_check"; + public static final String FOLLOW_GET_INFO_COMMAND = "follow_get_info"; private final ImClient imClient; @@ -298,4 +304,90 @@ public GroupGetResult groupGet(GroupGetRequest groupGetRequest, long random) thr String url = imClient.getUrl(SERVICE_NAME, GROUP_GET_COMMAND, random); return HttpUtil.post(url, groupGetRequest, GroupGetResult.class, imClient.getConfig()); } + + /** + * 关注用户 + * + * @param followAddRequest 关注用户请求参数 + * @return 关注用户结果 + * @throws IOException 关注用户异常 + */ + public FollowAddResult followAdd(FollowAddRequest followAddRequest) throws IOException { + String url = imClient.getUrl(SERVICE_NAME_FOLLOW, FOLLOW_ADD_COMMAND); + return HttpUtil.post(url, followAddRequest, FollowAddResult.class, imClient.getConfig()); + } + + public FollowAddResult followAdd(FollowAddRequest followAddRequest, long random) throws IOException { + String url = imClient.getUrl(SERVICE_NAME_FOLLOW, FOLLOW_ADD_COMMAND, random); + return HttpUtil.post(url, followAddRequest, FollowAddResult.class, imClient.getConfig()); + } + + /** + * 取消关注用户 + * + * @param followDeleteRequest 取消关注用户请求参数 + * @return 取消关注用户结果 + * @throws IOException 取消关注用户异常 + */ + public FollowDeleteResult followDelete(FollowDeleteRequest followDeleteRequest) throws IOException { + String url = imClient.getUrl(SERVICE_NAME_FOLLOW, FOLLOW_DELETE_COMMAND); + return HttpUtil.post(url, followDeleteRequest, FollowDeleteResult.class, imClient.getConfig()); + } + + public FollowDeleteResult followDelete(FollowDeleteRequest followDeleteRequest, long random) throws IOException { + String url = imClient.getUrl(SERVICE_NAME_FOLLOW, FOLLOW_DELETE_COMMAND, random); + return HttpUtil.post(url, followDeleteRequest, FollowDeleteResult.class, imClient.getConfig()); + } + + /** + * 拉取关注、粉丝与互关列表 + * + * @param followGetRequest 拉取关注请求参数 + * @return 拉取关注结果 + * @throws IOException 拉取关注异常 + */ + public FollowGetResult followGet(FollowGetRequest followGetRequest) throws IOException { + String url = imClient.getUrl(SERVICE_NAME_FOLLOW, FOLLOW_GET_COMMAND); + return HttpUtil.post(url, followGetRequest, FollowGetResult.class, imClient.getConfig()); + } + + public FollowGetResult followGet(FollowGetRequest followGetRequest, long random) throws IOException { + String url = imClient.getUrl(SERVICE_NAME_FOLLOW, FOLLOW_GET_COMMAND, random); + return HttpUtil.post(url, followGetRequest, FollowGetResult.class, imClient.getConfig()); + } + + /** + * 检查关注关系 + * + * @param followCheckRequest 检查关注关系请求参数 + * @return 检查关注关系结果 + * @throws IOException 检查关注关系异常 + */ + public FollowCheckResult followCheck(FollowCheckRequest followCheckRequest) throws IOException { + String url = imClient.getUrl(SERVICE_NAME_FOLLOW, FOLLOW_CHECK_COMMAND); + return HttpUtil.post(url, followCheckRequest, FollowCheckResult.class, imClient.getConfig()); + } + + public FollowCheckResult followCheck(FollowCheckRequest followCheckRequest, long random) throws IOException { + String url = imClient.getUrl(SERVICE_NAME_FOLLOW, FOLLOW_CHECK_COMMAND, random); + return HttpUtil.post(url, followCheckRequest, FollowCheckResult.class, imClient.getConfig()); + } + + /** + * 获取用户的关注、粉丝与互关数 + * + * @param followGetInfoRequest 获取用户的关注、粉丝与互关数请求参数 + * @return 获取用户的关注、粉丝与互关数结果 + * @throws IOException 拉取关注异常 + */ + public FollowGetInfoResult followGetInfo(FollowGetInfoRequest followGetInfoRequest) throws IOException { + String url = imClient.getUrl(SERVICE_NAME_FOLLOW, FOLLOW_GET_INFO_COMMAND); + return HttpUtil.post(url, followGetInfoRequest, FollowGetInfoResult.class, imClient.getConfig()); + } + + public FollowGetInfoResult followGetInfo(FollowGetInfoRequest followGetInfoRequest, long random) throws IOException { + String url = imClient.getUrl(SERVICE_NAME_FOLLOW, FOLLOW_GET_INFO_COMMAND, random); + return HttpUtil.post(url, followGetInfoRequest, FollowGetInfoResult.class, imClient.getConfig()); + } + } diff --git a/src/main/java/io/github/doocs/im/model/request/FollowAddRequest.java b/src/main/java/io/github/doocs/im/model/request/FollowAddRequest.java new file mode 100644 index 0000000..f09f446 --- /dev/null +++ b/src/main/java/io/github/doocs/im/model/request/FollowAddRequest.java @@ -0,0 +1,89 @@ +package io.github.doocs.im.model.request; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.Serializable; +import java.util.List; + +/** + *
+ * 关注用户-请求参数 + *
+ * + * @author MC.Yang + * @version V1.0 + **/ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class FollowAddRequest extends GenericRequest implements Serializable { + private static final long serialVersionUID = -4998729848603268465L; + + /** + * 发起关注操作的用户的 UserID + */ + @JsonProperty("From_Account") + private String fromAccount; + + /** + * 关注结构体对象 + */ + @JsonProperty("FollowItem") + List+ * 检查关注关系-请求参数 + *
+ * + * @author MC.Yang + * @version V1.0 + **/ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class FollowCheckRequest extends GenericRequest implements Serializable { + private static final long serialVersionUID = -1540312147327812439L; + + /** + * 请求检查该用户与 To_Account 之间的关注关系 + */ + @JsonProperty("From_Account") + private String fromAccount; + + /** + * 待检查的用户列表,单次请求的 To_Account 数不得超过100 + */ + @JsonProperty("To_Account") + private List+ * 取消关注用户-请求参数 + *
+ * + * @author MC.Yang + * @version V1.0 + **/ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class FollowDeleteRequest extends GenericRequest implements Serializable { + private static final long serialVersionUID = -6307672357208946936L; + + /** + * 发起取关操作的用户的 UserID + */ + @JsonProperty("From_Account") + private String fromAccount; + + /** + * 待取关的用户的 UserID,单次请求的 To_Account 数不得超过20 + */ + @JsonProperty("To_Account") + private List+ * 获取用户的关注、粉丝与互关数-请求参数 + *
+ * + * @author MC.Yang + * @version V1.0 + **/ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class FollowGetInfoRequest extends GenericRequest implements Serializable { + private static final long serialVersionUID = 198471997889646572L; + + /** + * 发起拉取操作的用户的 UserID + */ + @JsonProperty("From_Account") + private String fromAccount; + + /** + * 待拉取计数的用户的 UserID,单次请求的 To_Account 数不得超过20 + */ + @JsonProperty("To_Account") + private List+ * 拉取关注、粉丝与互关列表-请求参数 + *
+ * + * @author MC.Yang + * @version V1.0 + **/ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class FollowGetRequest extends GenericRequest implements Serializable { + private static final long serialVersionUID = 1259725175653532351L; + + /** + * 用户的 UserID + */ + @JsonProperty("From_Account") + private String fromAccount; + + /** + * 待拉取的类型: + * 1 - 粉丝 + * 2 - 关注 + * 3 - 互关 + */ + @JsonProperty("FollowType") + private Integer followType; + + /** + * 分页的起始位置:首页为空,续拉请求填上一页回包返回的 NextCursor 字段 + */ + @JsonProperty("StartCursor") + private String startCursor; + + /** + * 拉取的数量:默认每页返回100条数据,最多支持1000条数据 + */ + @JsonProperty("WantNum") + private Integer wantNum; + + public FollowGetRequest() { + } + + public FollowGetRequest(String fromAccount, Integer followType, String startCursor, Integer wantNum) { + this.fromAccount = fromAccount; + this.followType = followType; + this.startCursor = startCursor; + this.wantNum = wantNum; + } + + private FollowGetRequest(FollowGetRequest.Builder builder) { + this.fromAccount = builder.fromAccount; + this.followType = builder.followType; + this.startCursor = builder.startCursor; + this.wantNum = builder.wantNum; + } + + public static FollowGetRequest.Builder builder() { + return new FollowGetRequest.Builder(); + } + + public String getFromAccount() { + return fromAccount; + } + + public void setFromAccount(String fromAccount) { + this.fromAccount = fromAccount; + } + + public Integer getFollowType() { + return followType; + } + + public void setFollowType(Integer followType) { + this.followType = followType; + } + + public String getStartCursor() { + return startCursor; + } + + public void setStartCursor(String startCursor) { + this.startCursor = startCursor; + } + + public Integer getWantNum() { + return wantNum; + } + + public void setWantNum(Integer wantNum) { + this.wantNum = wantNum; + } + + public static final class Builder { + private String fromAccount; + private Integer followType; + private String startCursor; + private Integer wantNum; + + private Builder() { + } + + public FollowGetRequest build() { + return new FollowGetRequest(this); + } + + public FollowGetRequest.Builder fromAccount(String fromAccount) { + this.fromAccount = fromAccount; + return this; + } + + public FollowGetRequest.Builder followType(Integer followType) { + this.followType = followType; + return this; + } + + public FollowGetRequest.Builder startCursor(String startCursor) { + this.startCursor = startCursor; + return this; + } + + public FollowGetRequest.Builder wantNum(Integer wantNum) { + this.wantNum = wantNum; + return this; + } + + } +} diff --git a/src/main/java/io/github/doocs/im/model/request/FollowRequestItem.java b/src/main/java/io/github/doocs/im/model/request/FollowRequestItem.java new file mode 100644 index 0000000..dd2f5f5 --- /dev/null +++ b/src/main/java/io/github/doocs/im/model/request/FollowRequestItem.java @@ -0,0 +1,62 @@ +package io.github.doocs.im.model.request; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.Serializable; + +/** + *+ * 关注请求结构体对象 + *
+ * + * @author MC.Yang + * @version V1.0 + **/ +public class FollowRequestItem implements Serializable { + private static final long serialVersionUID = -9020322405344913908L; + + /** + * 待关注的用户的 UserID,单次请求的 To_Account 数不得超过20 + */ + @JsonProperty("To_Account") + private String toAccount; + + public FollowRequestItem() { + } + + public FollowRequestItem(String toAccount) { + this.toAccount = toAccount; + } + + private FollowRequestItem(FollowRequestItem.Builder builder) { + this.toAccount = builder.toAccount; + } + + public static FollowRequestItem.Builder builder() { + return new FollowRequestItem.Builder(); + } + + public String getToAccount() { + return toAccount; + } + + public void setToAccount(String toAccount) { + this.toAccount = toAccount; + } + + public static final class Builder { + private String toAccount; + + private Builder() { + } + + public FollowRequestItem build() { + return new FollowRequestItem(this); + } + + public FollowRequestItem.Builder toAccount(String toAccount) { + this.toAccount = toAccount; + return this; + } + } +} diff --git a/src/main/java/io/github/doocs/im/model/response/FollowAddResult.java b/src/main/java/io/github/doocs/im/model/response/FollowAddResult.java new file mode 100644 index 0000000..cf29563 --- /dev/null +++ b/src/main/java/io/github/doocs/im/model/response/FollowAddResult.java @@ -0,0 +1,57 @@ +package io.github.doocs.im.model.response; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.Serializable; +import java.util.List; + +/** + *+ * 关注用户-结果 + *
+ * + * @author MC.Yang + * @version V1.0 + **/ +public class FollowAddResult extends GenericResult implements Serializable { + private static final long serialVersionUID = -8463119745041284748L; + + /** + * 批量关注的结果对象数组 + */ + @JsonProperty("ResultItem") + private List+ * 检查关注关系-结果 + *
+ * + * @author MC.Yang + * @version V1.0 + **/ +public class FollowCheckResult extends GenericResult implements Serializable { + private static final long serialVersionUID = 950703576946301497L; + + /** + * 校验结果对象数组 + */ + @JsonProperty("ResultItem") + private List+ * 校验结果对象 + *
+ * + * @author MC.Yang + * @version V1.0 + **/ +public class FollowCheckResultItem extends ResultItem implements Serializable { + private static final long serialVersionUID = -6833184498334647596L; + + /** + * 校验成功时 To_Account 与 From_Account 之间的关注关系: + * 0 - From_Account 没有关注 To_Account,To_Account 也没有关注 From_Account。 + * 1 - From_Account 没有关注 To_Account,To_Account 关注了 From_Account。 + * 2 - From_Account 关注了 To_Account,To_Account 没有关注 From_Account。 + * 3 - From_Account 关注了 To_Account,To_Account 也关注了 From_Account。 + */ + @JsonProperty("FollowType") + private Integer followType; + + public Integer getFollowType() { + return followType; + } + + public void setFollowType(Integer followType) { + this.followType = followType; + } + + @Override + public String toString() { + return "FollowCheckResultItem{" + + "toAccount='" + getToAccount() + '\'' + + ", resultCode=" + getResultCode() + + ", resultInfo='" + getResultInfo() + '\'' + + ", followType=" + followType + + '}'; + } +} diff --git a/src/main/java/io/github/doocs/im/model/response/FollowDeleteResult.java b/src/main/java/io/github/doocs/im/model/response/FollowDeleteResult.java new file mode 100644 index 0000000..987ff18 --- /dev/null +++ b/src/main/java/io/github/doocs/im/model/response/FollowDeleteResult.java @@ -0,0 +1,57 @@ +package io.github.doocs.im.model.response; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.Serializable; +import java.util.List; + +/** + *+ * 取消关注用户-结果 + *
+ * + * @author MC.Yang + * @version V1.0 + **/ +public class FollowDeleteResult extends GenericResult implements Serializable { + private static final long serialVersionUID = 3253549117573601073L; + + /** + * 批量取关的结果对象数组 + */ + @JsonProperty("ResultItem") + private List+ * 获取用户的关注、粉丝与互关数-结果 + *
+ * + * @author MC.Yang + * @version V1.0 + **/ +public class FollowGetInfoResult extends GenericResult implements Serializable { + private static final long serialVersionUID = 6489950260163429701L; + + /** + * 拉取的结果对象数组 + */ + @JsonProperty("FollowInfo") + private List+ * 拉取关注、粉丝与互关列表-结果 + *
+ * + * @author MC.Yang + * @version V1.0 + **/ +public class FollowGetResult extends GenericResult implements Serializable { + private static final long serialVersionUID = -374927471394227839L; + + /** + * 粉丝/关注/互关列表 + */ + @JsonProperty("FollowItem") + private List+ * 拉取的结果对象 + *
+ * + * @author MC.Yang + * @version V1.0 + **/ +public class FollowInfoResultItem extends ResultItem implements Serializable { + private static final long serialVersionUID = 6150410504453879405L; + + /** + * To_Account 的粉丝数 + */ + @JsonProperty("FollowerCount") + private Integer followerCount; + + /** + * To_Account 的关注数 + */ + @JsonProperty("FollowingCount") + private Integer followingCount; + + /** + * To_Account 的互关数 + */ + @JsonProperty("MutualFollowingCount") + private Integer mutualFollowingCount; + + public Integer getFollowerCount() { + return followerCount; + } + + public void setFollowerCount(Integer followerCount) { + this.followerCount = followerCount; + } + + public Integer getFollowingCount() { + return followingCount; + } + + public void setFollowingCount(Integer followingCount) { + this.followingCount = followingCount; + } + + public Integer getMutualFollowingCount() { + return mutualFollowingCount; + } + + public void setMutualFollowingCount(Integer mutualFollowingCount) { + this.mutualFollowingCount = mutualFollowingCount; + } + + @Override + public String toString() { + return "FollowInfoResultItem{" + + "followerCount=" + followerCount + + ", followingCount=" + followingCount + + ", mutualFollowingCount=" + mutualFollowingCount + + ", toAccount='" + getToAccount() + '\'' + + ", resultCode=" + getResultCode() + + ", resultInfo='" + getResultInfo() + '\'' + + '}'; + } + +} diff --git a/src/main/java/io/github/doocs/im/model/response/FollowResultItem.java b/src/main/java/io/github/doocs/im/model/response/FollowResultItem.java new file mode 100644 index 0000000..13fc086 --- /dev/null +++ b/src/main/java/io/github/doocs/im/model/response/FollowResultItem.java @@ -0,0 +1,70 @@ +package io.github.doocs.im.model.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.github.doocs.im.model.request.ProfileItem; + +import java.io.Serializable; +import java.util.List; + +/** + *+ * 粉丝/关注/互关列表 + *
+ * + * @author MC.Yang + * @version V1.0 + **/ +public class FollowResultItem implements Serializable { + private static final long serialVersionUID = -3806086675364942543L; + + /** + * 粉丝/关注/互关的用户的 UserID + */ + @JsonProperty("To_Account") + private String toAccount; + + /** + * 关注时间 + */ + @JsonProperty("FollowTime") + private Integer followTime; + + /** + * 用户资料 + */ + @JsonProperty("ProfileItem") + private List