#760 小程序增加统一服务消息接口

This commit is contained in:
Binary Wang
2018-09-23 18:16:51 +08:00
parent b8e9d9d2c4
commit e237f0be68
12 changed files with 430 additions and 55 deletions

View File

@@ -2,6 +2,7 @@ package cn.binarywang.wx.miniapp.api;
import cn.binarywang.wx.miniapp.bean.WxMaKefuMessage;
import cn.binarywang.wx.miniapp.bean.WxMaTemplateMessage;
import cn.binarywang.wx.miniapp.bean.WxMaUniformMessage;
import me.chanjar.weixin.common.error.WxErrorException;
/**
@@ -14,6 +15,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 UNIFORM_MSG_SEND_URL = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send";
/**
* <pre>
@@ -32,4 +34,14 @@ public interface WxMaMsgService {
* </pre>
*/
void sendTemplateMsg(WxMaTemplateMessage templateMessage) throws WxErrorException;
/**
* <pre>
* 下发小程序和公众号统一的服务消息
* 详情请见: <a href="https://developers.weixin.qq.com/miniprogram/dev/api/open-api/uniform-message/sendUniformMessage.html">下发小程序和公众号统一的服务消息</a>
* 接口url格式https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=ACCESS_TOKEN
* </pre>
*/
void sendUniformMsg(WxMaUniformMessage uniformMessage) throws WxErrorException;
}

View File

@@ -4,6 +4,7 @@ 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.WxMaTemplateMessage;
import cn.binarywang.wx.miniapp.bean.WxMaUniformMessage;
import cn.binarywang.wx.miniapp.constant.WxMaConstants;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
@@ -36,4 +37,13 @@ public class WxMaMsgServiceImpl implements WxMaMsgService {
}
}
@Override
public void sendUniformMsg(WxMaUniformMessage uniformMessage) throws WxErrorException {
String responseContent = this.wxMaService.post(UNIFORM_MSG_SEND_URL, uniformMessage.toJson());
JsonObject jsonObject = JSON_PARSER.parse(responseContent).getAsJsonObject();
if (jsonObject.get(WxMaConstants.ERRCODE).getAsInt() != 0) {
throw new WxErrorException(WxError.fromJson(responseContent));
}
}
}