forked from binarywang/WxJava
-
Notifications
You must be signed in to change notification settings - Fork 0
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
e6a3f60
commit 2a7c977
Showing
6 changed files
with
197 additions
and
140 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpMassMessageService.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,95 @@ | ||
package me.chanjar.weixin.mp.api; | ||
|
||
import me.chanjar.weixin.common.exception.WxErrorException; | ||
import me.chanjar.weixin.mp.bean.*; | ||
import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; | ||
import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; | ||
|
||
/** | ||
* <pre> | ||
* 群发消息服务类 | ||
* Created by Binary Wang on 2017-8-16. | ||
* </pre> | ||
* | ||
* @author <a href="https://github.com/binarywang">Binary Wang</a> | ||
*/ | ||
public interface WxMpMassMessageService { | ||
/** | ||
* 上传群发用的图文消息 | ||
*/ | ||
String MEDIA_UPLOAD_NEWS_URL = "https://api.weixin.qq.com/cgi-bin/media/uploadnews"; | ||
/** | ||
* 上传群发用的视频 | ||
*/ | ||
String MEDIA_UPLOAD_VIDEO_URL = "https://api.weixin.qq.com/cgi-bin/media/uploadvideo"; | ||
/** | ||
* 分组群发消息 | ||
*/ | ||
String MESSAGE_MASS_SENDALL_URL = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall"; | ||
/** | ||
* 按openId列表群发消息 | ||
*/ | ||
String MESSAGE_MASS_SEND_URL = "https://api.weixin.qq.com/cgi-bin/message/mass/send"; | ||
/** | ||
* 群发消息预览接口 | ||
*/ | ||
String MESSAGE_MASS_PREVIEW_URL = "https://api.weixin.qq.com/cgi-bin/message/mass/preview"; | ||
|
||
/** | ||
* <pre> | ||
* 上传群发用的图文消息,上传后才能群发图文消息 | ||
* | ||
* 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140549&token=&lang=zh_CN | ||
* </pre> | ||
* | ||
* @see #massGroupMessageSend(WxMpMassTagMessage) | ||
* @see #massOpenIdsMessageSend(WxMpMassOpenIdsMessage) | ||
*/ | ||
WxMpMassUploadResult massNewsUpload(WxMpMassNews news) throws WxErrorException; | ||
|
||
/** | ||
* <pre> | ||
* 上传群发用的视频,上传后才能群发视频消息 | ||
* 详情请见: http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140549&token=&lang=zh_CN | ||
* </pre> | ||
* | ||
* @see #massGroupMessageSend(WxMpMassTagMessage) | ||
* @see #massOpenIdsMessageSend(WxMpMassOpenIdsMessage) | ||
*/ | ||
WxMpMassUploadResult massVideoUpload(WxMpMassVideo video) throws WxErrorException; | ||
|
||
/** | ||
* <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; | ||
|
||
/** | ||
* <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; | ||
|
||
/** | ||
* <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 Exception; | ||
|
||
} |
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
58 changes: 58 additions & 0 deletions
58
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpMassMessageServiceImpl.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,58 @@ | ||
package me.chanjar.weixin.mp.api.impl; | ||
|
||
import me.chanjar.weixin.common.exception.WxErrorException; | ||
import me.chanjar.weixin.mp.api.WxMpMassMessageService; | ||
import me.chanjar.weixin.mp.api.WxMpService; | ||
import me.chanjar.weixin.mp.bean.*; | ||
import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; | ||
import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* <pre> | ||
* 群发消息服务类 | ||
* Created by Binary Wang on 2017-8-16. | ||
* </pre> | ||
* | ||
* @author <a href="https://github.com/binarywang">Binary Wang</a> | ||
*/ | ||
public class WxMpMassMessageServiceImpl implements WxMpMassMessageService { | ||
protected final Logger log = LoggerFactory.getLogger(this.getClass()); | ||
private WxMpService wxMpService; | ||
|
||
public WxMpMassMessageServiceImpl(WxMpService wxMpService) { | ||
this.wxMpService = wxMpService; | ||
} | ||
|
||
@Override | ||
public WxMpMassUploadResult massNewsUpload(WxMpMassNews news) throws WxErrorException { | ||
String responseContent = this.wxMpService.post(MEDIA_UPLOAD_NEWS_URL, news.toJson()); | ||
return WxMpMassUploadResult.fromJson(responseContent); | ||
} | ||
|
||
@Override | ||
public WxMpMassUploadResult massVideoUpload(WxMpMassVideo video) throws WxErrorException { | ||
String responseContent = this.wxMpService.post(MEDIA_UPLOAD_VIDEO_URL, video.toJson()); | ||
return WxMpMassUploadResult.fromJson(responseContent); | ||
} | ||
|
||
@Override | ||
public WxMpMassSendResult massGroupMessageSend(WxMpMassTagMessage message) throws WxErrorException { | ||
String responseContent = this.wxMpService.post(WxMpMassMessageService.MESSAGE_MASS_SENDALL_URL, message.toJson()); | ||
return WxMpMassSendResult.fromJson(responseContent); | ||
} | ||
|
||
@Override | ||
public WxMpMassSendResult massOpenIdsMessageSend(WxMpMassOpenIdsMessage message) throws WxErrorException { | ||
String responseContent = this.wxMpService.post(MESSAGE_MASS_SEND_URL, message.toJson()); | ||
return WxMpMassSendResult.fromJson(responseContent); | ||
} | ||
|
||
@Override | ||
public WxMpMassSendResult massMessagePreview(WxMpMassPreviewMessage wxMpMassPreviewMessage) throws Exception { | ||
String responseContent = this.wxMpService.post(MESSAGE_MASS_PREVIEW_URL, wxMpMassPreviewMessage.toJson()); | ||
return WxMpMassSendResult.fromJson(responseContent); | ||
} | ||
|
||
} |
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
Oops, something went wrong.