mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
✨ #1239 增加微信小程序订阅消息发送接口
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package cn.binarywang.wx.miniapp.api;
|
||||
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaKefuMessage;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaTemplateMessage;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaUniformMessage;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
@@ -15,6 +16,7 @@ import me.chanjar.weixin.common.error.WxErrorException;
|
||||
public interface WxMaMsgService {
|
||||
String KEFU_MESSAGE_SEND_URL = "https://api.weixin.qq.com/cgi-bin/message/custom/send";
|
||||
String TEMPLATE_MSG_SEND_URL = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send";
|
||||
String SUBSCRIBE_MSG_SEND_URL = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send";
|
||||
String UNIFORM_MSG_SEND_URL = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send";
|
||||
|
||||
/**
|
||||
@@ -36,6 +38,15 @@ public interface WxMaMsgService {
|
||||
void sendTemplateMsg(WxMaTemplateMessage templateMessage) throws WxErrorException;
|
||||
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.send.html
|
||||
* </pre>
|
||||
* 发送订阅消息
|
||||
*/
|
||||
void sendSubscribeMsg(WxMaSubscribeMessage subscribeMessage) throws WxErrorException;
|
||||
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 下发小程序和公众号统一的服务消息
|
||||
|
||||
@@ -3,6 +3,7 @@ package cn.binarywang.wx.miniapp.api.impl;
|
||||
import cn.binarywang.wx.miniapp.api.WxMaMsgService;
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaKefuMessage;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaTemplateMessage;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaUniformMessage;
|
||||
import cn.binarywang.wx.miniapp.constant.WxMaConstants;
|
||||
@@ -27,6 +28,11 @@ public class WxMaMsgServiceImpl implements WxMaMsgService {
|
||||
return responseContent != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 小程序模板消息接口将于2020年1月10日下线,开发者可使用订阅消息功能
|
||||
* </pre>
|
||||
*/
|
||||
@Override
|
||||
public void sendTemplateMsg(WxMaTemplateMessage templateMessage) throws WxErrorException {
|
||||
String responseContent = this.wxMaService.post(TEMPLATE_MSG_SEND_URL, templateMessage.toJson());
|
||||
@@ -36,6 +42,15 @@ public class WxMaMsgServiceImpl implements WxMaMsgService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendSubscribeMsg(WxMaSubscribeMessage subscribeMessage) throws WxErrorException {
|
||||
String responseContent = this.wxMaService.post(SUBSCRIBE_MSG_SEND_URL, subscribeMessage.toJson());
|
||||
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
|
||||
if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) {
|
||||
throw new WxErrorException(WxError.fromJson(responseContent, WxType.MiniApp));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendUniformMsg(WxMaUniformMessage uniformMessage) throws WxErrorException {
|
||||
String responseContent = this.wxMaService.post(UNIFORM_MSG_SEND_URL, uniformMessage.toJson());
|
||||
|
||||
Reference in New Issue
Block a user