Skip to content

Commit

Permalink
feat: add officialAccount api
Browse files Browse the repository at this point in the history
  • Loading branch information
yanglbme committed Jan 10, 2024
1 parent 5d1845b commit 51c004d
Show file tree
Hide file tree
Showing 16 changed files with 801 additions and 76 deletions.
28 changes: 14 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,22 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<excludes>
<exclude>**/app.properties</exclude>
</excludes>
</configuration>
<!-- <configuration>-->
<!-- <excludes>-->
<!-- <exclude>**/app.properties</exclude>-->
<!-- </excludes>-->
<!-- </configuration>-->
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>app.properties</exclude>
</excludes>
</resource>
</resources>
<!-- <resources>-->
<!-- <resource>-->
<!-- <directory>src/main/resources</directory>-->
<!-- <filtering>true</filtering>-->
<!-- <excludes>-->
<!-- <exclude>app.properties</exclude>-->
<!-- </excludes>-->
<!-- </resource>-->
<!-- </resources>-->
</build>

<profiles>
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/io/github/doocs/im/core/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Message {
public static final String SERVICE_NAME = "openim";

public static final String SERVICE_NAME_MSG_EXT = "openim_msg_ext_http_svc";
public static final String SERVICE_NAME_GROUP = "group_open_http_svc";

/**
* 单聊消息相关命令字
Expand All @@ -34,6 +35,8 @@ public class Message {
public static final String MODIFY_C2C_MSG_COMMAND = "modify_c2c_msg";
public static final String GET_KEY_VALUES_COMMAND = "get_key_values";
public static final String SET_KEY_VALUES_COMMAND = "set_key_values";
public static final String DELETE_C2C_MSG_RAMBLE_COMMAND = "delete_c2c_msg_ramble";
public static final String CLEAR_GROUP_MSG_COMMAND = "clear_group_msg";

private final ImClient imClient;

Expand Down Expand Up @@ -210,4 +213,38 @@ public SetKeyValuesResult setKeyValues(SetKeyValuesRequest setKeyValuesRequest,
String url = imClient.getUrl(SERVICE_NAME_MSG_EXT, SET_KEY_VALUES_COMMAND, random);
return HttpUtil.post(url, setKeyValuesRequest, SetKeyValuesResult.class, imClient.getConfig());
}

/**
* 单向删除单聊历史消息
*
* @param deleteC2cMsgRambleRequest 请求参数
* @return 结果
* @throws IOException 异常
*/
public DeleteC2cMsgRambleResult deleteC2cMsgRamble(DeleteC2cMsgRambleRequest deleteC2cMsgRambleRequest) throws IOException {
String url = imClient.getUrl(SERVICE_NAME, DELETE_C2C_MSG_RAMBLE_COMMAND);
return HttpUtil.post(url, deleteC2cMsgRambleRequest, DeleteC2cMsgRambleResult.class, imClient.getConfig());
}

public DeleteC2cMsgRambleResult deleteC2cMsgRamble(DeleteC2cMsgRambleRequest deleteC2cMsgRambleRequest, long random) throws IOException {
String url = imClient.getUrl(SERVICE_NAME, DELETE_C2C_MSG_RAMBLE_COMMAND, random);
return HttpUtil.post(url, deleteC2cMsgRambleRequest, DeleteC2cMsgRambleResult.class, imClient.getConfig());
}

/**
* 清空群聊历史消息
*
* @param clearGroupMsgRequest 请求参数
* @return 结果
* @throws IOException 异常
*/
public ClearGroupMsgResult clearGroupMsg(ClearGroupMsgRequest clearGroupMsgRequest) throws IOException {
String url = imClient.getUrl(SERVICE_NAME_GROUP, CLEAR_GROUP_MSG_COMMAND);
return HttpUtil.post(url, clearGroupMsgRequest, ClearGroupMsgResult.class, imClient.getConfig());
}

public ClearGroupMsgResult clearGroupMsg(ClearGroupMsgRequest clearGroupMsgRequest, long random) throws IOException {
String url = imClient.getUrl(SERVICE_NAME_GROUP, CLEAR_GROUP_MSG_COMMAND, random);
return HttpUtil.post(url, clearGroupMsgRequest, ClearGroupMsgResult.class, imClient.getConfig());
}
}
62 changes: 44 additions & 18 deletions src/main/java/io/github/doocs/im/core/OfficialAccount.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
package io.github.doocs.im.core;

