package com.agileai.weixin.custom; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import com.agileai.weixin.core.MessageEventHandler; import com.agileai.weixin.model.TextMessage; import com.agileai.weixin.model.Constans.ReqType; import com.agileai.weixin.tool.MessageBuilder; publicclass BizMessageEventHandler extends MessageEventHandler { protectedstatic List<String> RecognizableText = new ArrayList<String>(); public BizMessageEventHandler(){ if (RecognizableText.isEmpty()){ RecognizableText.add("1"); RecognizableText.add("2"); RecognizableText.add("3"); RecognizableText.add("4"); RecognizableText.add("5"); } } public String handleSubscribe(Map<String, String> requestMap){ String result = null; String fromUserName = requestMap.get("FromUserName"); String toUserName = requestMap.get("ToUserName"); TextMessage textMessage = new TextMessage(); textMessage.setToUserName(fromUserName); textMessage.setFromUserName(toUserName); textMessage.setCreateTime(new Date().getTime()); textMessage.setMsgType(ReqType.TEXT); textMessage.setFuncFlag(0); StringBuffer contentMsg = new StringBuffer(); contentMsg.append("多謝關注!瀋陽數通暢聯軟件技術有限公司是耕耘於軟件集成領域的專業技術團隊,以「分享SOA平臺軟件、傳遞敏捷集成機制」爲使命,但願以自身所長,爲客戶和夥伴提供從數據層、服務層、應用層、流程層、交互層全方位的產品和技術解決方案。"); contentMsg.append("歡迎訪問<a href=\"http://www.agileai.com\">手機網站</a>。"); textMessage.setContent(contentMsg.toString()); result = MessageBuilder.textMessageToXml(textMessage); return result; } public String handleTextMessage(Map<String, String> requestMap){ String result = null; String content = requestMap.get("Content"); if (RecognizableText.contains(content)){ String fromUserName = requestMap.get("FromUserName"); String toUserName = requestMap.get("ToUserName"); TextMessage textMessage = new TextMessage(); textMessage.setToUserName(fromUserName); textMessage.setFromUserName(toUserName); textMessage.setCreateTime(new Date().getTime()); textMessage.setMsgType(ReqType.TEXT); textMessage.setFuncFlag(0); StringBuffer contentMsg = new StringBuffer(); contentMsg.append("親,您的輸入是").append(content); textMessage.setContent(contentMsg.toString()); result = MessageBuilder.textMessageToXml(textMessage); }else{ String fromUserName = requestMap.get("FromUserName"); String toUserName = requestMap.get("ToUserName"); TextMessage textMessage = new TextMessage(); textMessage.setToUserName(fromUserName); textMessage.setFromUserName(toUserName); textMessage.setCreateTime(new Date().getTime()); textMessage.setMsgType(ReqType.TEXT); textMessage.setFuncFlag(0); StringBuffer contentMsg = new StringBuffer(); contentMsg.append("親,您的輸入不能被識別:)"); textMessage.setContent(contentMsg.toString()); result = MessageBuilder.textMessageToXml(textMessage); } return result; } public String handleLocationEvent(Map<String, String> requestMap){ String result = null; String openId = requestMap.get("FromUserName"); double latitude = Double.parseDouble(requestMap.get("Latitude")); double longitude = Double.parseDouble(requestMap.get("Longitude")); double precision = Double.parseDouble(requestMap.get("Precision")); HashMap<String,Object> row = new HashMap<String,Object>(); row.put("Latitude",latitude); row.put("Longitude",longitude); row.put("Precision",precision); row.put("receiveTime",new Date()); LocationCache.put(openId, row); return result; } public String handleMenuClickEvent(String eventKey,Map<String, String> requestMap){ String result = null; if ("MyWork".equals(eventKey)){ String fromUserName = requestMap.get("FromUserName"); String toUserName = requestMap.get("ToUserName"); TextMessage textMessage = new TextMessage(); textMessage.setToUserName(fromUserName); textMessage.setFromUserName(toUserName); textMessage.setCreateTime(new Date().getTime()); textMessage.setMsgType(ReqType.TEXT); textMessage.setFuncFlag(0); StringBuffer contentMsg = new StringBuffer(); contentMsg.append("個人工做包括全部該用戶的工做相關功能,如:個人待辦、個人待閱、個人信息、個人日程、個人客戶、個人訂閱等,目前正在集成中……").append("\n"); textMessage.setContent(contentMsg.toString()); result = MessageBuilder.textMessageToXml(textMessage); } return result; } } |