Java源码示例:me.chanjar.weixin.mp.bean.result.WxMpMassSendResult
示例1
@Override
public WxMpMassSendResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
WxMpMassSendResult sendResult = new WxMpMassSendResult();
JsonObject sendResultJsonObject = json.getAsJsonObject();
if (sendResultJsonObject.get("errcode") != null && !sendResultJsonObject.get("errcode").isJsonNull()) {
sendResult.setErrorCode(GsonHelper.getAsString(sendResultJsonObject.get("errcode")));
}
if (sendResultJsonObject.get("errmsg") != null && !sendResultJsonObject.get("errmsg").isJsonNull()) {
sendResult.setErrorMsg(GsonHelper.getAsString(sendResultJsonObject.get("errmsg")));
}
if (sendResultJsonObject.get("msg_id") != null && !sendResultJsonObject.get("msg_id").isJsonNull()) {
sendResult.setMsgId(GsonHelper.getAsString(sendResultJsonObject.get("msg_id")));
}
if (sendResultJsonObject.get("msg_data_id") != null && !sendResultJsonObject.get("msg_data_id").isJsonNull()) {
sendResult.setMsgDataId(GsonHelper.getAsString(sendResultJsonObject.get("msg_data_id")));
}
return sendResult;
}
示例2
@Test
public void testTextMassOpenIdsMessageSend() throws WxErrorException {
// 发送群发消息
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>");
massMessage.getToUsers().add(configProvider.getOpenid());
WxMpMassSendResult massResult = this.wxService.getMassMessageService()
.massOpenIdsMessageSend(massMessage);
assertNotNull(massResult);
assertNotNull(massResult.getMsgId());
}
示例3
@Test(dataProvider = "massMessages")
public void testMediaMassOpenIdsMessageSend(String massMsgType, String mediaId) throws WxErrorException {
// 发送群发消息
TestConfigStorage configProvider = (TestConfigStorage) this.wxService
.getWxMpConfigStorage();
WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage();
massMessage.setMsgType(massMsgType);
massMessage.setMediaId(mediaId);
massMessage.getToUsers().add(configProvider.getOpenid());
WxMpMassSendResult massResult = this.wxService.getMassMessageService()
.massOpenIdsMessageSend(massMessage);
assertNotNull(massResult);
assertNotNull(massResult.getMsgId());
}
示例4
@Test
public void testTextMassGroupMessageSend() throws WxErrorException {
WxMpMassTagMessage massMessage = new WxMpMassTagMessage();
massMessage.setMsgType(WxConsts.MassMsgType.TEXT);
massMessage.setContent("测试群发消息\n欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>");
massMessage
.setTagId(this.wxService.getUserTagService().tagGet().get(0).getId());
WxMpMassSendResult massResult = this.wxService.getMassMessageService()
.massGroupMessageSend(massMessage);
assertNotNull(massResult);
assertNotNull(massResult.getMsgId());
}
示例5
@Test(dataProvider = "massMessages")
public void testMediaMassGroupMessageSend(String massMsgType, String mediaId)
throws WxErrorException {
WxMpMassTagMessage massMessage = new WxMpMassTagMessage();
massMessage.setMsgType(massMsgType);
massMessage.setMediaId(mediaId);
massMessage.setTagId(this.wxService.getUserTagService().tagGet().get(0).getId());
WxMpMassSendResult massResult = this.wxService.getMassMessageService()
.massGroupMessageSend(massMessage);
assertNotNull(massResult);
assertNotNull(massResult.getMsgId());
}
示例6
public WxMpMassSendResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
WxMpMassSendResult sendResult = new WxMpMassSendResult();
JsonObject sendResultJsonObject = json.getAsJsonObject();
if (sendResultJsonObject.get("errcode") != null && !sendResultJsonObject.get("errcode").isJsonNull()) {
sendResult.setErrorCode(GsonHelper.getAsString(sendResultJsonObject.get("errcode")));
}
if (sendResultJsonObject.get("errmsg") != null && !sendResultJsonObject.get("errmsg").isJsonNull()) {
sendResult.setErrorMsg(GsonHelper.getAsString(sendResultJsonObject.get("errmsg")));
}
if (sendResultJsonObject.get("msg_id") != null && !sendResultJsonObject.get("msg_id").isJsonNull()) {
sendResult.setMsgId(GsonHelper.getAsString(sendResultJsonObject.get("msg_id")));
}
return sendResult;
}
示例7
@Test
public void testTextMassOpenIdsMessageSend() throws WxErrorException {
// 发送群发消息
ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.wxMpConfigStorage;
WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage();
massMessage.setMsgType(WxConsts.MASS_MSG_TEXT);
massMessage.setContent("测试群发消息\n欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>");
massMessage.getToUsers().add(configProvider.getOpenId());
WxMpMassSendResult massResult = wxService.massOpenIdsMessageSend(massMessage);
Assert.assertNotNull(massResult);
Assert.assertNotNull(massResult.getMsgId());
}
示例8
@Test(dataProvider="massMessages")
public void testMediaMassOpenIdsMessageSend(String massMsgType, String mediaId) throws WxErrorException, IOException {
// 发送群发消息
ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.wxMpConfigStorage;
WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage();
massMessage.setMsgType(massMsgType);
massMessage.setMediaId(mediaId);
massMessage.getToUsers().add(configProvider.getOpenId());
WxMpMassSendResult massResult = wxService.massOpenIdsMessageSend(massMessage);
Assert.assertNotNull(massResult);
Assert.assertNotNull(massResult.getMsgId());
}
示例9
@Test
public void testTextMassGroupMessageSend() throws WxErrorException {
WxMpMassGroupMessage massMessage = new WxMpMassGroupMessage();
massMessage.setMsgtype(WxConsts.MASS_MSG_TEXT);
massMessage.setContent("测试群发消息\n欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>");
massMessage.setGroupId(wxService.groupGet().get(0).getId());
WxMpMassSendResult massResult = wxService.massGroupMessageSend(massMessage);
Assert.assertNotNull(massResult);
Assert.assertNotNull(massResult.getMsgId());
}
示例10
@Test(dataProvider="massMessages")
public void testMediaMassGroupMessageSend(String massMsgType, String mediaId) throws WxErrorException, IOException {
WxMpMassGroupMessage massMessage = new WxMpMassGroupMessage();
massMessage.setMsgtype(massMsgType);
massMessage.setMediaId(mediaId);
massMessage.setGroupId(wxService.groupGet().get(0).getId());
WxMpMassSendResult massResult = wxService.massGroupMessageSend(massMessage);
Assert.assertNotNull(massResult);
Assert.assertNotNull(massResult.getMsgId());
}
示例11
@Override
public void uploadNews(YxArticleDto wxNewsArticleItem) throws WxErrorException {
WxMpService wxMpService = WxMpConfiguration.getWxMpService();
WxMpMaterialNews wxMpMaterialNews = new WxMpMaterialNews();
WxMpMaterialNews.WxMpMaterialNewsArticle article = new WxMpMaterialNews.WxMpMaterialNewsArticle();
WxMpMaterialUploadResult wxMpMaterialUploadResult = uploadPhotoToWx( wxMpService,
wxNewsArticleItem.getImageInput() );
wxNewsArticleItem.setThumbMediaId( wxMpMaterialUploadResult.getMediaId() );
article.setAuthor( wxNewsArticleItem.getAuthor() );
//处理content
String content = processContent(wxMpService, wxNewsArticleItem.getContent());
System.out.println(content);
article.setContent( content );
article.setContentSourceUrl( wxNewsArticleItem.getUrl() );
article.setDigest( wxNewsArticleItem.getSynopsis() );
article.setShowCoverPic( true );
article.setThumbMediaId( wxNewsArticleItem.getThumbMediaId() );
article.setTitle( wxNewsArticleItem.getTitle() );
//TODO 暂时注释掉,测试号没有留言权限
//article.setNeedOpenComment( wxNewsArticleItem );
//article.setOnlyFansCanComment( wxNewsArticleItem );
wxMpMaterialNews.addArticle( article );
log.info( "wxMpMaterialNews : {}", JSONUtil.toJsonStr( wxMpMaterialNews ) );
WxMpMaterialUploadResult wxMpMaterialUploadResult1 = wxMpService.getMaterialService()
.materialNewsUpload( wxMpMaterialNews );
//推送开始
WxMpMassTagMessage massMessage = new WxMpMassTagMessage();
massMessage.setMsgType(WxConsts.MassMsgType.MPNEWS);
massMessage.setMediaId(wxMpMaterialUploadResult1.getMediaId());
massMessage.setSendAll(true);
WxMpMassSendResult massResult = wxMpService.getMassMessageService()
.massGroupMessageSend(massMessage);
if(!massResult.getErrorCode().equals("0")) {
log.info("error:"+massResult.getErrorMsg());
throw new ErrorRequestException("发送失败");
}
log.info( "massResult : {}", JSONUtil.toJsonStr( massResult ) );
log.info( "wxMpMaterialUploadResult : {}", JSONUtil.toJsonStr( wxMpMaterialUploadResult1 ) );
}
示例12
@Override
public WxMpMassSendResult massGroupMessageSend(WxMpMassTagMessage message) throws WxErrorException {
String responseContent = this.wxMpService.post(WxMpMassMessageService.MESSAGE_MASS_SENDALL_URL, message.toJson());
return WxMpMassSendResult.fromJson(responseContent);
}
示例13
@Override
public WxMpMassSendResult massOpenIdsMessageSend(WxMpMassOpenIdsMessage message) throws WxErrorException {
String responseContent = this.wxMpService.post(MESSAGE_MASS_SEND_URL, message.toJson());
return WxMpMassSendResult.fromJson(responseContent);
}
示例14
@Override
public WxMpMassSendResult massMessagePreview(WxMpMassPreviewMessage wxMpMassPreviewMessage) throws WxErrorException {
String responseContent = this.wxMpService.post(MESSAGE_MASS_PREVIEW_URL, wxMpMassPreviewMessage.toJson());
return WxMpMassSendResult.fromJson(responseContent);
}
示例15
public WxMpMassSendResult massGroupMessageSend(WxMpMassGroupMessage message) throws WxErrorException {
String url = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall";
String responseContent = execute(new SimplePostRequestExecutor(), url, message.toJson());
return WxMpMassSendResult.fromJson(responseContent);
}
示例16
public WxMpMassSendResult massOpenIdsMessageSend(WxMpMassOpenIdsMessage message) throws WxErrorException {
String url = "https://api.weixin.qq.com/cgi-bin/message/mass/send";
String responseContent = execute(new SimplePostRequestExecutor(), url, message.toJson());
return WxMpMassSendResult.fromJson(responseContent);
}
示例17
/**
* <pre>
* 分组群发消息.
* 如果发送图文消息,必须先使用 {@link #massNewsUpload(WxMpMassNews)} 获得media_id,然后再发送
* 如果发送视频消息,必须先使用 {@link #massVideoUpload(WxMpMassVideo)} 获得media_id,然后再发送
* 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140549&token=&lang=zh_CN
* </pre>
*/
WxMpMassSendResult massGroupMessageSend(WxMpMassTagMessage message) throws WxErrorException;
示例18
/**
* <pre>
* 按openId列表群发消息.
* 如果发送图文消息,必须先使用 {@link #massNewsUpload(WxMpMassNews)} 获得media_id,然后再发送
* 如果发送视频消息,必须先使用 {@link #massVideoUpload(WxMpMassVideo)} 获得media_id,然后再发送
* 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140549&token=&lang=zh_CN
* </pre>
*/
WxMpMassSendResult massOpenIdsMessageSend(WxMpMassOpenIdsMessage message) throws WxErrorException;
示例19
/**
* <pre>
* 群发消息预览接口.
* 开发者可通过该接口发送消息给指定用户,在手机端查看消息的样式和排版。为了满足第三方平台开发者的需求,在保留对openID预览能力的同时,增加了对指定微信号发送预览的能力,但该能力每日调用次数有限制(100次),请勿滥用。
* 接口调用请求说明
* http请求方式: POST
* https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token=ACCESS_TOKEN
* 详情请见:http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140549&token=&lang=zh_CN
* </pre>
*
* @return wxMpMassSendResult
*/
WxMpMassSendResult massMessagePreview(WxMpMassPreviewMessage wxMpMassPreviewMessage) throws WxErrorException;