You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					147 lines
				
				5.9 KiB
			
		
		
			
		
	
	
					147 lines
				
				5.9 KiB
			| 
								 
											3 years ago
										 
									 | 
							
								package com.ynxbd.wx.servlet.menu;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								import com.soecode.wxtools.api.IService;
							 | 
						||
| 
								 | 
							
								import com.soecode.wxtools.api.WxConsts;
							 | 
						||
| 
								 | 
							
								import com.soecode.wxtools.api.WxService;
							 | 
						||
| 
								 | 
							
								import com.soecode.wxtools.bean.WxMenu;
							 | 
						||
| 
								 | 
							
								import com.soecode.wxtools.bean.WxMenu.WxMenuButton;
							 | 
						||
| 
								 | 
							
								import com.soecode.wxtools.exception.WxErrorException;
							 | 
						||
| 
								 | 
							
								import com.ynxbd.wx.config.WeChatConfig;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								import javax.servlet.ServletException;
							 | 
						||
| 
								 | 
							
								import javax.servlet.http.HttpServlet;
							 | 
						||
| 
								 | 
							
								import javax.servlet.http.HttpServletRequest;
							 | 
						||
| 
								 | 
							
								import javax.servlet.http.HttpServletResponse;
							 | 
						||
| 
								 | 
							
								import java.io.IOException;
							 | 
						||
| 
								 | 
							
								import java.io.PrintWriter;
							 | 
						||
| 
								 | 
							
								import java.util.ArrayList;
							 | 
						||
| 
								 | 
							
								import java.util.List;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								//@WebServlet("/createmenu") 云龙县人民医院
							 | 
						||
