#921 企业微信发送应用消息接口支持Markdown消息格式
This commit is contained in:
@@ -10,7 +10,6 @@ import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import me.chanjar.weixin.common.bean.WxJsapiSignature;
|
||||
import me.chanjar.weixin.common.error.WxError;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
@@ -141,9 +140,10 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
|
||||
public WxCpMessageSendResult messageSend(WxCpMessage message) throws WxErrorException {
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/message/send";
|
||||
Integer agentId = message.getAgentId();
|
||||
if(null == agentId){
|
||||
if (null == agentId) {
|
||||
message.setAgentId(this.getWxCpConfigStorage().getAgentId());
|
||||
}
|
||||
|
||||
return WxCpMessageSendResult.fromJson(this.post(url, message.toJson()));
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
|
||||
}
|
||||
|
||||
/**
|
||||
* 向微信端发送请求,在这里执行的策略是当发生access_token过期时才去刷新,然后重新执行请求,而不是全局定时请求
|
||||
* 向微信端发送请求,在这里执行的策略是当发生access_token过期时才去刷新,然后重新执行请求,而不是全局定时请求.
|
||||
*/
|
||||
@Override
|
||||
public <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException {
|
||||
|
||||
@@ -10,6 +10,7 @@ import me.chanjar.weixin.cp.bean.article.MpnewsArticle;
|
||||
import me.chanjar.weixin.cp.bean.article.NewArticle;
|
||||
import me.chanjar.weixin.cp.bean.messagebuilder.FileBuilder;
|
||||
import me.chanjar.weixin.cp.bean.messagebuilder.ImageBuilder;
|
||||
import me.chanjar.weixin.cp.bean.messagebuilder.MarkdownMsgBuilder;
|
||||
import me.chanjar.weixin.cp.bean.messagebuilder.MpnewsBuilder;
|
||||
import me.chanjar.weixin.cp.bean.messagebuilder.NewsBuilder;
|
||||
import me.chanjar.weixin.cp.bean.messagebuilder.TextBuilder;
|
||||
@@ -94,6 +95,13 @@ public class WxCpMessage implements Serializable {
|
||||
return new MpnewsBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得markdown消息builder.
|
||||
*/
|
||||
public static MarkdownMsgBuilder MARKDOWN() {
|
||||
return new MarkdownMsgBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得文件消息builder.
|
||||
*/
|
||||
@@ -112,6 +120,7 @@ public class WxCpMessage implements Serializable {
|
||||
* {@link WxConsts.KefuMsgType#VIDEO}
|
||||
* {@link WxConsts.KefuMsgType#NEWS}
|
||||
* {@link WxConsts.KefuMsgType#MPNEWS}
|
||||
* {@link WxConsts.KefuMsgType#MARKDOWN}
|
||||
* </pre>
|
||||
*
|
||||
* @param msgType 消息类型
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package me.chanjar.weixin.cp.bean.messagebuilder;
|
||||
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.cp.bean.WxCpMessage;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* markdown类型的消息builder
|
||||
* Created by Binary Wang on 2019/1/20.
|
||||
* </pre>
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public class MarkdownMsgBuilder extends BaseBuilder<MarkdownMsgBuilder> {
|
||||
private String content;
|
||||
|
||||
public MarkdownMsgBuilder() {
|
||||
this.msgType = WxConsts.KefuMsgType.MARKDOWN;
|
||||
}
|
||||
|
||||
public MarkdownMsgBuilder content(String content) {
|
||||
this.content = content;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpMessage build() {
|
||||
WxCpMessage m = super.build();
|
||||
m.setContent(this.content);
|
||||
return m;
|
||||
}
|
||||
}
|
||||
@@ -8,14 +8,19 @@
|
||||
*/
|
||||
package me.chanjar.weixin.cp.util.json;
|
||||
|
||||
import com.google.gson.*;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.cp.bean.WxCpMessage;
|
||||
import me.chanjar.weixin.cp.bean.article.MpnewsArticle;
|
||||
import me.chanjar.weixin.cp.bean.article.NewArticle;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* @author Daniel Qian
|
||||
@@ -37,12 +42,19 @@ public class WxCpMessageGsonAdapter implements JsonSerializer<WxCpMessage> {
|
||||
if (StringUtils.isNotBlank(message.getToTag())) {
|
||||
messageJson.addProperty("totag", message.getToTag());
|
||||
}
|
||||
|
||||
if (WxConsts.KefuMsgType.TEXT.equals(message.getMsgType())) {
|
||||
JsonObject text = new JsonObject();
|
||||
text.addProperty("content", message.getContent());
|
||||
messageJson.add("text", text);
|
||||
}
|
||||
|
||||
if (WxConsts.KefuMsgType.MARKDOWN.equals(message.getMsgType())) {
|
||||
JsonObject text = new JsonObject();
|
||||
text.addProperty("content", message.getContent());
|
||||
messageJson.add("markdown", text);
|
||||
}
|
||||
|
||||
if (WxConsts.KefuMsgType.TEXTCARD.equals(message.getMsgType())) {
|
||||
JsonObject text = new JsonObject();
|
||||
text.addProperty("title", message.getTitle());
|
||||
|
||||
Reference in New Issue
Block a user