客服接口-发消息
接口调用请求说明
http请求方式: POST
https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN
各消息类型所需的JSON数据包如下:
发送文本消息
{
"touser":"OPENID",
"msgtype":"text",
"text":
{
"content":"Hello World"
}
}
代码中json系列化代码
public static void asJson(Writer writer, WxOutMsg msg) {
NutMap map = new NutMap();
map.put("touser", msg.getToUserName());
map.put("msgtype", msg.getMsgType());
switch (WxMsgType.valueOf(msg.getMsgType())) {
case text:
map.put("text", new NutMap().setv("content", msg.getContent()));
break;
case image:
map.put("image", new NutMap().setv("media_id", msg.getImage().getMediaId()));
break;
case voice:
map.put("voice", new NutMap().setv("media_id", msg.getVoice().getMediaId()));
break;
case video:
NutMap _video = new NutMap();
_video.setv("media_id", msg.getVideo().getMediaId());
if (msg.getVideo().getTitle() != null)
_video.put("title", (msg.getVideo().getTitle()));
if (msg.getVideo().getDescription() != null)
_video.put("description", (msg.getVideo().getDescription()));
map.put("video", _video);
break;
case music:
NutMap _music = new NutMap();
WxMusic music = msg.getMusic();
if (music.getTitle() != null)
_music.put("title", (music.getTitle()));
if (music.getDescription() != null)
_music.put("description", (music.getDescription()));
if (music.getMusicUrl() != null)
_music.put("musicurl", (music.getMusicUrl()));
if (music.getHQMusicUrl() != null)
_music.put("hqmusicurl", (music.getHQMusicUrl()));
_music.put("thumb_media_id", (music.getThumbMediaId()));
break;
case news:
NutMap _news = new NutMap();
List<NutMap> list = new ArrayList<NutMap>();
for (WxArticle article : msg.getArticles()) {
NutMap item = new NutMap();
if (article.getTitle() != null)
item.put("title", (article.getTitle()));
if (article.getDescription() != null)
item.put("description", (article.getDescription()));
if (article.getPicUrl() != null)
item.put("picurl", (article.getPicUrl()));
if (article.getUrl() != null)
item.put("url", (article.getUrl()));
list.add(item);
}
_news.put("articles", list);
map.put("news", _news);
break;
case mpnews:
map.put("mpnews", new NutMap().setv("media_id", msg.getMedia_id()));
break;
case wxcard:
map.put("wxcard",
new NutMap().setv("card_id", msg.getCard().getId())
.setv("card_ext", msg.getCard().getExt()));
break;
default:
break;
}
Json.toJson(writer, map);
}
也没有序列化fromUser,微信接口也是要求openid的