123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472 |
- package com.yihu.wlyy.wechat.process;
- import com.yihu.wlyy.util.SystemConf;
- import com.yihu.wlyy.wechat.util.WeiXinMessageReplyUtils;
- import com.yihu.wlyy.wechat.util.WeiXinMessageUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.stereotype.Component;
- import java.util.*;
- /**
- * 微信事件处理
- *
- * Created by lyr on 2016/08/11.
- */
- @Component
- public class WeiXinEventProcess {
- /**
- * 微信推送事件处理
- *
- * @param message
- * @return
- */
- public static String eventProcess(Map<String, String> message) throws Exception {
- String result = "";
- String event = message.get("Event");
- switch (event) {
- case WeiXinMessageUtils.EVENT_TYPE_SCAN: // 扫描二维码事件
- result = scanEventProcess(message);
- break;
- case WeiXinMessageUtils.EVENT_TYPE_SUBSCRIBE: // 订阅事件
- if (message.containsKey("EventKey") && StringUtils.isNotEmpty(message.get("EventKey")) && message.containsKey("Ticket")
- && StringUtils.isNotEmpty(message.get("Ticket"))) {
- result = scanEventProcess(message);
- }else{
- result = subscribeEventProcess(message);
- }
- break;
- case WeiXinMessageUtils.EVENT_TYPE_CLICK: //菜单点击
- result = WeiXinEventProcess.clickProcess(message);
- default:
- break;
- }
- return result;
- }
- /**
- * 微信菜单点击处理
- *
- * @param message
- * @return
- */
- public static String clickProcess(Map<String, String> message) throws Exception {
- String result = "";
- if(message.get("EventKey").equals("caozuoshuoming")){
- String tempStr = clickEventProcess(message);
- /*int firsIndex = tempStr.indexOf("<item>");
- String result1 = tempStr.substring(0,firsIndex-1);
- int secondIndex = tempStr.indexOf("<item>",firsIndex+10);
- String result2 = tempStr.substring(secondIndex-1);*/
- result=tempStr.replace("<ArticleCount>5</ArticleCount>","<ArticleCount>4</ArticleCount>");
- }
- if(message.get("EventKey").equals("jiankangdangan")){
- result = clickEventProcessMenu(message);
- }
- return result;
- }
- /**
- * 菜单点击消息发送
- *
- * @param message
- * @return
- * @throws Exception
- */
- private static String clickEventProcess(Map<String,String> message) throws Exception{
- String result = "";
- // 配置信息
- Properties systemConf = SystemConf.getInstance().getSystemProperties();
- // 图文信息
- List<Map<String,String>> articles = new ArrayList<>();
- Map<String,String> articleConsult = new HashMap<>();
- // 图文URL
- String urlConsult = systemConf.getProperty("patient_consult_url");
- // 图文消息图片URL
- String picUrlConsult = systemConf.getProperty("patient_operatinginstrutions_pic_url");
- // URL设置服务器URL、AppId
- urlConsult = urlConsult.replace("{server}", systemConf.getProperty("wechat_base_url"))
- .replace("{appId}", systemConf.getProperty("appId"));
- //图片地址
- picUrlConsult = picUrlConsult.replace("{server}", systemConf.getProperty("server_url"));
- articleConsult.put("Url",urlConsult);
- articleConsult.put("Title", "医生咨询功能使用说明");
- articleConsult.put("Description","功能使用说明");
- articleConsult.put("PicUrl",picUrlConsult);
- articles.add(articleConsult);
- Map<String,String> articleBooking = new HashMap<>();
- // 图文URL
- String urlBooking = systemConf.getProperty("patient_booking_url");
- // 图文消息图片URL
- String picUrlBooking = systemConf.getProperty("patient_booking_pic_url");
- // URL设置服务器URL、AppId
- urlBooking = urlBooking.replace("{server}", systemConf.getProperty("wechat_base_url"))
- .replace("{appId}", systemConf.getProperty("appId"));
- System.out.println("picUrlBooking ===>"+picUrlBooking);
- System.out.println("server_url ===>"+systemConf.getProperty("server_url"));
- //图片地址
- picUrlBooking = picUrlBooking.replace("{server}", systemConf.getProperty("server_url"));
- articleBooking.put("Url",urlBooking);
- articleBooking.put("Title", "预约挂号功能使用说明");
- articleBooking.put("Description","功能使用说明");
- articleBooking.put("PicUrl",picUrlBooking);
- articles.add(articleBooking);
- Map<String,String> articleDevice = new HashMap<>();
- // 图文URL
- String urlDevice = systemConf.getProperty("patient_device_url");
- // 图文消息图片URL
- String picUrlDevice = systemConf.getProperty("patient_device_pic_url");
- // URL设置服务器URL、AppId
- urlDevice = urlDevice.replace("{server}", systemConf.getProperty("wechat_base_url"))
- .replace("{appId}", systemConf.getProperty("appId"));
- //图片地址
- picUrlDevice = picUrlDevice.replace("{server}", systemConf.getProperty("server_url"));
- articleDevice.put("Url",urlDevice);
- articleDevice.put("Title", "体征设备管理功能使用说明");
- articleDevice.put("Description","功能使用说明");
- articleDevice.put("PicUrl",picUrlDevice);
- articles.add(articleDevice);
- Map<String,String> articleFamily = new HashMap<>();
- // 图文URL
- String urlFamily = systemConf.getProperty("patient_family_url");
- // 图文消息图片URL
- String picUrlFamily = systemConf.getProperty("patient_family_pic_url");
- // URL设置服务器URL、AppId
- urlFamily = urlFamily.replace("{server}", systemConf.getProperty("wechat_base_url"))
- .replace("{appId}", systemConf.getProperty("appId"));
- //图片地址
- picUrlFamily = picUrlFamily.replace("{server}", systemConf.getProperty("server_url"));
- articleFamily.put("Url",urlFamily);
- articleFamily.put("Title", "我的家庭功能使用说明");
- articleFamily.put("Description","功能使用说明");
- articleFamily.put("PicUrl",picUrlFamily);
- articles.add(articleFamily);
- // 构建回复消息XML
- result = WeiXinMessageReplyUtils.replyNewsMessage(message.get("FromUserName"),message.get("ToUserName"),articles);
- return result;
- }
- /**
- * 菜单点击消息发送
- *
- * @param message
- * @return
- * @throws Exception
- */
- private static String clickEventProcessMenu(Map<String,String> message) throws Exception{
- String result = "";
- // 配置信息
- Properties systemConf = SystemConf.getInstance().getSystemProperties();
- // 图文信息
- List<Map<String,String>> articles = new ArrayList<>();
- //就诊记录
- Map<String,String> articleVisit = new HashMap<>();
- String visit = systemConf.getProperty("patient_visit_url");
- // 图文消息图片URL
- String visit_pic = systemConf.getProperty("patient_visit_pic");
- // URL设置服务器URL、AppId
- visit = visit.replace("{server}", systemConf.getProperty("wechat_base_url"))
- .replace("{appId}", systemConf.getProperty("appId"));
- //图片地址
- visit_pic = visit_pic.replace("{server}", systemConf.getProperty("server_url"));
- articleVisit.put("Url",visit);
- articleVisit.put("Title", "就诊记录");
- articleVisit.put("Description","就诊记录");
- articleVisit.put("PicUrl",visit_pic);
- articles.add(articleVisit);
- //#检查检验
- Map<String,String> articleInspect = new HashMap<>();
- // 图文URL
- String inspect = systemConf.getProperty("patient_inspect_url");
- // 图文消息图片URL
- String inspect_pic = systemConf.getProperty("patient_inspect_pic");
- // URL设置服务器URL、AppId
- inspect = inspect.replace("{server}", systemConf.getProperty("wechat_base_url"))
- .replace("{appId}", systemConf.getProperty("appId"));
- //图片地址
- inspect_pic = inspect_pic.replace("{server}", systemConf.getProperty("server_url"));
- articleInspect.put("Url",inspect);
- articleInspect.put("Title", "检查检验");
- articleInspect.put("Description","检查检验");
- articleInspect.put("PicUrl",inspect_pic);
- articles.add(articleInspect);
- Map<String,String> articleExamination = new HashMap<>();
- // 图文URL
- String examination = systemConf.getProperty("patient_examination_url");
- // 图文消息图片URL
- String examination_pic = systemConf.getProperty("patient_examination_pic");
- // URL设置服务器URL、AppId
- examination = examination.replace("{server}", systemConf.getProperty("wechat_base_url"))
- .replace("{appId}", systemConf.getProperty("appId"));
- //图片地址
- examination_pic = examination_pic.replace("{server}", systemConf.getProperty("server_url"));
- articleExamination.put("Url",examination);
- articleExamination.put("Title", "社区体检");
- articleExamination.put("Description","社区体检");
- articleExamination.put("PicUrl",examination_pic);
- articles.add(articleExamination);
- // 构建回复消息XML
- result = WeiXinMessageReplyUtils.replyNewsMessage(message.get("FromUserName"),message.get("ToUserName"),articles);
- return result;
- }
- /**
- * 关注事件消息发送
- * @param message
- * @return
- * @throws Exception
- */
- private static String subscribeEventProcess(Map<String,String> message) throws Exception{
- String result = "";
- // 配置信息
- Properties systemConf = SystemConf.getInstance().getSystemProperties();
- // 图文信息
- List<Map<String,String>> articles = new ArrayList<>();
- Map<String,String> article = new HashMap<>();
- // 图文URL
- String url = systemConf.getProperty("doctor_subscribe_url");
- // 图文消息图片URL
- String picUrl = systemConf.getProperty("doctor_qrcode_pic_url");
- // URL设置服务器URL、AppId
- url = url.replace("{server}", systemConf.getProperty("wechat_base_url"))
- .replace("{appId}", systemConf.getProperty("appId"));
- //图片地址
- picUrl = picUrl.replace("{server}", systemConf.getProperty("server_url"));
- article.put("Url",url);
- article.put("Title", "欢迎关注厦门i健康,快来签约家庭医生吧~");
- article.put("Description","请点击查看家庭签约");
- article.put("PicUrl",picUrl);
- articles.add(article);
- //设置URL
- setUrlItems(articles,systemConf);
- // 构建回复消息XML
- result = WeiXinMessageReplyUtils.replyNewsMessage(message.get("FromUserName"),message.get("ToUserName"),articles);
- return result;
- }
- /**
- * 设置微信公共链接
- * @param articles
- */
- public static void setUrlItems(List<Map<String,String>> articles,Properties systemConf){
- Map<String,String> articleConsult = new HashMap<>();
- // 图文URL
- String urlConsult = systemConf.getProperty("patient_consult_url");
- // 图文消息图片URL
- String picUrlConsult = systemConf.getProperty("patient_operatinginstrutions_pic_url");
- // URL设置服务器URL、AppId
- urlConsult = urlConsult.replace("{server}", systemConf.getProperty("wechat_base_url"))
- .replace("{appId}", systemConf.getProperty("appId"));
- //图片地址
- picUrlConsult = picUrlConsult.replace("{server}", systemConf.getProperty("server_url"));
- articleConsult.put("Url",urlConsult);
- articleConsult.put("Title", "医生咨询功能使用说明");
- articleConsult.put("Description","功能使用说明");
- articleConsult.put("PicUrl",picUrlConsult);
- articles.add(articleConsult);
- Map<String,String> articleBooking = new HashMap<>();
- // 图文URL
- String urlBooking = systemConf.getProperty("patient_booking_url");
- // 图文消息图片URL
- String picUrlBooking = systemConf.getProperty("patient_booking_pic_url");
- // URL设置服务器URL、AppId
- urlBooking = urlBooking.replace("{server}", systemConf.getProperty("wechat_base_url"))
- .replace("{appId}", systemConf.getProperty("appId"));
- //图片地址
- picUrlBooking = picUrlBooking.replace("{server}", systemConf.getProperty("server_url"));
- articleBooking.put("Url",urlBooking);
- articleBooking.put("Title", "预约挂号功能使用说明");
- articleBooking.put("Description","功能使用说明");
- articleBooking.put("PicUrl",picUrlBooking);
- articles.add(articleBooking);
- Map<String,String> articleDevice = new HashMap<>();
- // 图文URL
- String urlDevice = systemConf.getProperty("patient_device_url");
- // 图文消息图片URL
- String picUrlDevice = systemConf.getProperty("patient_device_pic_url");
- // URL设置服务器URL、AppId
- urlDevice = urlDevice.replace("{server}", systemConf.getProperty("wechat_base_url"))
- .replace("{appId}", systemConf.getProperty("appId"));
- //图片地址
- picUrlDevice = picUrlDevice.replace("{server}", systemConf.getProperty("server_url"));
- articleDevice.put("Url",urlDevice);
- articleDevice.put("Title", "体征设备管理功能使用说明");
- articleDevice.put("Description","功能使用说明");
- articleDevice.put("PicUrl",picUrlDevice);
- articles.add(articleDevice);
- Map<String,String> articleFamily = new HashMap<>();
- // 图文URL
- String urlFamily = systemConf.getProperty("patient_family_url");
- // 图文消息图片URL
- String picUrlFamily = systemConf.getProperty("patient_family_pic_url");
- // URL设置服务器URL、AppId
- urlFamily = urlFamily.replace("{server}", systemConf.getProperty("wechat_base_url"))
- .replace("{appId}", systemConf.getProperty("appId"));
- //图片地址
- picUrlFamily = picUrlFamily.replace("{server}", systemConf.getProperty("server_url"));
- articleFamily.put("Url",urlFamily);
- articleFamily.put("Title", "我的家庭功能使用说明");
- articleFamily.put("Description","功能使用说明");
- articleFamily.put("PicUrl",picUrlFamily);
- articles.add(articleFamily);
- }
- /**
- * 微信扫码事件处理
- *
- * @param message
- * @return
- * @throws Exception
- */
- private static String scanEventProcess(Map<String, String> message) throws Exception {
- String result = "";
- // 场景值
- String eventKey = message.get("EventKey");
- if(StringUtils.isNotEmpty(eventKey) && (eventKey.startsWith("qr_") ||
- eventKey.startsWith("qrscene_qr_"))) {
- // 配置
- Properties systemConf = SystemConf.getInstance().getSystemProperties();
- // 图文信息
- List<Map<String,String>> articles = new ArrayList<>();
- Map<String,String> article = new HashMap<>();
- // 二维码跳转URL
- String url = systemConf.getProperty("doctor_qrcode_url");
- // 图片URL
- String picUrl = systemConf.getProperty("doctor_qrcode_pic_url");
- // 二维码参数
- String[] keys = eventKey.replace("qrscene_qr_","").replace("qr_","").split("_");
- // 图文消息URL
- url = url.replace("{server}", systemConf.getProperty("wechat_base_url"))
- .replace("{appId}", systemConf.getProperty("appId"))
- .replace("{doctorCode}",keys[0]);
- //图片地址
- picUrl = picUrl.replace("{server}", systemConf.getProperty("server_url"));
- article.put("Url",url);
- article.put("Title",keys[1] + "医生签约");
- article.put("Description","请点击查看医生详情并申请签约");
- article.put("PicUrl",picUrl);
- articles.add(article);
- //设置通用链接
- setUrlItems(articles,systemConf);
- // 消息XML
- result = WeiXinMessageReplyUtils.replyNewsMessage(message.get("FromUserName"),message.get("ToUserName"),articles);
- }else if(StringUtils.isNotEmpty(eventKey) && (eventKey.startsWith("hs_") ||
- eventKey.startsWith("qrscene_hs_"))){
- // 配置信息
- Properties systemConf = SystemConf.getInstance().getSystemProperties();
- // 图文信息
- List<Map<String,String>> articles = new ArrayList<>();
- Map<String,String> article = new HashMap<>();
- // 社区二维码跳转URL
- String url = systemConf.getProperty("doctor_hos_qrcode_url");
- // 图片URL
- String picUrl = systemConf.getProperty("doctor_qrcode_pic_url");
- // 二维码参数
- String[] keys = eventKey.replace("qrscene_hs_","").replace("hs_","").split("_");
- // 图文消息URL
- url = url.replace("{server}", systemConf.getProperty("wechat_base_url"))
- .replace("{appId}", systemConf.getProperty("appId"))
- .replace("{hospital}",keys[0] + ":" + keys[1]);
- //图片地址
- picUrl = picUrl.replace("{server}", systemConf.getProperty("server_url"));
- article.put("Url",url);
- article.put("Title",keys[1]);
- article.put("Description","请点击查看社区详情");
- article.put("PicUrl",picUrl);
- articles.add(article);
- //设置通用链接
- setUrlItems(articles,systemConf);
- // 消息XML
- result = WeiXinMessageReplyUtils.replyNewsMessage(message.get("FromUserName"),message.get("ToUserName"),articles);
- } else if(StringUtils.isNotEmpty(eventKey) && (eventKey.startsWith("tw_") ||
- eventKey.startsWith("qrscene_tw_"))){
- // 配置信息
- Properties systemConf = SystemConf.getInstance().getSystemProperties();
- // 图文信息
- List<Map<String,String>> articles = new ArrayList<>();
- Map<String,String> article = new HashMap<>();
- // 社区二维码跳转URL
- String url = systemConf.getProperty("doctor_town_qrcode_url");
- // 图片URL
- String picUrl = systemConf.getProperty("doctor_qrcode_pic_url");
- // 二维码参数
- String[] keys = eventKey.replace("qrscene_tw_","").replace("tw_","").split("_");
- // 图文消息URL
- url = url.replace("{server}", systemConf.getProperty("wechat_base_url"))
- .replace("{appId}", systemConf.getProperty("appId"))
- .replace("{town}",keys[0]);
- //图片地址
- picUrl = picUrl.replace("{server}", systemConf.getProperty("server_url"));
- article.put("Url",url);
- article.put("Title",keys[1]);
- article.put("Description","请点击查看区详情");
- article.put("PicUrl",picUrl);
- articles.add(article);
- //设置通用链接
- setUrlItems(articles,systemConf);
- // 消息XML
- result = WeiXinMessageReplyUtils.replyNewsMessage(message.get("FromUserName"),message.get("ToUserName"),articles);
- }
- return result;
- }
- }
|