Skip to content

Commit 5d1845b

Browse files
committed
feat: add officialAccount api
1 parent 3753dd4 commit 5d1845b

12 files changed

+763
-39
lines changed

src/main/java/io/github/doocs/im/core/Message.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ public class Message {
2121

2222
public static final String SERVICE_NAME_MSG_EXT = "openim_msg_ext_http_svc";
2323

24-
public static final String SERVICE_NAME_OFFICIAL_ACCOUNT = "official_account_open_http_svc";
25-
2624
/**
2725
* 单聊消息相关命令字
2826
*/
@@ -36,7 +34,6 @@ public class Message {
3634
public static final String MODIFY_C2C_MSG_COMMAND = "modify_c2c_msg";
3735
public static final String GET_KEY_VALUES_COMMAND = "get_key_values";
3836
public static final String SET_KEY_VALUES_COMMAND = "set_key_values";
39-
public static final String SEND_OFFICIAL_ACCOUNT_MSG_COMMAND = "send_official_account_msg";
4037

4138
private final ImClient imClient;
4239

@@ -213,21 +210,4 @@ public SetKeyValuesResult setKeyValues(SetKeyValuesRequest setKeyValuesRequest,
213210
String url = imClient.getUrl(SERVICE_NAME_MSG_EXT, SET_KEY_VALUES_COMMAND, random);
214211
return HttpUtil.post(url, setKeyValuesRequest, SetKeyValuesResult.class, imClient.getConfig());
215212
}
216-
217-
/**
218-
* 公众号用户发送广播消息
219-
*
220-
* @param sendOfficialAccountMsgRequest 请求参数
221-
* @return 结果
222-
* @throws IOException 异常
223-
*/
224-
public SendOfficialAccountMsgResult sendOfficialAccountMsg(SendOfficialAccountMsgRequest sendOfficialAccountMsgRequest) throws IOException {
225-
String url = imClient.getUrl(SERVICE_NAME_OFFICIAL_ACCOUNT, SEND_OFFICIAL_ACCOUNT_MSG_COMMAND);
226-
return HttpUtil.post(url, sendOfficialAccountMsgRequest, SendOfficialAccountMsgResult.class, imClient.getConfig());
227-
}
228-
229-
public SendOfficialAccountMsgResult sendOfficialAccountMsg(SendOfficialAccountMsgRequest sendOfficialAccountMsgRequest, long random) throws IOException {
230-
String url = imClient.getUrl(SERVICE_NAME_OFFICIAL_ACCOUNT, SEND_OFFICIAL_ACCOUNT_MSG_COMMAND, random);
231-
return HttpUtil.post(url, sendOfficialAccountMsgRequest, SendOfficialAccountMsgResult.class, imClient.getConfig());
232-
}
233213
}

src/main/java/io/github/doocs/im/core/OfficialAccount.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33
import io.github.doocs.im.ImClient;
44
import io.github.doocs.im.model.request.CreateOfficialAccountRequest;
55
import io.github.doocs.im.model.request.DestroyOfficialAccountRequest;
6+
import io.github.doocs.im.model.request.GetOfficialAccountInfoRequest;
7+
import io.github.doocs.im.model.request.GetSubscriberInfoRequest;
68
import io.github.doocs.im.model.request.ModifyOfficialAccountBaseInfoRequest;
9+
import io.github.doocs.im.model.request.SendOfficialAccountMsgRequest;
710
import io.github.doocs.im.model.response.CreateOfficialAccountResult;
811
import io.github.doocs.im.model.response.DestroyOfficialAccountResult;
12+
import io.github.doocs.im.model.response.GetOfficialAccountInfoResult;
13+
import io.github.doocs.im.model.response.GetSubscriberInfoResult;
914
import io.github.doocs.im.model.response.ModifyOfficialAccountBaseInfoResult;
15+
import io.github.doocs.im.model.response.SendOfficialAccountMsgResult;
1016
import io.github.doocs.im.util.HttpUtil;
1117

1218
import java.io.IOException;
@@ -29,6 +35,9 @@ public class OfficialAccount {
2935
public static final String CREATE_OFFICIAL_ACCOUNT = "create_official_account";
3036
public static final String DESTROY_OFFICIAL_ACCOUNT = "destroy_official_account";
3137
public static final String MODIFY_OFFICIAL_ACCOUNT_BASE_INFO = "modify_official_account_base_info";
38+
public static final String SEND_OFFICIAL_ACCOUNT_MSG_COMMAND = "send_official_account_msg";
39+
public static final String GET_OFFICIAL_ACCOUNT_INFO = "get_official_account_info";
40+
public static final String GET_SUBSCRIBER_INFO = "get_subscriber_info";
3241

3342
private final ImClient imClient;
3443

@@ -86,4 +95,55 @@ public ModifyOfficialAccountBaseInfoResult modifyOfficialAccountBaseInfo(ModifyO
8695
String url = imClient.getUrl(SERVICE_NAME, MODIFY_OFFICIAL_ACCOUNT_BASE_INFO, random);
8796
return HttpUtil.post(url, modifyOfficialAccountBaseInfoRequest, ModifyOfficialAccountBaseInfoResult.class, imClient.getConfig());
8897
}
98+
99+
/**
100+
* 公众号用户发送广播消息
101+
*
102+
* @param sendOfficialAccountMsgRequest 请求参数
103+
* @return 结果
104+
* @throws IOException 异常
105+
*/
106+
public SendOfficialAccountMsgResult sendOfficialAccountMsg(SendOfficialAccountMsgRequest sendOfficialAccountMsgRequest) throws IOException {
107+
String url = imClient.getUrl(SERVICE_NAME, SEND_OFFICIAL_ACCOUNT_MSG_COMMAND);
108+
return HttpUtil.post(url, sendOfficialAccountMsgRequest, SendOfficialAccountMsgResult.class, imClient.getConfig());
109+
}
110+
111+
public SendOfficialAccountMsgResult sendOfficialAccountMsg(SendOfficialAccountMsgRequest sendOfficialAccountMsgRequest, long random) throws IOException {
112+
String url = imClient.getUrl(SERVICE_NAME, SEND_OFFICIAL_ACCOUNT_MSG_COMMAND, random);
113+
return HttpUtil.post(url, sendOfficialAccountMsgRequest, SendOfficialAccountMsgResult.class, imClient.getConfig());
114+
}
115+
116+
/**
117+
* 获取公众号详细资料
118+
*
119+
* @param getOfficialAccountInfoRequest 请求参数
120+
* @return 结果
121+
* @throws IOException 异常
122+
*/
123+
public GetOfficialAccountInfoResult getOfficialAccountInfo(GetOfficialAccountInfoRequest getOfficialAccountInfoRequest) throws IOException {
124+
String url = imClient.getUrl(SERVICE_NAME, GET_OFFICIAL_ACCOUNT_INFO);
125+
return HttpUtil.post(url, getOfficialAccountInfoRequest, GetOfficialAccountInfoResult.class, imClient.getConfig());
126+
}
127+
128+
public GetOfficialAccountInfoResult getOfficialAccountInfo(GetOfficialAccountInfoRequest getOfficialAccountInfoRequest, long random) throws IOException {
129+
String url = imClient.getUrl(SERVICE_NAME, GET_OFFICIAL_ACCOUNT_INFO, random);
130+
return HttpUtil.post(url, getOfficialAccountInfoRequest, GetOfficialAccountInfoResult.class, imClient.getConfig());
131+
}
132+
133+
/**
134+
* 获取公众号订阅者列表
135+
*
136+
* @param getSubscriberInfoRequest 请求参数
137+
* @return 结果
138+
* @throws IOException 异常
139+
*/
140+
public GetSubscriberInfoResult getSubscriberInfo(GetSubscriberInfoRequest getSubscriberInfoRequest) throws IOException {
141+
String url = imClient.getUrl(SERVICE_NAME, GET_SUBSCRIBER_INFO);
142+
return HttpUtil.post(url, getSubscriberInfoRequest, GetSubscriberInfoResult.class, imClient.getConfig());
143+
}
144+
145+
public GetSubscriberInfoResult getSubscriberInfo(GetSubscriberInfoRequest getSubscriberInfoRequest, long random) throws IOException {
146+
String url = imClient.getUrl(SERVICE_NAME, GET_SUBSCRIBER_INFO, random);
147+
return HttpUtil.post(url, getSubscriberInfoRequest, GetSubscriberInfoResult.class, imClient.getConfig());
148+
}
89149
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package io.github.doocs.im.model.request;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
import java.io.Serializable;
7+
import java.util.List;
8+
9+
/**
10+
* 获取公众号详细资料-请求参数
11+
*
12+
* @author hyh
13+
* @since 2024/01/10 10:34
14+
*/
15+
@JsonInclude(JsonInclude.Include.NON_NULL)
16+
public class GetOfficialAccountInfoRequest extends GenericRequest implements Serializable {
17+
private static final long serialVersionUID = -7046784535464765710L;
18+
/**
19+
* 需要获取的公众号列表 ID
20+
*/
21+
@JsonProperty("OfficialAccountIdList")
22+
private List<OfficialAccountItem> officialAccountIdList;
23+
24+
/**
25+
* 过滤返回的公众号信息字段,不填时默认返回全部字段,包括 OfficialAccountBaseInfoFilter 过滤器,主要可取以下值:
26+
* CreateTime 公众号的创建时间
27+
* Name 公众号名称
28+
* Owner_Account公众号所属的用户
29+
* LastMsgTime 公众号内的最后一条消息时间
30+
* SubscriberNum 公众号目前的订阅者人数
31+
* Introduction 公众号简介
32+
* FaceUrl 公众号的头像Url
33+
* Organization 公众号的所在组织
34+
* CustomString 公众号维度的自定义字段
35+
*/
36+
@JsonProperty("ResponseFilter")
37+
private ResponseFilter responseFilter;
38+
39+
public GetOfficialAccountInfoRequest() {
40+
}
41+
42+
public GetOfficialAccountInfoRequest(List<OfficialAccountItem> officialAccountIdList) {
43+
this.officialAccountIdList = officialAccountIdList;
44+
}
45+
46+
public GetOfficialAccountInfoRequest(List<OfficialAccountItem> officialAccountIdList, ResponseFilter responseFilter) {
47+
this.officialAccountIdList = officialAccountIdList;
48+
this.responseFilter = responseFilter;
49+
}
50+
51+
private GetOfficialAccountInfoRequest(Builder builder) {
52+
this.officialAccountIdList = builder.officialAccountIdList;
53+
this.responseFilter = builder.responseFilter;
54+
}
55+
56+
public static Builder builder() {
57+
return new Builder();
58+
}
59+
60+
public List<OfficialAccountItem> getOfficialAccountIdList() {
61+
return officialAccountIdList;
62+
}
63+
64+
public void setOfficialAccountIdList(List<OfficialAccountItem> officialAccountIdList) {
65+
this.officialAccountIdList = officialAccountIdList;
66+
}
67+
68+
public ResponseFilter getResponseFilter() {
69+
return responseFilter;
70+
}
71+
72+
public void setResponseFilter(ResponseFilter responseFilter) {
73+
this.responseFilter = responseFilter;
74+
}
75+
76+
77+
public static final class Builder {
78+
private List<OfficialAccountItem> officialAccountIdList;
79+
private ResponseFilter responseFilter;
80+
81+
private Builder() {
82+
}
83+
84+
public GetOfficialAccountInfoRequest build() {
85+
return new GetOfficialAccountInfoRequest(this);
86+
}
87+
88+
public Builder officialAccountIdList(List<OfficialAccountItem> officialAccountIdList) {
89+
this.officialAccountIdList = officialAccountIdList;
90+
return this;
91+
}
92+
93+
public Builder responseFilter(ResponseFilter responseFilter) {
94+
this.responseFilter = responseFilter;
95+
return this;
96+
}
97+
}
98+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package io.github.doocs.im.model.request;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
import java.io.Serializable;
7+
8+
/**
9+
* 获取公众号的订阅成员资料-请求参数
10+
*
11+
* @author hyh
12+
* @since 2024/01/10 11:20
13+
*/
14+
@JsonInclude(JsonInclude.Include.NON_NULL)
15+
public class GetSubscriberInfoRequest extends GenericRequest implements Serializable {
16+
private static final long serialVersionUID = -1051719195312598750L;
17+
/**
18+
* 需要获取的公众号 ID。使用创建时接口返回的 OfficialAccountUserID 字段
19+
*/
20+
@JsonProperty("Official_Account")
21+
private String officialAccount;
22+
23+
/**
24+
* 一次最多获取多少个成员的资料,不得超过200。如果不填,则获取群内全部成员的信息
25+
*/
26+
@JsonProperty("Limit")
27+
private Integer limit;
28+
29+
/**
30+
* 上一次拉取到的订阅者位置,首次调用填写"",续拉使用返回中的 Next 值
31+
*/
32+
@JsonProperty("Next")
33+
private String next;
34+
35+
public GetSubscriberInfoRequest() {
36+
}
37+
38+
public GetSubscriberInfoRequest(String officialAccount, String next) {
39+
this.officialAccount = officialAccount;
40+
this.next = next;
41+
}
42+
43+
public GetSubscriberInfoRequest(String officialAccount, Integer limit, String next) {
44+
this.officialAccount = officialAccount;
45+
this.limit = limit;
46+
this.next = next;
47+
}
48+
49+
private GetSubscriberInfoRequest(Builder builder) {
50+
this.officialAccount = builder.officialAccount;
51+
this.limit = builder.limit;
52+
this.next = builder.next;
53+
}
54+
55+
public static Builder builder() {
56+
return new Builder();
57+
}
58+
59+
public String getOfficialAccount() {
60+
return officialAccount;
61+
}
62+
63+
public void setOfficialAccount(String officialAccount) {
64+
this.officialAccount = officialAccount;
65+
}
66+
67+
public Integer getLimit() {
68+
return limit;
69+
}
70+
71+
public void setLimit(Integer limit) {
72+
this.limit = limit;
73+
}
74+
75+
public String getNext() {
76+
return next;
77+
}
78+
79+
public void setNext(String next) {
80+
this.next = next;
81+
}
82+
83+
public static final class Builder {
84+
private String officialAccount;
85+
private Integer limit;
86+
private String next;
87+
88+
private Builder() {
89+
}
90+
91+
public GetSubscriberInfoRequest build() {
92+
return new GetSubscriberInfoRequest(this);
93+
}
94+
95+
public Builder officialAccount(String officialAccount) {
96+
this.officialAccount = officialAccount;
97+
return this;
98+
}
99+
100+
public Builder limit(Integer limit) {
101+
this.limit = limit;
102+
return this;
103+
}
104+
105+
public Builder next(String next) {
106+
this.next = next;
107+
return this;
108+
}
109+
}
110+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package io.github.doocs.im.model.request;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
import java.io.Serializable;
7+
8+
/**
9+
* @author hyh
10+
* @since 2024/01/10 10:41
11+
*/
12+
@JsonInclude(JsonInclude.Include.NON_NULL)
13+
public class OfficialAccountItem implements Serializable {
14+
private static final long serialVersionUID = 1193395857815508620L;
15+
@JsonProperty("Official_Account")
16+
private String officialAccount;
17+
18+
public OfficialAccountItem() {
19+
}
20+
21+
public OfficialAccountItem(String officialAccount) {
22+
this.officialAccount = officialAccount;
23+
}
24+
25+
private OfficialAccountItem(Builder builder) {
26+
this.officialAccount = builder.officialAccount;
27+
}
28+
29+
public static Builder builder() {
30+
return new Builder();
31+
}
32+
33+
public String getOfficialAccount() {
34+
return officialAccount;
35+
}
36+
37+
public void setOfficialAccount(String officialAccount) {
38+
this.officialAccount = officialAccount;
39+
}
40+
41+
public static final class Builder {
42+
private String officialAccount;
43+
44+
private Builder() {
45+
}
46+
47+
public OfficialAccountItem build() {
48+
return new OfficialAccountItem(this);
49+
}
50+
51+
public Builder officialAccount(String officialAccount) {
52+
this.officialAccount = officialAccount;
53+
return this;
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)