8000 :new: #2356 【公众号】新增草稿箱和发布相关的接口 · aieyes/WxJava@705dfc3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 705dfc3

Browse files
mr-dragonaieyes
authored andcommitted
🆕 binarywang#2356 【公众号】新增草稿箱和发布相关的接口
1 parent a449e49 commit 705dfc3

20 files changed

+1330
-3
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
package me.chanjar.weixin.mp.api;
2+
3+
import me.chanjar.weixin.common.error.WxErrorException;
4+
import me.chanjar.weixin.mp.bean.draft.WxMpAddDraft;
5+
import me.chanjar.weixin.mp.bean.draft.WxMpDraftInfo;
6+
import me.chanjar.weixin.mp.bean.draft.WxMpDraftList;
7+
import me.chanjar.weixin.mp.bean.draft.WxMpUpdateDraft;
8+
9+
/**
10+
* 微信 草稿箱 接口.
11+
*
12+
* @author dragon
13+
* @date 2021-10-22
14+
*/
15+
public interface WxMpDraftService {
16+
17+
/**
18+
* 新建草稿 - 只有默认必填参数
19+
* <pre>
20+
* 请求地址:POST https://api.weixin.qq.com/cgi-bin/draft/add?access_token=ACCESS_TOKEN
21+
* 文档地址:https://developers.weixin.qq.com/doc/offiaccount/Draft_Box/Add_draft.html
22+
* </pre>
23+
*
24+
* @param title 标题
25+
* @param content 图文消息的具体内容,支持HTML标签,必须少于2万字符,小于1M,且此处会去除JS,涉及图片url必须来源 "上传图文消息内的图片获取URL"接口获取。外部图片url将被过滤。
26+
* @param thumbMediaId 图文消息的封面图片素材id(必须是永久MediaID)
27+
* @throws WxErrorException .
28+
*/
29+
String addDraft(String title, String content, String thumbMediaId) throws WxErrorException;
30+
31+
/**
32+
* 新建草稿 - 完整参数
33+
* <pre>
34+
* 请求地址:POST https://api.weixin.qq.com/cgi-bin/draft/add?access_token=ACCESS_TOKEN
35+
* 文档地址:https://developers.weixin.qq.com/doc/offiaccount/Draft_Box/Add_draft.html
36+
* </pre>
37+
*
38+
* @param addDraft 新建草稿信息
39+
* @throws WxErrorException .
40+
*/
41+
String addDraft(WxMpAddDraft addDraft) throws WxErrorException;
42+
43+
/**
44+
* 修改草稿 - 完整参数
45+
* 正常情况下调用成功时,errcode将为0。错误时微信会返回错误码等信息,请根据错误码查询错误信息
46+
* <pre>
47+
* 请求地址: POST https://api.weixin.qq.com/cgi-bin/draft/update?access_token=ACCESS_TOKEN
48+
* 文档地址:https://developers.weixin.qq.com/doc/offiaccount/Draft_Box/Update_draft.html
49+
* </pre>
50+
*
51+
* @param updateDraftInfo 修改草稿信息
52+
* @throws WxErrorException .
53+
*/
54+
Boolean updateDraft(WxMpUpdateDraft updateDraftInfo) throws WxErrorException;
55+
56+
/**
57+
* 获取草稿信息
58+
*
59+
* <pre>
60+
* 请求地址:POST https://api.weixin.qq.com/cgi-bin/draft/get?access_token=ACCESS_TOKEN
61+
* 文档地址:https://developers.weixin.qq.com/doc/offiaccount/Draft_Box/Get_draft.html
62+
* </pre>
63+
*
64+
* @param mediaId 要获取的草稿的media_id
65+
* @return 草稿信息
66+
* @throws WxErrorException .
67+
*/
68+
WxMpDraftInfo getDraft(String mediaId) throws WxErrorException;
69+
70+
/**
71+
* 删除草稿
72+
* 正常情况下调用成功时,errcode将为0。错误时微信会返回错误码等信息,请根据错误码查询错误信息。
73+
* 多次删除同一篇草稿,也返回 0.
74+
* <pre>
75+
* 请求地址:POST https://api.weixin.qq.com/cgi-bin/draft/delete?access_token=ACCESS_TOKEN
76+
* 文档地址:https://developers.weixin.qq.com/doc/offiaccount/Draft_Box/Delete_draft.html
77+
* </pre>
78+
*
79+
* @param mediaId 要删除的草稿的media_id
80+
* @throws WxErrorException .
81+
*/
82+
Boolean delDraft(String mediaId) throws WxErrorException;
83+
84+
/**
85+
* 获取草稿列表
86+
*
87+
* <pre>
88+
* 请求地址:POST https://api.weixin.qq.com/cgi-bin/draft/batchget?access_token=ACCESS_TOKEN
89+
* 文档地址:https://developers.weixin.qq.com/doc/offiaccount/Draft_Box/Get_draft_list.html
90+
* </pre>
91+
*
92+
* @param offset 分页页数,从0开始 从全部素材的该偏移位置开始返回,0表示从第一个素材返回
93+
* @param count 每页数量 返回素材的数量,取值在1到20之间
94+
* @param noContent 1 表示不返回 content 字段,0 表示正常返回,默认为 0
95+
* @return 草稿信息列表
96+
* @throws WxErrorException .
97+
*/
98+
WxMpDraftList listDraft(int offset, int count, int noContent) throws WxErrorException;
99+
100+
/**
101+
* 获取草稿列表
102+
* <pre>
103+
* 请求地址:POST https://api.weixin.qq.com/cgi-bin/draft/batchget?access_token=ACCESS_TOKEN
104+
* 文档地址:https://developers.weixin.qq.com/doc/offiaccount/Draft_Box/Get_draft_list.html
105+
* </pre>
106+
*
107+
* @param offset 分页页数,从0开始 从全部素材的该偏移位置开始返回,0表示从第一个素材返回
108+
* @param count 每页数量 返回素材的数量,取值在1到20之间
109+
* @return
110+
* @throws WxErrorException
111+
*/
112+
WxMpDraftList listDraft(int offset, int count) throws WxErrorException;
113+
114+
/**
115+
* 获取草稿数量
116+
* 开发者可以根据本接口来获取草稿的总数。此接口只统计数量,不返回草稿的具体内容。
117+
* <pre>
118+
* 请求地址:POST https://api.weixin.qq.com/cgi-bin/draft/count?access_token=ACCESS_TOKEN
119+
* 文档地址:https://developers.weixin.qq.com/doc/offiaccount/Draft_Box/Count_drafts.html
120+
* </pre>
121+
*
122+
* @return 草稿的总数
123+
* @throws WxErrorException .
124+
*/
125+
Long countDraft() throws WxErrorException;
126+
127+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package me.chanjar.weixin.mp.api;
2+
3+
import me.chanjar.weixin.common.error.WxErrorException;
4+
import me.chanjar.weixin.mp.bean.freepublish.WxMpFreePublishInfo;
5+
import me.chanjar.weixin.mp.bean.freepublish.WxMpFreePublishList;
6+
import me.chanjar.weixin.mp.bean.freepublish.WxMpFreePublishStatus;
7+
8+
/**
9+
* 微信 发布能力 接口.
10+
*
11+
* @author dragon
12+
* @date 2021-10-23
13+
*/
14+
public interface WxMpFreePublishService {
15+
16+
/**
17+
* 发布接口 - 只有默认必填参数
18+
* 开发者需要先将图文素材以草稿的形式保存(见“草稿箱/新建草稿”,如需从已保存的草稿中选择,见“草稿箱/获取草稿列表”),选择要发布的草稿 media_id 进行发布
19+
* <pre>
20+
* 请求地址:POST https://api.weixin.qq.com/cgi-bin/freepublish/submit?access_token=ACCESS_TOKEN
21+
* 文档地址:https://developers.weixin.qq.com/doc/offiaccount/Publish/Publish.html
22+
* </pre>
23+
*
24+
* @param mediaId 要发布的草稿的media_id
25+
* @throws WxErrorException .
26+
*/
27+
String submit(String mediaId) throws WxErrorException;
28+
29+
/**
30+
* 发布状态轮询接口
31+
* 开发者可以尝试通过下面的发布状态轮询接口获知发布情况。
32+
* <pre>
33+
* 请求地址:POST https://api.weixin.qq.com/cgi-bin/freepublish/get?access_token=ACCESS_TOKEN
34+
* 文档地址:https://developers.weixin.qq.com/doc/offiaccount/Publish/Get_status.html
35+
* </pre>
36+
*
37+
* @param publishId 发布任务id
38+
* @throws WxErrorException .
39+
*/
40+
WxMpFreePublishStatus getPushStatus(String publishId) throws WxErrorException;
41+
42+
/**
43+
* 删除发布
44+
* 发布成功之后,随时可以通过该接口删除。此操作不可逆,请谨慎操作。
45+
* <pre>
46+
* 请求地址:POST https://api.weixin.qq.com/cgi-bin/freepublish/delete?access_token=ACCESS_TOKEN
47+
* 文档地址:https://developers.weixin.qq.com/doc/offiaccount/Publish/Delete_posts.html
48+
* </pre>
49+
*
50+
* @param articleId 成功发布时返回的 article_id
51+
* @param index 要删除的文章在图文消息中的位置,第一篇编号为1,该字段不填或填0会删除全部文章
52+
* @throws WxErrorException .
53+
*/
54+
Boolean deletePush(String articleId, Integer index) throws WxErrorException;
55+
56+
/**
57+
* 删除发布 - 此条发布的所有内容,不指定文章编号
58+
* 发布成功之后,随时可以通过该接口删除。此操作不可逆,请谨慎操作。
59+
* <pre>
60+
* 请求地址:POST https://api.weixin.qq.com/cgi-bin/freepublish/delete?access_token=ACCESS_TOKEN
61+
* 文档地址:https://developers.weixin.qq.com/doc/offiaccount/Publish/Delete_posts.html
62+
* </pre>
63+
*
64+
* @param articleId 成功发布时返回的 article_id
65+
* @throws WxErrorException .
66+
*/
67+
Boolean deletePushAllArticle(String articleId) throws WxErrorException;
68+
69+
/**
70+
* 通过 article_id 获取已发布文章
71+
* 开发者可以通过 article_id 获取已发布的图文信息。
72+
* <pre>
73+
* 请求地址:POST https://api.weixin.qq.com/cgi-bin/freepublish/getarticle?access_token=ACCESS_TOKEN
74+
* 文档地址:https://developers.weixin.qq.com/doc/offiaccount/Publish/Get_article_from_id.html
75+
* </pre>
76+
*
77+
* @param articleId 要获取的草稿的article_id
78+
* @return 已发布文章信息
79+
* @throws WxErrorException .
80+
*/
81+
WxMpFreePublishInfo getArticleFromId(String articleId) throws WxErrorException;
82+
83+
/**
84+
* 获取成功发布列表 - 支持选择是否返回:图文消息的具体内容
85+
*
86+
* <pre>
87+
* 请求地址:POST https://api.weixin.qq.com/cgi-bin/draft/batchget?access_token=ACCESS_TOKEN
88+
* 文档地址:https://developers.weixin.qq.com/doc/offiaccount/Publish/Get_publication_records.html
89+
* </pre>
90+
*
91+
* @param offset 分页页数,从0开始 从全部素材的该偏移位置开始返回,0表示从第一个素材返回
92+
* @param count 每页数量 返回素材的数量,取值在1到20之间
93+
* @param noContent 1 表示不返回 content 字段,0 表示正常返回,默认为 0
94+
* @return 草稿信息列表
95+
* @throws WxErrorException .
96+
*/
97+
WxMpFreePublishList getPublicationRecords(int offset, int count, int noContent) throws WxErrorException;
98+
99+
/**
100+
* 获取成功发布列表 - 默认返回 图文消息的具体内容
101+
* <pre>
102+
* 请求地址:POST https://api.weixin.qq.com/cgi-bin/draft/batchget?access_token=ACCESS_TOKEN
103+
* 文档地址:https://developers.weixin.qq.com/doc/offiaccount/Publish/Get_publication_records.html
104+
* </pre>
105+
*
106+
* @param offset 分页页数,从0开始 从全部素材的该偏移位置开始返回,0表示从第一个素材返回
107+
* @param count 每页数量 返回素材的数量,取值在1到20之间
108+
* @return
109+
* @throws WxErrorException
110+
*/
111+
WxMpFreePublishList getPublicationRecords(int offset, int count) throws WxErrorException;
112+
113+
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,20 @@ public interface WxMpService extends WxService {
567567
*/
568568
WxMpReimburseInvoiceService getReimburseInvoiceService();
569569

570+
/**
571+
* 返回草稿箱相关接口
572+
*
573+
* @return WxMpDraftService
574+
*/
575+
WxMpDraftService getDraftService();
576+
577+
/**
578+
* 返回发布能力接口
579+
*
580+
* @return WxMpFreePublishService
581+
*/
582+
WxMpFreePublishService getFreePublishService();
583+
570584
/**
571585
* .
572586
*
@@ -818,4 +832,18 @@ public interface WxMpService extends WxService {
818832
* @param merchantInvoiceService the merchant invoice service
819833
*/
820834
void setMerchantInvoiceService(WxMpMerchantInvoiceService merchantInvoiceService);
835+
836+
/**
837+
* Sets draft service.
838+
*
839+
* @param draftService the draft service
840+
*/
841+
void setDraftService(WxMpDraftService draftService);
842+
843+
/**
844+
* Sets free publish service.
845+
*
846+
* @param freePublishService the free publish service
847+
*/
848+
void setFreePublishService(WxMpFreePublishService freePublishService);
821849
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImpl.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
import me.chanjar.weixin.common.util.DataUtils;
2626
import me.chanjar.weixin.common.util.RandomUtils;
2727
import me.chanjar.weixin.common.util.crypto.SHA1;
28-
import me.chanjar.weixin.common.util.http.*;
28+
import me.chanjar.weixin.common.util.http.RequestExecutor;
29+
import me.chanjar.weixin.common.util.http.RequestHttp;
30+
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
31+
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
32+
import me.chanjar.weixin.common.util.http.URIUtil;
2933
import me.chanjar.weixin.common.util.json.GsonParser;
3034
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
3135
import me.chanjar.weixin.mp.api.*;
@@ -42,7 +46,16 @@
4246
import java.util.Map;
4347
import java.util.concurrent.locks.Lock;
4448

45-
import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Other.*;
49+
import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Other.CLEAR_QUOTA_URL;
50+
import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Other.FETCH_SHORTEN_URL;
51+
import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Other.GEN_SHORTEN_URL;
52+
import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Other.GET_CALLBACK_IP_URL;
53+
import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Other.GET_CURRENT_AUTOREPLY_INFO_URL;
54+
import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Other.GET_TICKET_URL;
55+
import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Other.NETCHECK_URL;
56+
import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Other.QRCONNECT_URL;
57+
import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Other.SEMANTIC_SEMPROXY_SEARCH_URL;
58+
import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Other.SHORTURL_API_URL;
4659

4760
/**
4861
* 基础实现类.
@@ -146,6 +159,14 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH
146159
@Setter
147160
private WxMpReimburseInvoiceService reimburseInvoiceService = new WxMpReimburseInvoiceServiceImpl(this);
148161

162+
@Getter
163+
@Setter
164+
private WxMpDraftService draftService = new WxMpDraftServiceImpl(this);
165+
166+
@Getter
167+
@Setter
168+
private WxMpFreePublishService freePublishService = new WxMpFreePublishServiceImpl(this);
169+
149170
private Map<String, WxMpConfigStorage> configStorageMap;
150171

151172
private int retrySleepMillis = 1000;

0 commit comments

Comments
 (0)
0