8000 【公众号】群发消息支持多图片群发 by Tang178042684 · Pull Request #2851 · binarywang/WxJava · GitHub
[go: up one dir, main page]

Skip to content

【公众号】群发消息支持多图片群发 #2851

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
【公众号】群发消息支持多图片群发
-测试用例
  • Loading branch information
唐英鹏 committed Oct 25, 2022
commit 43c8c6f7d7a2aae2ac4c1df60bcc1f9990a3ef4c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.chanjar.weixin.mp.api.impl;

import com.google.inject.Inject;

import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.error.WxErrorException;
Expand All @@ -21,6 +22,8 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import static org.testng.Assert.assertNotNull;

Expand All @@ -38,7 +41,7 @@ public class WxMpMassMessageServiceImplTest {
@Test
public void testTextMassOpenIdsMessageSend() throws WxErrorException {
// 发送群发消息
TestConfigStorage configProvider = (TestConfigStorage) this.wxService .getWxMpConfigStorage();
TestConfigStorage configProvider = (TestConfigStorage) this.wxService.getWxMpConfigStorage();
WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage();
massMessage.setMsgType(WxConsts.MassMsgType.TEXT);
massMessage.setContent("测试群发消息\n欢迎欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>");
Expand All @@ -63,6 +66,30 @@ public void testMediaMassOpenIdsMessageSend(String massMsgType, String mediaId)
assertNotNull(massResult.getMsgId());
}

@Test
public void testImagesMassOpenIdsMessageSend() throws WxErrorException {
// 发送群发消息
List<String> massMsg = new ArrayList<>();
for (int i = 0; i < 2; i++) {
try (InputStream inputStream = ClassLoader
.getSystemResourceAsStream(i + ".jpeg")) {
WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService().mediaUpload(WxConsts.MediaFileType.IMAGE, TestConstants.FILE_JPG, inputStream);
assertNotNull(uploadMediaRes);
assertNotNull(uploadMediaRes.getMediaId());
massMsg.add(uploadMediaRes.getMediaId());
} catch (IOException e) {
e.printStackTrace();
}
}
WxMpMassTagMessage massMessage = new WxMpMassTagMessage();
massMessage.setMsgType(WxConsts.MassMsgType.IMAGE);
massMessage.setMediaIds(new ArrayList<>(massMsg));
massMessage.setSendAll(true);
WxMpMassSendResult massResult = this.wxService.getMassMessageService().massGroupMessageSend(massMessage);
assertNotNull(massResult);
assertNotNull(massResult.getMsgId());
}

@Test
public void testTextMassGroupMessageSend() throws WxErrorException {
WxMpMassTagMessage massMessage = new WxMpMassTagMessage();
Expand All @@ -77,7 +104,7 @@ public void testTextMassGroupMessageSend() throws WxErrorException {
}

@Test(dataProvider = "massMessages")
public void testMediaMassGroupMessageSend(String massMsgType, String mediaId) throws WxErrorException {
public void testMediaMassGroupMessageSend(String massMsgType, String mediaId) throws WxErrorException {
WxMpMassTagMessage massMessage = new WxMpMassTagMessage();
massMessage.setMsgType(massMsgType);
massMessage.setMediaId(mediaId);
Expand Down Expand Up @@ -123,7 +150,8 @@ public Object[][] massMessages() throws WxErrorException, IOException {
.mediaUpload(WxConsts.MediaFileType.IMAGE, TestConstants.FILE_JPG, inputStream);
assertNotNull(uploadMediaRes);
assertNotNull(uploadMediaRes.getMediaId());
messages[1] = new Object[]{WxConsts.MassMsgType.IMAGE, uploadMediaRes.getMediaId()};
messages[1] = new Object[]{WxConsts.MassMsgType.IMAGE, uploadMediaRes.getMediaId()
};
}

/*
Expand Down
Binary file added weixin-java-mp/src/test/resources/0.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added weixin-java-mp/src/test/resources/1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
0