JAVA微信公众号开发之客服消息
生活随笔
收集整理的這篇文章主要介紹了
JAVA微信公众号开发之客服消息
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
微信公眾號(hào)客服消息
1、用戶發(fā)送信息
2、點(diǎn)擊自定義菜單(僅有點(diǎn)擊推事件、掃碼推事件、掃碼推事件且彈出“消息接收中”提示框這3種菜單類型是會(huì)觸發(fā)客服接口的)
3、關(guān)注公眾號(hào)
4、掃描二維碼
5、支付成功
6、用戶維權(quán)
?
接口調(diào)用請(qǐng)求說明
http請(qǐng)求方式:?POST https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN各消息類型所需的JSON數(shù)據(jù)包如下:
發(fā)送文本消息
{"touser":"OPENID","msgtype":"text","text":{"content":"Hello?World"} }發(fā)送圖片消息
{"touser":"OPENID","msgtype":"image","image":{"media_id":"MEDIA_ID"} }發(fā)送語(yǔ)音消息
{"touser":"OPENID","msgtype":"voice","voice":{"media_id":"MEDIA_ID"} }發(fā)送視頻消息
{"touser":"OPENID","msgtype":"video","video":{"media_id":"MEDIA_ID","thumb_media_id":"MEDIA_ID","title":"TITLE","description":"DESCRIPTION"} }發(fā)送音樂消息
{"touser":"OPENID","msgtype":"music","music":{"title":"MUSIC_TITLE","description":"MUSIC_DESCRIPTION","musicurl":"MUSIC_URL","hqmusicurl":"HQ_MUSIC_URL","thumb_media_id":"THUMB_MEDIA_ID"?} }發(fā)送圖文消息(點(diǎn)擊跳轉(zhuǎn)到外鏈) 圖文消息條數(shù)限制在8條以內(nèi),注意,如果圖文數(shù)超過8,則將會(huì)無響應(yīng)。
{"touser":"OPENID","msgtype":"news","news":{"articles":?[{"title":"Happy?Day","description":"Is?Really?A?Happy?Day","url":"URL","picurl":"PIC_URL"},{"title":"Happy?Day","description":"Is?Really?A?Happy?Day","url":"URL","picurl":"PIC_URL"}]} }發(fā)送圖文消息(點(diǎn)擊跳轉(zhuǎn)到圖文消息頁(yè)面) 圖文消息條數(shù)限制在8條以內(nèi),注意,如果圖文數(shù)超過8,則將會(huì)無響應(yīng)。
{"touser":"OPENID","msgtype":"mpnews","mpnews":{"media_id":"MEDIA_ID"} }發(fā)送卡券
{"touser":"OPENID",?"msgtype":"wxcard","wxcard":{??????????????"card_id":"123dsdajkasd231jhksad"????????}, }| button | 是 | 一級(jí)菜單數(shù)組,個(gè)數(shù)應(yīng)為1~3個(gè) |
| sub_button | 否 | 二級(jí)菜單數(shù)組,個(gè)數(shù)應(yīng)為1~5個(gè) |
| type | 是 | 菜單的響應(yīng)動(dòng)作類型,view表示網(wǎng)頁(yè)類型,click表示點(diǎn)擊類型,miniprogram表示小程序類型 |
| name | 是 | 菜單標(biāo)題,不超過16個(gè)字節(jié),子菜單不超過60個(gè)字節(jié) |
| key | click等點(diǎn)擊類型必須 | 菜單KEY值,用于消息接口推送,不超過128字節(jié) |
| url | view、miniprogram類型必須 | 網(wǎng)頁(yè)鏈接,用戶點(diǎn)擊菜單可打開鏈接,不超過1024字節(jié)。type為miniprogram時(shí),不支持小程序的老版本客戶端將打開本url。 |
| media_id | media_id類型和view_limited類型必須 | 調(diào)用新增永久素材接口返回的合法media_id |
| appid | miniprogram類型必須 | 小程序的appid(僅認(rèn)證公眾號(hào)可配置) |
| pagepath | miniprogram類型必須 | 小程序的頁(yè)面路徑 |
創(chuàng)建一個(gè)客服實(shí)體類,然后組裝成json字符串發(fā)給微信服務(wù)器
? public class Custom { private String touser; private String msgtype; private Text text; public String getTouser() { return touser; } public void setTouser(String touser) { this.touser = touser; } public String getMsgtype() { return msgtype; } public void setMsgtype(String msgtype) { this.msgtype = msgtype; } public Text getText() { return text; } public void setText(Text text) { this.text = text; } } public static String createCustom(String openId,String content,String accessToken){Custom custom = new Custom();Text text = new Text();text.setContent(content);custom.setMsgtype(MESSAGE_TEXT);custom.setTouser(openId);custom.setText(text);String url = CUSTOM.replace("ACCESS_TOKEN", accessToken);//獲取accesstoken在地圖那篇文章里有介紹JSONObject jsonObject = SignUtil.doPostStr(url, JSONObject.fromObject(custom).toString());System.out.println(jsonObject);return jsonObject.toString();} /*** post請(qǐng)求*/public static JSONObject doPostStr(String url,String outStr){DefaultHttpClient httpClient = new DefaultHttpClient();HttpPost httpPost = new HttpPost(url);JSONObject jsonObject = null;String result="";try {httpPost.setEntity(new StringEntity(outStr,"utf-8"));HttpResponse response = httpClient.execute(httpPost);result = EntityUtils.toString(response.getEntity(),"utf-8");} catch (Exception e) {} jsonObject = JSONObject.fromObject(result);return jsonObject;}
所有事件都是返回到在公眾號(hào)里服務(wù)器配置的回調(diào)接口方法,需重寫httpservlet的doPost方法
最近在整理一些資源工具,放在網(wǎng)站分享?http://tools.maqway.com
歡迎關(guān)注公眾號(hào):麻雀唯伊 , 不定時(shí)更新資源文章,生活優(yōu)惠,或許有你想看的
?
?
總結(jié)
以上是生活随笔為你收集整理的JAVA微信公众号开发之客服消息的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux查看riak版本,riak源码
- 下一篇: 闭关修炼(四)并发包/类