-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9307f4
commit ee517b6
Showing
8 changed files
with
534 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
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.ModifyOfficialAccountBaseInfoRequest; | ||
import io.github.doocs.im.model.response.CreateOfficialAccountResult; | ||
import io.github.doocs.im.model.response.DestroyOfficialAccountResult; | ||
import io.github.doocs.im.model.response.ModifyOfficialAccountBaseInfoResult; | ||
import io.github.doocs.im.util.HttpUtil; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* 公众号 | ||
* | ||
* @author hyh | ||
* @since 2024/01/09 21:50 | ||
*/ | ||
public class Official { | ||
/** | ||
* 公众号服务名 | ||
*/ | ||
public static final String SERVICE_NAME = "official_account_open_http_svc"; | ||
|
||
/** | ||
* 公众号相关命令字 | ||
*/ | ||
public static final String CREATE_OFFICIAL_ACCOUNT = "create_official_account"; | ||
public static final String DESTROY_OFFICIAL_ACCOUNT = "destroy_official_account"; | ||
public static final String MODIFY_OFFICIAL_ACCOUNT_BASE_INFO = "modify_official_account_base_info"; | ||
|
||
private final ImClient imClient; | ||
|
||
public Official(ImClient imClient) { | ||
this.imClient = imClient; | ||
} | ||
|
||
/** | ||
* 创建公众号 | ||
* | ||
* @param createOfficialAccountRequest 请求参数 | ||
* @return 结果 | ||
* @throws IOException 异常 | ||
*/ | ||
public CreateOfficialAccountResult createOfficialAccount(CreateOfficialAccountRequest createOfficialAccountRequest) throws IOException { | ||
String url = imClient.getUrl(SERVICE_NAME, CREATE_OFFICIAL_ACCOUNT); | ||
return HttpUtil.post(url, createOfficialAccountRequest, CreateOfficialAccountResult.class, imClient.getConfig()); | ||
} | ||
|
||
public CreateOfficialAccountResult createOfficialAccount(CreateOfficialAccountRequest createOfficialAccountRequest, long random) throws IOException { | ||
String url = imClient.getUrl(SERVICE_NAME, CREATE_OFFICIAL_ACCOUNT, random); | ||
return HttpUtil.post(url, createOfficialAccountRequest, CreateOfficialAccountResult.class, imClient.getConfig()); | ||
} | ||
|
||
/** | ||
* 销毁公众号 | ||
* | ||
* @param destroyOfficialAccountRequest 请求参数 | ||
* @return 结果 | ||
* @throws IOException 异常 | ||
*/ | ||
public DestroyOfficialAccountResult destroyOfficialAccount(DestroyOfficialAccountRequest destroyOfficialAccountRequest) throws IOException { | ||
String url = imClient.getUrl(SERVICE_NAME, DESTROY_OFFICIAL_ACCOUNT); | ||
return HttpUtil.post(url, destroyOfficialAccountRequest, DestroyOfficialAccountResult.class, imClient.getConfig()); | ||
} | ||
|
||
public DestroyOfficialAccountResult destroyOfficialAccount(DestroyOfficialAccountRequest destroyOfficialAccountRequest, long random) throws IOException { | ||
String url = imClient.getUrl(SERVICE_NAME, DESTROY_OFFICIAL_ACCOUNT, random); | ||
return HttpUtil.post(url, destroyOfficialAccountRequest, DestroyOfficialAccountResult.class, imClient.getConfig()); | ||
} | ||
|
||
/** | ||
* 修改公众号资料 | ||
* | ||
* @param modifyOfficialAccountBaseInfoRequest 请求参数 | ||
* @return 结果 | ||
* @throws IOException 异常 | ||
*/ | ||
public ModifyOfficialAccountBaseInfoResult modifyOfficialAccountBaseInfo(ModifyOfficialAccountBaseInfoRequest modifyOfficialAccountBaseInfoRequest) throws IOException { | ||
String url = imClient.getUrl(SERVICE_NAME, MODIFY_OFFICIAL_ACCOUNT_BASE_INFO); | ||
return HttpUtil.post(url, modifyOfficialAccountBaseInfoRequest, ModifyOfficialAccountBaseInfoResult.class, imClient.getConfig()); | ||
} | ||
|
||
public ModifyOfficialAccountBaseInfoResult modifyOfficialAccountBaseInfo(ModifyOfficialAccountBaseInfoRequest modifyOfficialAccountBaseInfoRequest, long random) throws IOException { | ||
String url = imClient.getUrl(SERVICE_NAME, MODIFY_OFFICIAL_ACCOUNT_BASE_INFO, random); | ||
return HttpUtil.post(url, modifyOfficialAccountBaseInfoRequest, ModifyOfficialAccountBaseInfoResult.class, imClient.getConfig()); | ||
} | ||
} |
161 changes: 161 additions & 0 deletions
161
src/main/java/io/github/doocs/im/model/request/CreateOfficialAccountRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
package io.github.doocs.im.model.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* 创建公众号-请求参数 | ||
* | ||
* @author hyh | ||
* @date 2024/1/9 21:54 | ||
*/ | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public class CreateOfficialAccountRequest extends GenericRequest implements Serializable { | ||
private static final long serialVersionUID = -4787413705241959236L; | ||
|
||
/** | ||
* 公众号所属的账号 ID(需是 已导入 的账号),代表公众号的拥有者 | ||
*/ | ||
@JsonProperty("Owner_Account") | ||
private String ownerAccount; | ||
|
||
/** | ||
* 公众号的 ID。为了使公众号 ID 更加简单,便于记忆传播,腾讯云支持 App 在通过 REST API 创建公众号时 自定义公众号 ID。 | ||
* 若不填,则系统会默认生成一个公众号 ID 返回 | ||
*/ | ||
@JsonProperty("OfficialAccountUserID") | ||
private String officialAccountUserID; | ||
|
||
/** | ||
* 公众号的名称,最长 150 字节,使用 UTF-8 编码,1 个汉字占 3 个字节 | ||
*/ | ||
@JsonProperty("Name") | ||
private String name; | ||
|
||
/** | ||
* 公众号简介,最长 400 字节,使用 UTF-8 编码,1 个汉字占 3 个字节 | ||
*/ | ||
@JsonProperty("Introduction") | ||
private String introduction; | ||
|
||
/** | ||
* 公众号头像,最长500字节 | ||
*/ | ||
@JsonProperty("FaceUrl") | ||
private String faceUrl; | ||
|
||
/** | ||
* 一个公众号的最大可订阅人数,缺省时的默认值为 100000 | ||
*/ | ||
@JsonProperty("MaxSubscriberNum") | ||
private Integer maxSubscriberNum; | ||
|
||
/** | ||
* 公众号所属的团体组织,最长 500 字节,使用 UTF-8 编码,1 个汉字占 3 个字节 | ||
*/ | ||
@JsonProperty("Organization") | ||
private String organization; | ||
|
||
/** | ||
* 公众号的自定义字段,最长 3000 字节,业务层可以使用此字段来实现特殊场景的需求 | ||
*/ | ||
@JsonProperty("CustomString") | ||
private String customString; | ||
|
||
public CreateOfficialAccountRequest() { | ||
} | ||
|
||
public CreateOfficialAccountRequest(String ownerAccount, String name) { | ||
this.ownerAccount = ownerAccount; | ||
this.name = name; | ||
} | ||
|
||
public CreateOfficialAccountRequest(String ownerAccount, String officialAccountUserID, String name, | ||
String introduction, String faceUrl, Integer maxSubscriberNum, | ||
String organization, String customString) { | ||
this.ownerAccount = ownerAccount; | ||
this.officialAccountUserID = officialAccountUserID; | ||
this.name = name; | ||
this.introduction = introduction; | ||
this.faceUrl = faceUrl; | ||
this.maxSubscriberNum = maxSubscriberNum; | ||
this.organization = organization; | ||
this.customString = customString; | ||
} | ||
|
||
private CreateOfficialAccountRequest(Builder builder) { | ||
this.ownerAccount = builder.ownerAccount; | ||
this.officialAccountUserID = builder.officialAccountUserID; | ||
this.name = builder.name; | ||
this.introduction = builder.introduction; | ||
this.faceUrl = builder.faceUrl; | ||
this.maxSubscriberNum = builder.maxSubscriberNum; | ||
this.organization = builder.organization; | ||
this.customString = builder.customString; | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
|
||
public static final class Builder { | ||
private String ownerAccount; | ||
private String officialAccountUserID; | ||
private String name; | ||
private String introduction; | ||
private String faceUrl; | ||
private Integer maxSubscriberNum; | ||
private String organization; | ||
private String customString; | ||
|
||
private Builder() { | ||
} | ||
|
||
public CreateOfficialAccountRequest build() { | ||
return new CreateOfficialAccountRequest(this); | ||
} | ||
|
||
public Builder ownerAccount(String ownerAccount) { | ||
this.ownerAccount = ownerAccount; | ||
return this; | ||
} | ||
|
||
public Builder officialAccountUserID(String officialAccountUserID) { | ||
this.officialAccountUserID = officialAccountUserID; | ||
return this; | ||
} | ||
|
||
public Builder name(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
public Builder introduction(String introduction) { | ||
this.introduction = introduction; | ||
return this; | ||
} | ||
|
||
public Builder faceUrl(String faceUrl) { | ||
this.faceUrl = faceUrl; | ||
return this; | ||
} | ||
|
||
public Builder maxSubscriberNum(Integer maxSubscriberNum) { | ||
this.maxSubscriberNum = maxSubscriberNum; | ||
return this; | ||
} | ||
|
||
public Builder organization(String organization) { | ||
this.organization = organization; | ||
return this; | ||
} | ||
|
||
public Builder customString(String customString) { | ||
this.customString = customString; | ||
return this; | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/io/github/doocs/im/model/request/DestroyOfficialAccountRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package io.github.doocs.im.model.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* 销毁公众号-请求参数 | ||
* | ||
* @author hyh | ||
* @date 2024/1/9 22:06 | ||
*/ | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public class DestroyOfficialAccountRequest extends GenericRequest implements Serializable { | ||
private static final long serialVersionUID = 5130762102739300161L; | ||
|
||
/** | ||
* 需要销毁的公众号 ID. 使用创建时接口返回的 OfficialAccountUserID 字段 | ||
*/ | ||
@JsonProperty("Official_Account") | ||
private String officialAccount; | ||
|
||
public DestroyOfficialAccountRequest() { | ||
} | ||
|
||
public DestroyOfficialAccountRequest(String officialAccount) { | ||
this.officialAccount = officialAccount; | ||
} | ||
|
||
private DestroyOfficialAccountRequest(Builder builder) { | ||
this.officialAccount = builder.officialAccount; | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
|
||
public static final class Builder { | ||
private String officialAccount; | ||
|
||
private Builder() { | ||
} | ||
|
||
public DestroyOfficialAccountRequest build() { | ||
return new DestroyOfficialAccountRequest(this); | ||
} | ||
|
||
public Builder officialAccount(String officialAccount) { | ||
this.officialAccount = officialAccount; | ||
return this; | ||
} | ||
} | ||
} |
Oops, something went wrong.