Skip to content

Commit

Permalink
feat: add officialAccount api
Browse files Browse the repository at this point in the history
  • Loading branch information
hongyiheng committed Jan 10, 2024
1 parent fbba3af commit 3392468
Show file tree
Hide file tree
Showing 15 changed files with 1,002 additions and 4 deletions.
73 changes: 73 additions & 0 deletions src/main/java/io/github/doocs/im/core/OfficialAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public class OfficialAccount {
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";
public static final String ADD_SUBSCRIBER = "add_subscriber";
public static final String DELETE_SUBSCRIBER = "delete_subscriber";
public static final String MODIFY_SUBSCRIBER_INFO = "modify_subscriber_info";
public static final String GET_SUBSCRIBED_OFFICIAL_ACCOUNT_LIST = "get_subscribed_official_account_list";


private final ImClient imClient;

Expand Down Expand Up @@ -172,4 +177,72 @@ public OfficialAccountMsgGetSimpleResult msgGetSimple(OfficialAccountMsgGetSimpl
String url = imClient.getUrl(SERVICE_NAME, OFFICIAL_ACCOUNT_MSG_GET_SIMPLE_COMMAND, random);
return HttpUtil.post(url, officialAccountMsgGetSimpleRequest, OfficialAccountMsgGetSimpleResult.class, imClient.getConfig());
}

/**
* 公众号添加订阅者
*
* @param addSubscriberRequest 请求参数
* @return 结果
* @throws IOException 异常
*/
public AddSubscriberResult addSubscriber(AddSubscriberRequest addSubscriberRequest) throws IOException {
String url = imClient.getUrl(SERVICE_NAME, ADD_SUBSCRIBER);
return HttpUtil.post(url, addSubscriberRequest, AddSubscriberResult.class, imClient.getConfig());
}

public AddSubscriberResult addSubscriber(AddSubscriberRequest addSubscriberRequest, long random) throws IOException {
String url = imClient.getUrl(SERVICE_NAME, ADD_SUBSCRIBER, random);
return HttpUtil.post(url, addSubscriberRequest, AddSubscriberResult.class, imClient.getConfig());
}

/**
* 公众号删除订阅者
*
* @param deleteSubscriberRequest 请求参数
* @return 结果
* @throws IOException 异常
*/
public DeleteSubscriberResult deleteSubscriber(DeleteSubscriberRequest deleteSubscriberRequest) throws IOException {
String url = imClient.getUrl(SERVICE_NAME, DELETE_SUBSCRIBER);
return HttpUtil.post(url, deleteSubscriberRequest, DeleteSubscriberResult.class, imClient.getConfig());
}

public DeleteSubscriberResult deleteSubscriber(DeleteSubscriberRequest deleteSubscriberRequest, long random) throws IOException {
String url = imClient.getUrl(SERVICE_NAME, DELETE_SUBSCRIBER, random);
return HttpUtil.post(url, deleteSubscriberRequest, DeleteSubscriberResult.class, imClient.getConfig());
}

/**
* 修改订阅者信息
*
* @param modifySubscriberInfoRequest 请求参数
* @return 结果
* @throws IOException 异常
*/
public ModifySubscriberInfoResult modifySubscriberInfo(ModifySubscriberInfoRequest modifySubscriberInfoRequest) throws IOException {
String url = imClient.getUrl(SERVICE_NAME, MODIFY_SUBSCRIBER_INFO);
return HttpUtil.post(url, modifySubscriberInfoRequest, ModifySubscriberInfoResult.class, imClient.getConfig());
}

public ModifySubscriberInfoResult modifySubscriberInfo(ModifySubscriberInfoRequest modifySubscriberInfoRequest, long random) throws IOException {
String url = imClient.getUrl(SERVICE_NAME, MODIFY_SUBSCRIBER_INFO, random);
return HttpUtil.post(url, modifySubscriberInfoRequest, ModifySubscriberInfoResult.class, imClient.getConfig());
}

/**
* 获取订阅公众号列表
*
* @param getSubscribedOfficialAccountListRequest 请求参数
* @return 结果
* @throws IOException 异常
*/
public GetSubscribedOfficialAccountListResult getSubscribedOfficialAccountList(GetSubscribedOfficialAccountListRequest getSubscribedOfficialAccountListRequest) throws IOException {
String url = imClient.getUrl(SERVICE_NAME, GET_SUBSCRIBED_OFFICIAL_ACCOUNT_LIST);
return HttpUtil.post(url, getSubscribedOfficialAccountListRequest, GetSubscribedOfficialAccountListResult.class, imClient.getConfig());
}

public GetSubscribedOfficialAccountListResult getSubscribedOfficialAccountList(GetSubscribedOfficialAccountListRequest getSubscribedOfficialAccountListRequest, long random) throws IOException {
String url = imClient.getUrl(SERVICE_NAME, GET_SUBSCRIBED_OFFICIAL_ACCOUNT_LIST, random);
return HttpUtil.post(url, getSubscribedOfficialAccountListRequest, GetSubscribedOfficialAccountListResult.class, imClient.getConfig());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
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 hyh
* @since 2024/01/10 15:11
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AddSubscriberRequest extends GenericRequest implements Serializable {
private static final long serialVersionUID = 1989326297259052718L;
/**
* 需要订阅的公众号 ID。使用创建时接口返回的 OfficialAccountUserID 字段
*/
@JsonProperty("Official_Account")
private String officialAccount;

/**
* 待添加的订阅者数组
*/
@JsonProperty("SubscriberList")
private List<OfficialAccountItem> subscriberList;

public AddSubscriberRequest() {
}

public AddSubscriberRequest(String officialAccount, List<OfficialAccountItem> subscriberList) {
this.officialAccount = officialAccount;
this.subscriberList = subscriberList;
}

private AddSubscriberRequest(Builder builder) {
this.officialAccount = builder.officialAccount;
this.subscriberList = builder.subscriberList;
}

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

public String getOfficialAccount() {
return officialAccount;
}

public void setOfficialAccount(String officialAccount) {
this.officialAccount = officialAccount;
}

public List<OfficialAccountItem> getSubscriberList() {
return subscriberList;
}

public void setSubscriberList(List<OfficialAccountItem> subscriberList) {
this.subscriberList = subscriberList;
}


public static final class Builder {
private String officialAccount;
private List<OfficialAccountItem> subscriberList;

private Builder() {
}

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

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

public Builder subscriberList(List<OfficialAccountItem> subscriberList) {
this.subscriberList = subscriberList;
return this;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
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 hyh
* @since 2024/01/10 15:28
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class DeleteSubscriberRequest extends GenericRequest implements Serializable {
private static final long serialVersionUID = -4604299710168815132L;
/**
* 需要订阅的公众号 ID。使用创建时接口返回的 OfficialAccountUserID 字段
*/
@JsonProperty("Official_Account")
private String officialAccount;

/**
* 待删除的的订阅者 UserID 集合
*/
@JsonProperty("SubscriberToDel_Account")
private List<String> subscriberToDelAccount;

public DeleteSubscriberRequest() {
}

public DeleteSubscriberRequest(String officialAccount, List<String> subscriberToDelAccount) {
this.officialAccount = officialAccount;
this.subscriberToDelAccount = subscriberToDelAccount;
}

private DeleteSubscriberRequest(Builder builder) {
this.officialAccount = builder.officialAccount;
this.subscriberToDelAccount = builder.subscriberToDelAccount;
}

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

public String getOfficialAccount() {
return officialAccount;
}

public void setOfficialAccount(String officialAccount) {
this.officialAccount = officialAccount;
}

public List<String> getSubscriberToDelAccount() {
return subscriberToDelAccount;
}

public void setSubscriberToDelAccount(List<String> subscriberToDelAccount) {
this.subscriberToDelAccount = subscriberToDelAccount;
}

public static final class Builder {
private String officialAccount;
private List<String> subscriberToDelAccount;

private Builder() {
}

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

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

public Builder subscriberToDelAccount(List<String> subscriberToDelAccount) {
this.subscriberToDelAccount = subscriberToDelAccount;
return this;
}
}
}
Loading

0 comments on commit 3392468

Please sign in to comment.