| 
								 | 
							
								public class 云龙县人民医院 extends HttpServlet {
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        // 实例化 统一业务API入口
							 | 
						||
| 
								 | 
							
								        IService iService = new WxService();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        // 验证服务器的有效性
							 | 
						||
| 
								 | 
							
								        PrintWriter out = response.getWriter();
							 | 
						||
| 
								 | 
							
								        String signature = request.getParameter("signature");
							 | 
						||
| 
								 | 
							
								        String timestamp = request.getParameter("timestamp");
							 | 
						||
| 
								 | 
							
								        String nonce = request.getParameter("nonce");
							 | 
						||
| 
								 | 
							
								        String echostr = request.getParameter("echostr");
							 | 
						||
| 
								 | 
							
								        if (iService.checkSignature(signature, timestamp, nonce, echostr)) {
							 | 
						||
| 
								 | 
							
								            out.print(echostr);
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        WxMenu menu = new WxMenu();
							 | 
						||
| 
								 | 
							
								        List<WxMenuButton> btnList = new ArrayList<>();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        WxMenuButton btn1 = new WxMenuButton();
							 | 
						||
| 
								 | 
							
								        btn1.setType(WxConsts.MENU_BUTTON_CLICK);
							 | 
						||
| 
								 | 
							
								        btn1.setKey("l1");
							 | 
						||
| 
								 | 
							
								        btn1.setName("医院概况");
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        List<WxMenuButton> subList = new ArrayList<>();
							 | 
						||
| 
								 | 
							
								        WxMenuButton btn1_1 = new WxMenuButton();
							 | 
						||
| 
								 | 
							
								        btn1_1.setType(WxConsts.MENU_BUTTON_VIEW);
							 | 
						||
| 
								 | 
							
								        btn1_1.setName("医院简介");
							 | 
						||
| 
								 | 
							
								        btn1_1.setUrl(
							 | 
						||
| 
								 | 
							
								                "https://mp.weixin.qq.com/s?__biz=MzA3OTg1NDA0OQ==&mid=507759111&idx=1&sn=316c935daa9d3a49ff8d71d16f3b51ec&chksm=041a4a89336dc39f1b512b565e20fb872566d66305c6ded5d2dbe613d42fb54154b710cae236&scene=0#rd");
							 | 
						||
| 
								 | 
							
								        WxMenuButton btn1_2 = new WxMenuButton();
							 | 
						||
| 
								 | 
							
								        btn1_2.setType(WxConsts.MENU_BUTTON_VIEW);
							 | 
						||
| 
								 | 
							
								        btn1_2.setName("就医指南");
							 | 
						||
| 
								 | 
							
								        btn1_2.setUrl(
							 | 
						||
| 
								 | 
							
								                "https://mp.weixin.qq.com/s?__biz=MzA3OTg1NDA0OQ==&mid=507759118&idx=1&sn=ee7c52e724bf7f5476df9112865e3c5f&chksm=041a4a80336dc3968d73416e7a8187f933ac748cbcfac098e0fdb82e95420416dd2135fb37e5&scene=0#rd");
							 | 
						||
| 
								 | 
							
								        WxMenuButton btn1_3 = new WxMenuButton();
							 | 
						||
| 
								 | 
							
								        btn1_3.setType(WxConsts.MENU_BUTTON_VIEW);
							 | 
						||
| 
								 | 
							
								        btn1_3.setName("医保相关");
							 | 
						||
| 
								 | 
							
								        btn1_3.setUrl(
							 | 
						||
| 
								 | 
							
								                "https://mp.weixin.qq.com/s?__biz=MzA3OTg1NDA0OQ==&mid=507759120&idx=1&sn=0657ca3c3b0c80625c0588246ee58996&chksm=041a4a9e336dc3885a956cd22dd70bed1ce9625bc0eec0a00ac3a0faca2ecb3d6dbf19c21722&scene=0#rd");
							 | 
						||
| 
								 | 
							
								        subList.add(btn1_1);
							 | 
						||
| 
								 | 
							
								        subList.add(btn1_2);
							 | 
						||
| 
								 | 
							
								        subList.add(btn1_3);
							 | 
						||
| 
								 | 
							
								        btn1.setSub_button(subList);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        WxMenuButton btn2 = new WxMenuButton();
							 | 
						||
| 
								 | 
							
								        btn2.setType(WxConsts.MENU_BUTTON_CLICK);
							 | 
						||
| 
								 | 
							
								        btn2.setKey("l2");
							 | 
						||
| 
								 | 
							
								        btn2.setName("预约挂号");
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        List<WxMenuButton> subList2 = new ArrayList<>();
							 | 
						||
| 
								 | 
							
								        WxMenuButton btn2_1 = new WxMenuButton();
							 | 
						||
| 
								 | 
							
								        btn2_1.setType(WxConsts.MENU_BUTTON_VIEW);
							 | 
						||
| 
								 | 
							
								        btn2_1.setName("今日挂号");
							 | 
						||
| 
								 | 
							
								        btn2_1.setUrl(WeChatConfig.getBaseUrl() + "reg-site.html");
							 | 
						||
| 
								 | 
							
								        WxMenuButton btn2_2 = new WxMenuButton();
							 | 
						||
| 
								 | 
							
								        btn2_2.setType(WxConsts.MENU_BUTTON_VIEW);
							 | 
						||
| 
								 | 
							
								        btn2_2.setName("预约挂号");
							 | 
						||
| 
								 | 
							
								        btn2_2.setUrl(WeChatConfig.getBaseUrl() + "reg-reserve.html");
							 | 
						||
| 
								 | 
							
								        WxMenuButton btn2_3 = new WxMenuButton();
							 | 
						||
| 
								 | 
							
								        btn2_3.setType(WxConsts.MENU_BUTTON_VIEW);
							 | 
						||
| 
								 | 
							
								        btn2_3.setName("电子健康卡");
							 | 
						||
| 
								 | 
							
								        btn2_3.setUrl(WeChatConfig.getBaseUrl() + "health-card.html");
							 | 
						||
| 
								 | 
							
								        subList2.add(btn2_1);
							 | 
						||
| 
								 | 
							
								        subList2.add(btn2_2);
							 | 
						||
| 
								 | 
							
								        subList2.add(btn2_3);
							 | 
						||
| 
								 | 
							
								        btn2.setSub_button(subList2);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        WxMenuButton btn3 = new WxMenuButton();
							 | 
						||
| 
								 | 
							
								        btn3.setType(WxConsts.MENU_BUTTON_CLICK);
							 | 
						||
| 
								 | 
							
								        btn3.setKey("l3");
							 | 
						||
| 
								 | 
							
								        btn3.setName("我的信息");
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        List<WxMenuButton> subList3 = new ArrayList<>();
							 | 
						||
| 
								 | 
							
								        WxMenuButton btn3_1 = new WxMenuButton();
							 | 
						||
| 
								 | 
							
								        btn3_1.setType(WxConsts.MENU_BUTTON_VIEW);
							 | 
						||
| 
								 | 
							
								        btn3_1.setName("个人中心");
							 | 
						||
| 
								 | 
							
								        btn3_1.setUrl(WeChatConfig.getBaseUrl() + "my-info.html");
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        WxMenuButton btn3_2 = new WxMenuButton();
							 | 
						||
| 
								 | 
							
								        btn3_2.setType(WxConsts.MENU_BUTTON_VIEW);
							 | 
						||
| 
								 | 
							
								        btn3_2.setName("微信支付");
							 | 
						||
| 
								 | 
							
								        btn3_2.setUrl(WeChatConfig.getBaseUrl() + "pay-info.html");
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        WxMenuButton btn3_3 = new WxMenuButton();
							 | 
						||
| 
								 | 
							
								        btn3_3.setType(WxConsts.MENU_BUTTON_VIEW);
							 | 
						||
| 
								 | 
							
								        btn3_3.setName("报告单");
							 | 
						||
| 
								 | 
							
								        btn3_3.setUrl(WeChatConfig.getBaseUrl() + "all-result.html");
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        // WxMenuButton btn3_3 = new WxMenuButton();
							 | 
						||
| 
								 | 
							
								        // btn3_2.setType(WxConsts.MENU_BUTTON_VIEW);
							 | 
						||
| 
								 | 
							
								        // btn3_2.setName("发消息给我");
							 | 
						||
| 
								 | 
							
								        // btn3_2.setUrl("http://wsxrmyy.s1.natapp.cc/wx/sendmessage.jsp");
							 | 
						||
| 
								 | 
							
								        subList3.add(btn3_1);
							 | 
						||
| 
								 | 
							
								        subList3.add(btn3_2);
							 | 
						||
| 
								 | 
							
								        subList3.add(btn3_3);
							 | 
						||
| 
								 | 
							
								        btn3.setSub_button(subList3);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        // 将三个按钮设置进btnList
							 | 
						||
| 
								 | 
							
								        btnList.add(btn1);
							 | 
						||
| 
								 | 
							
								        btnList.add(btn2);
							 | 
						||
| 
								 | 
							
								        btnList.add(btn3); // 微信支付菜单
							 | 
						||
| 
								 | 
							
								        // btnList.add(btn3_1);
							 | 
						||
| 
								 | 
							
								        // btnList.add(btn3_3);
							 | 
						||
| 
								 | 
							
								        // btnList.add(btn3_2);
							 | 
						||
| 
								 | 
							
								        // 设置进菜单类
							 | 
						||
| 
								 | 
							
								        menu.setButton(btnList);
							 | 
						||
| 
								 | 
							
								        // 调用API即可
							 | 
						||
| 
								 | 
							
								        try {
							 | 
						||
| 
								 | 
							
								            // 参数1--menu ,参数2--是否是个性化定制。如果是个性化菜单栏,需要设置MenuRule
							 | 
						||
| 
								 | 
							
								            iService.createMenu(menu, false);
							 | 
						||
| 
								 | 
							
								        } catch (WxErrorException e) {
							 | 
						||
| 
								 | 
							
								            // TODO Auto-generated catch block
							 | 
						||
| 
								 | 
							
								            e.printStackTrace();
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    protected void doPost(HttpServletRequest request, HttpServletResponse response)
							 | 
						||
| 
								 | 
							
								            throws ServletException, IOException {
							 | 
						||
| 
								 | 
							
								        // TODO Auto-generated method stub
							 | 
						||
| 
								 | 
							
								        doGet(request, response);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								}
							 |