日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

JAVA微信公众号开发之客服消息

發(fā)布時(shí)間:2023/12/14 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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"????????}, } 參數(shù)是否必須說明
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é)
keyclick等點(diǎn)擊類型必須菜單KEY值,用于消息接口推送,不超過128字節(jié)
urlview、miniprogram類型必須網(wǎng)頁(yè)鏈接,用戶點(diǎn)擊菜單可打開鏈接,不超過1024字節(jié)。type為miniprogram時(shí),不支持小程序的老版本客戶端將打開本url。
media_idmedia_id類型和view_limited類型必須調(diào)用新增永久素材接口返回的合法media_id
appidminiprogram類型必須小程序的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方法

? public void doPost(HttpServletRequest req,HttpServletResponse resp) throws IOException { req.setCharacterEncoding("UTF-8"); resp.setCharacterEncoding("UTF-8"); String serverPath=""; PrintWriter out = resp.getWriter(); //String openId = GetCookie.getCookie(req,resp); Map<String, String> map; try { map = MessageUtil.xmlToMap(req);//微信以xml形式轉(zhuǎn)過來需要轉(zhuǎn)化,下面給方法 String fromUserName = map.get("FromUserName");//來自誰的消息 System.out.println(fromUserName); String toUserName = map.get("ToUserName");//微信公眾號(hào) String msgType = map.get("MsgType");//消息類型,下面有介紹類型 //String content = map.get("Content");//內(nèi)容 String message = ""; if(MessageUtil.MESSAGE_EVENT.equals(msgType)){ System.out.println("事件"); String eventType = map.get("Event"); System.out.println(eventType); String eventKey = map.get("EventKey"); System.out.println(map.get("EventKey")); if(MessageUtil.MESSAGE_CLICK.equals(eventType)){ String key = map.get("EventKey"); String accessToken = "",//獲取accessToken if(key.equals("2")){ String content = "內(nèi)容"; ? ?MessageUtil.createCustom(fromUserName, content, accessToken); }else{ return; } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } ? ?MessageUtil.createCustom(fromUserName, content, accessToken); }else{ return; } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }

最近在整理一些資源工具,放在網(wǎng)站分享?http://tools.maqway.com
歡迎關(guān)注公眾號(hào):麻雀唯伊 , 不定時(shí)更新資源文章,生活優(yōu)惠,或許有你想看的

?

?

總結(jié)

以上是生活随笔為你收集整理的JAVA微信公众号开发之客服消息的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。