JAVA微信公众号开发之客服消息
生活随笔
收集整理的這篇文章主要介紹了
JAVA微信公众号开发之客服消息
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
微信公眾號客服消息
1、用戶發送信息
2、點擊自定義菜單(僅有點擊推事件、掃碼推事件、掃碼推事件且彈出“消息接收中”提示框這3種菜單類型是會觸發客服接口的)
3、關注公眾號
4、掃描二維碼
5、支付成功
6、用戶維權
?
接口調用請求說明
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"} }發送圖片消息
{"touser":"OPENID","msgtype":"image","image":{"media_id":"MEDIA_ID"} }發送語音消息
{"touser":"OPENID","msgtype":"voice","voice":{"media_id":"MEDIA_ID"} }發送視頻消息
{"touser":"OPENID","msgtype":"video","video":{"media_id":"MEDIA_ID","thumb_media_id":"MEDIA_ID","title":"TITLE","description":"DESCRIPTION"} }發送音樂消息
{"touser":"OPENID","msgtype":"music","music":{"title":"MUSIC_TITLE","description":"MUSIC_DESCRIPTION","musicurl":"MUSIC_URL","hqmusicurl":"HQ_MUSIC_URL","thumb_media_id":"THUMB_MEDIA_ID"?} }發送圖文消息(點擊跳轉到外鏈) 圖文消息條數限制在8條以內,注意,如果圖文數超過8,則將會無響應。
{"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"}]} }發送圖文消息(點擊跳轉到圖文消息頁面) 圖文消息條數限制在8條以內,注意,如果圖文數超過8,則將會無響應。
{"touser":"OPENID","msgtype":"mpnews","mpnews":{"media_id":"MEDIA_ID"} }發送卡券
{"touser":"OPENID",?"msgtype":"wxcard","wxcard":{??????????????"card_id":"123dsdajkasd231jhksad"????????}, }| button | 是 | 一級菜單數組,個數應為1~3個 |
| sub_button | 否 | 二級菜單數組,個數應為1~5個 |
| type | 是 | 菜單的響應動作類型,view表示網頁類型,click表示點擊類型,miniprogram表示小程序類型 |
| name | 是 | 菜單標題,不超過16個字節,子菜單不超過60個字節 |
| key | click等點擊類型必須 | 菜單KEY值,用于消息接口推送,不超過128字節 |
| url | view、miniprogram類型必須 | 網頁鏈接,用戶點擊菜單可打開鏈接,不超過1024字節。type為miniprogram時,不支持小程序的老版本客戶端將打開本url。 |
| media_id | media_id類型和view_limited類型必須 | 調用新增永久素材接口返回的合法media_id |
| appid | miniprogram類型必須 | 小程序的appid(僅認證公眾號可配置) |
| pagepath | miniprogram類型必須 | 小程序的頁面路徑 |
創建一個客服實體類,然后組裝成json字符串發給微信服務器
? 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請求*/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;}
所有事件都是返回到在公眾號里服務器配置的回調接口方法,需重寫httpservlet的doPost方法
最近在整理一些資源工具,放在網站分享?http://tools.maqway.com
歡迎關注公眾號:麻雀唯伊 , 不定時更新資源文章,生活優惠,或許有你想看的
?
?
總結
以上是生活随笔為你收集整理的JAVA微信公众号开发之客服消息的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux查看riak版本,riak源码
- 下一篇: 闭关修炼(四)并发包/类