import io.github.doocs.im.ImClient;
import io.github.doocs.im.model.request.CreateOfficialAccountRequest;
import io.github.doocs.im.model.request.DestroyOfficialAccountRequest;
import io.github.doocs.im.model.request.GetOfficialAccountInfoRequest;
import io.github.doocs.im.model.request.GetSubscriberInfoRequest;
import io.github.doocs.im.model.request.ModifyOfficialAccountBaseInfoRequest;
import io.github.doocs.im.model.request.SendOfficialAccountMsgRequest;
import io.github.doocs.im.model.response.CreateOfficialAccountResult;
import io.github.doocs.im.model.response.DestroyOfficialAccountResult;
import io.github.doocs.im.model.response.GetOfficialAccountInfoResult;
import io.github.doocs.im.model.response.GetSubscriberInfoResult;
import io.github.doocs.im.model.response.ModifyOfficialAccountBaseInfoResult;
import io.github.doocs.im.model.response.SendOfficialAccountMsgResult;
import io.github.doocs.im.model.request.*;
import io.github.doocs.im.model.response.*;
import io.github.doocs.im.util.HttpUtil;

import java.io.IOException;
Expand All @@ -36,8 +26,10 @@ public class OfficialAccount {
public static final String DESTROY_OFFICIAL_ACCOUNT = "destroy_official_account";
public static final String MODIFY_OFFICIAL_ACCOUNT_BASE_INFO = "modify_official_account_base_info";
public static final String SEND_OFFICIAL_ACCOUNT_MSG_COMMAND = "send_official_account_msg";
public static final String GET_OFFICIAL_ACCOUNT_INFO = "get_official_account_info";
public static final String GET_SUBSCRIBER_INFO = "get_subscriber_info";
public static final String GET_OFFICIAL_ACCOUNT_INFO_COMMAND = "get_official_account_info";
public static final String GET_SUBSCRIBER_INFO_COMMAND = "get_subscriber_info";
public static final String OFFICIAL_ACCOUNT_MSG_RECALL_COMMAND = "official_account_msg_recall";
public static final String OFFICIAL_ACCOUNT_MSG_GET_SIMPLE_COMMAND = "official_account_msg_get_simple";

private final ImClient imClient;

Expand Down Expand Up @@ -121,12 +113,12 @@ public SendOfficialAccountMsgResult sendOfficialAccountMsg(SendOfficialAccountMs
* @throws IOException 异常
*/
public GetOfficialAccountInfoResult getOfficialAccountInfo(GetOfficialAccountInfoRequest getOfficialAccountInfoRequest) throws IOException {
String url = imClient.getUrl(SERVICE_NAME, GET_OFFICIAL_ACCOUNT_INFO);
String url = imClient.getUrl(SERVICE_NAME, GET_OFFICIAL_ACCOUNT_INFO_COMMAND);
return HttpUtil.post(url, getOfficialAccountInfoRequest, GetOfficialAccountInfoResult.class, imClient.getConfig());
}

public GetOfficialAccountInfoResult getOfficialAccountInfo(GetOfficialAccountInfoRequest getOfficialAccountInfoRequest, long random) throws IOException {
String url = imClient.getUrl(SERVICE_NAME, GET_OFFICIAL_ACCOUNT_INFO, random);
String url = imClient.getUrl(SERVICE_NAME, GET_OFFICIAL_ACCOUNT_INFO_COMMAND, random);
return HttpUtil.post(url, getOfficialAccountInfoRequest, GetOfficialAccountInfoResult.class, imClient.getConfig());
}

Expand All @@ -138,12 +130,46 @@ public GetOfficialAccountInfoResult getOfficialAccountInfo(GetOfficialAccountInf
* @throws IOException 异常
*/
public GetSubscriberInfoResult getSubscriberInfo(GetSubscriberInfoRequest getSubscriberInfoRequest) throws IOException {
String url = imClient.getUrl(SERVICE_NAME, GET_SUBSCRIBER_INFO);
String url = imClient.getUrl(SERVICE_NAME, GET_SUBSCRIBER_INFO_COMMAND);
return HttpUtil.post(url, getSubscriberInfoRequest, GetSubscriberInfoResult.class, imClient.getConfig());
}

public GetSubscriberInfoResult getSubscriberInfo(GetSubscriberInfoRequest getSubscriberInfoRequest, long random) throws IOException {
String url = imClient.getUrl(SERVICE_NAME, GET_SUBSCRIBER_INFO, random);
String url = imClient.getUrl(SERVICE_NAME, GET_SUBSCRIBER_INFO_COMMAND, random);
return HttpUtil.post(url, getSubscriberInfoRequest, GetSubscriberInfoResult.class, imClient.getConfig());
}

/**
* 撤回公众号消息
*
* @param officialAccountMsgRecallRequest 请求参数
* @return 结果
* @throws IOException 异常
*/
public OfficialAccountMsgRecallResult msgRecall(OfficialAccountMsgRecallRequest officialAccountMsgRecallRequest) throws IOException {
String url = imClient.getUrl(SERVICE_NAME, OFFICIAL_ACCOUNT_MSG_RECALL_COMMAND);
return HttpUtil.post(url, officialAccountMsgRecallRequest, OfficialAccountMsgRecallResult.class, imClient.getConfig());
}

public OfficialAccountMsgRecallResult msgRecall(OfficialAccountMsgRecallRequest officialAccountMsgRecallRequest, long random) throws IOException {
String url = imClient.getUrl(SERVICE_NAME, OFFICIAL_ACCOUNT_MSG_RECALL_COMMAND, random);
return HttpUtil.post(url, officialAccountMsgRecallRequest, OfficialAccountMsgRecallResult.class, imClient.getConfig());
}

/**
* 拉取公众号用户历史消息
*
* @param officialAccountMsgGetSimpleRequest 请求参数
* @return 结果
* @throws IOException 异常
*/
public OfficialAccountMsgGetSimpleResult msgGetSimple(OfficialAccountMsgGetSimpleRequest officialAccountMsgGetSimpleRequest) throws IOException {
String url = imClient.getUrl(SERVICE_NAME, OFFICIAL_ACCOUNT_MSG_GET_SIMPLE_COMMAND);
return HttpUtil.post(url, officialAccountMsgGetSimpleRequest, OfficialAccountMsgGetSimpleResult.class, imClient.getConfig());
}

public OfficialAccountMsgGetSimpleResult msgGetSimple(OfficialAccountMsgGetSimpleRequest officialAccountMsgGetSimpleRequest, long random) throws IOException {
String url = imClient.getUrl(SERVICE_NAME, OFFICIAL_ACCOUNT_MSG_GET_SIMPLE_COMMAND, random);
return HttpUtil.post(url, officialAccountMsgGetSimpleRequest, OfficialAccountMsgGetSimpleResult.class, imClient.getConfig());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AdminGetRoamMsgRequest extends GenericRequest implements Serializable {
private static final long serialVersionUID = -1979505757549864474L;

/**
* 会话其中一方的 UserID,若已指定发送消息方账号,则为消息发送方
* 会话其中一方的 UserID,以该 UserID 的角度去查询消息。同一个会话,分别以会话双方的角度去查询消息,结果可能会不一样,请参考本接口的接口说明
*/
@JsonProperty("From_Account")
private String fromAccount;
@JsonProperty("Operator_Account")
private String operatorAccount;

/**
* 会话其中一方的 UserID
* 会话的另一方 UserID
*/
@JsonProperty("To_Account")
private String toAccount;
@JsonProperty("Peer_Account")
private String peerAccount;

/**
* 请求的消息条数
Expand Down Expand Up @@ -53,27 +54,26 @@ public class AdminGetRoamMsgRequest extends GenericRequest implements Serializab
public AdminGetRoamMsgRequest() {
}

public AdminGetRoamMsgRequest(String fromAccount, String toAccount, Integer maxCnt, Integer minTime, Integer maxTime) {
this.fromAccount = fromAccount;
this.toAccount = toAccount;
public AdminGetRoamMsgRequest(String operatorAccount, String peerAccount, Integer maxCnt, Integer minTime, Integer maxTime) {
this.operatorAccount = operatorAccount;
this.peerAccount = peerAccount;
this.maxCnt = maxCnt;
this.minTime = minTime;
this.maxTime = maxTime;
}

public AdminGetRoamMsgRequest(String fromAccount, String toAccount, Integer maxCnt, Integer minTime,
Integer maxTime, String lastMsgKey) {
this.fromAccount = fromAccount;
this.toAccount = toAccount;
public AdminGetRoamMsgRequest(String operatorAccount, String peerAccount, Integer maxCnt, Integer minTime, Integer maxTime, String lastMsgKey) {
this.operatorAccount = operatorAccount;
this.peerAccount = peerAccount;
this.maxCnt = maxCnt;
this.minTime = minTime;
this.maxTime = maxTime;
this.lastMsgKey = lastMsgKey;
}

private AdminGetRoamMsgRequest(Builder builder) {
this.fromAccount = builder.fromAccount;
this.toAccount = builder.toAccount;
this.operatorAccount = builder.operatorAccount;
this.peerAccount = builder.peerAccount;
this.maxCnt = builder.maxCnt;
this.minTime = builder.minTime;
this.maxTime = builder.maxTime;
Expand All @@ -84,20 +84,20 @@ public static Builder builder() {
return new Builder();
}

public String getFromAccount() {
return fromAccount;
public String getOperatorAccount() {
return operatorAccount;
}

public void setFromAccount(String fromAccount) {
this.fromAccount = fromAccount;
public void setOperatorAccount(String operatorAccount) {
this.operatorAccount = operatorAccount;
}

public String getToAccount() {
return toAccount;
public String getPeerAccount() {
return peerAccount;
}

public void setToAccount(String toAccount) {
this.toAccount = toAccount;
public void setPeerAccount(String peerAccount) {
this.peerAccount = peerAccount;
}

public Integer getMaxCnt() {
Expand Down Expand Up @@ -134,8 +134,8 @@ public void setLastMsgKey(String lastMsgKey) {


public static final class Builder {
private String fromAccount;
private String toAccount;
private String operatorAccount;
private String peerAccount;
private Integer maxCnt;
private Integer minTime;
private Integer maxTime;
Expand All @@ -148,13 +148,13 @@ public AdminGetRoamMsgRequest build() {
return new AdminGetRoamMsgRequest(this);
}

public Builder fromAccount(String fromAccount) {
this.fromAccount = fromAccount;
public Builder operatorAccount(String operatorAccount) {
this.operatorAccount = operatorAccount;
return this;
}

public Builder toAccount(String toAccount) {
this.toAccount = toAccount;
public Builder peerAccount(String peerAccount) {
this.peerAccount = peerAccount;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package io.github.doocs.im.model.request;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;

/**
* 清空群聊历史消息-请求参数
*
* @author bingo
* @since 2024/1/10 10:25
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ClearGroupMsgRequest extends GenericRequest implements Serializable {
private static final long serialVersionUID = 1822917977659354031L;
@JsonProperty("GroupId")
private String groupId;

@JsonProperty("MsgSeq")
private Long msgSeq;

public ClearGroupMsgRequest() {
}

public ClearGroupMsgRequest(String groupId) {
this.groupId = groupId;
}

public ClearGroupMsgRequest(String groupId, Long msgSeq) {
this.groupId = groupId;
this.msgSeq = msgSeq;
}

private ClearGroupMsgRequest(Builder builder) {
this.groupId = builder.groupId;
this.msgSeq = builder.msgSeq;
}

public static Builder builder() {
return new Builder();
}

public String getGroupId() {
return groupId;
}

public void setGroupId(String groupId) {
this.groupId = groupId;
}

public Long getMsgSeq() {
return msgSeq;
}

public void setMsgSeq(Long msgSeq) {
this.msgSeq = msgSeq;
}


public static final class Builder {
private String groupId;
private Long msgSeq;

private Builder() {
}

public ClearGroupMsgRequest build() {
return new ClearGroupMsgRequest(this);
}

public Builder groupId(String groupId) {
this.groupId = groupId;
return this;
}

public Builder msgSeq(Long msgSeq) {
this.msgSeq = msgSeq;
return this;
}
}
}
Loading

0 comments on commit 51c004d

Please sign in to comment.