11package me .chanjar .weixin .mp .api .impl ;
22
33import com .google .inject .Inject ;
4+ import me .chanjar .weixin .common .api .WxConsts ;
45import me .chanjar .weixin .common .error .WxErrorException ;
56import me .chanjar .weixin .mp .api .WxMpService ;
67import me .chanjar .weixin .mp .api .test .ApiTestModule ;
2324public class WxMpDraftServiceImplTest {
2425
2526 /**
26- * 1.先上传一个永久图片素材:me.chanjar.weixin.mp.api.impl.WxMpMaterialServiceImplTest. testUploadMaterial
27+ * 1.先上传一个永久图片素材:{@link me.chanjar.weixin.mp.api.impl.WxMpMaterialServiceImplTest# testUploadMaterial}
2728 * 2.后续图文需要设置一个永久素材id
2829 */
29- final String thumbMediaId = "zUUtT8ZYeXzZ4slFbtnAkh7Yd-f45DbFoF9ERzVC6s4 " ;
30+ final String thumbMediaId = "-V3dxNv-eyJlImuJjWrmaTPt76BS6jHrL6-cGBlFPaXxAuv0qeJYV2p6Ezirr0zS " ;
3031
3132 /**
3233 * 新增草稿后返回的id,后续查询、修改、删除,获取等需要使用
3334 */
34- final String mediaId = "zUUtT8ZYeXzZ4slFbtnAkpgGKyqnTsjtUvMdVBRWJVk " ;
35+ final String mediaId = "-V3dxNv-eyJlImuJjWrmaZLwMkTKfDEhzq5NURU02H-k1qHMJ0lh9p0UU46w3rbd " ;
3536
3637 @ Inject
3738 protected WxMpService wxService ;
@@ -114,6 +115,7 @@ public void testListDraft() throws WxErrorException {
114115 ,"total_count":1,"item_count":1}
115116
116117 */
118+ System .out .println (draftList );
117119 assertThat (draftList ).isNotNull ();
118120 }
119121
@@ -124,5 +126,101 @@ public void testCountDraft() throws WxErrorException {
124126 assertThat (countDraft ).isNotNull ();
125127 }
126128
129+ //-----以下是图片类型草稿测试
130+
131+ /**
132+ * 先上传一个永久图片素材:{@link me.chanjar.weixin.mp.api.impl.WxMpMaterialServiceImplTest#testUploadMaterial}
133+ * 这里的图片,使用的是 mm.jpeg
134+ */
135+ @ Test
136+ public void testAddDraftPic () throws WxErrorException {
137+ List <WxMpDraftArticles > draftArticleList = new ArrayList <>();
138+ ArrayList <WxMpDraftImageInfo .ImageItem > imageItems = new ArrayList <>();
139+ imageItems .add (new WxMpDraftImageInfo .ImageItem (thumbMediaId ));
140+
141+ ArrayList <WxMpDraftCoverInfo .CropPercent > cropPercents = new ArrayList <>();
142+ cropPercents .add (new WxMpDraftCoverInfo .CropPercent ("1_1" , "0.1" , "0" , "1" , "0.9" ));
143+
144+ WxMpDraftArticles draftArticle = WxMpDraftArticles .builder ()
145+ .articleType (WxConsts .ArticleType .NEWS_PIC )
146+ .title ("新建图片草稿" )
147+ .content ("图片消息的具体内容" )
148+ // 打开评论、所有人可评论
149+ .needOpenComment (1 ).onlyFansCanComment (0 )
150+ .imageInfo (WxMpDraftImageInfo .builder ().imageList (imageItems ).build ())
151+ .coverInfo (WxMpDraftCoverInfo .builder ().cropPercentList (cropPercents ).build ())
152+ .productInfo (WxMpDraftProductInfo .builder ().footerProductInfo (new WxMpDraftProductInfo .FooterProductInfo ("" )).build ())
153+ .build ();
154+ draftArticleList .add (draftArticle );
155+
156+ WxMpAddDraft addDraft = WxMpAddDraft .builder ().articles (draftArticleList ).build ();
157+ String mediaId = this .wxService .getDraftService ().addDraft (addDraft );
158+ System .out .println (mediaId );
159+ assertThat (mediaId ).isNotNull ();
160+ }
161+
162+ @ Test
163+ public void testGetDraftPic () throws WxErrorException {
164+ final WxMpDraftInfo draftInfo = this .wxService .getDraftService ().getDraft (mediaId );
165+ assertThat (draftInfo ).isNotNull ();
166+ System .out .println (draftInfo .toJson ());
167+ // 【响应数据】:{
168+ // "news_item": [
169+ // {
170+ // "article_type": "newspic",
171+ // "title": "新建图片草稿",
172+ // "content": "图片消息的具体内容",
173+ // "thumb_media_id": "-V3dxNv-eyJlImuJjWrmaTPt76BS6jHrL6-cGBlFPaXxAuv0qeJYV2p6Ezirr0zS",
174+ // "need_open_comment": 1,
175+ // "only_fans_can_comment": 0,
176+ // "url": "http://mp.weixin.qq.com/s?__biz=MzkyNTg4NDM1NA==&tempkey=MTMyM18rUktkOHFIQm5Kd3U5Rk1yS2NRYWtyZWUyNDNwS2MxZTZ3VXBKTkVScExpUFdGYzN2X0IzOEl1NGxEMGFpYld6NmdvbE9UUzlyYUdiVklvWTQ2YlRzSkkzQlpWMEZpcG9JRWp5LWZCVVNoWURodUlfWnE4VWZVQnlPd2VaUkg5SGREYUd3TW1wQkhlbTFuenBvRzFIbUxhMEJVbEo0Z3oyd2tnSGJBfn4%3D&chksm=423e8b9e75490288e8388c9ee91d6dad462bbce654742edd316622ab2b2fcfc593a4db58577b#rd",
177+ // "thumb_url": "http://mmbiz.qpic.cn/sz_mmbiz_jpg/s7FE7rYN42QgPuJeXX9MfNuJBiaoalrWv8fj4AEqnK0WBM3KzqS0DsqHIW4epA3cx1PGjpco87BTssgQibvSNBIQ/0?wx_fmt=jpeg",
178+ // "image_info": {
179+ // "image_list": [
180+ // {
181+ // "image_media_id": "-V3dxNv-eyJlImuJjWrmaTPt76BS6jHrL6-cGBlFPaXxAuv0qeJYV2p6Ezirr0zS"
182+ // }
183+ // ]
184+ // }
185+ // }
186+ // ]
187+ // }
188+ }
189+
190+ @ Test
191+ public void testUpdateDraftPic () throws WxErrorException {
192+ ArrayList <WxMpDraftImageInfo .ImageItem > imageItems = new ArrayList <>();
193+ imageItems .add (new WxMpDraftImageInfo .ImageItem (thumbMediaId ));
194+ ArrayList <WxMpDraftCoverInfo .CropPercent > cropPercents = new ArrayList <>();
195+ cropPercents .add (new WxMpDraftCoverInfo .CropPercent ("1_1" , "0.3" , "0" , "1" , "0.7" ));
196+
197+ WxMpDraftArticles draftArticle = WxMpDraftArticles .builder ()
198+ .articleType (WxConsts .ArticleType .NEWS_PIC )
199+ .title ("修改图片草稿" )
200+ .content ("修改后的图片消息的具体内容" )
201+ // 打开评论、所有人可评论
202+ .needOpenComment (1 ).onlyFansCanComment (0 )
203+ .imageInfo (WxMpDraftImageInfo .builder ().imageList (imageItems ).build ())
204+ .coverInfo (WxMpDraftCoverInfo .builder ().cropPercentList (cropPercents ).build ())
205+ .productInfo (WxMpDraftProductInfo .builder ().footerProductInfo (new WxMpDraftProductInfo .FooterProductInfo ("" )).build ())
206+ .build ();
207+
208+ WxMpUpdateDraft updateDraft = WxMpUpdateDraft .builder ()
209+ .mediaId (mediaId )
210+ .index (0 )
211+ .articles (draftArticle )
212+ .build ();
213+ Boolean updateDraftResult = this .wxService .getDraftService ().updateDraft (updateDraft );
214+ assertThat (updateDraftResult ).isTrue ();
215+ }
216+
217+ @ Test
218+ public void testDelDraftPic () throws WxErrorException {
219+ Boolean delDraftResult = this .wxService .getDraftService ().delDraft (mediaId );
220+ System .out .println (delDraftResult );
221+ // 【响应数据】:{"errcode":0,"errmsg":"ok"}
222+ assertThat (delDraftResult ).isTrue ();
223+ }
224+
127225}
128226
0 commit comments