public static void DoXinqiu(WeixinRequest wr) { final String url = wr.getUrl(); final String openId = wr.getOpenId(); AsynTaskQueue.shared() .addTask( new Runnable() { @Override public void run() { try { ArrayList<Article> articles = new ArrayList<Article>(); Article article = new Article(); article.setTitle("你是猫奴还是汪奴?"); article.setDescription("点击大图可以创建新的奴星球"); article.setPicUrl(url.replace(":80", "") + "/images/gou.jpg"); article.setUrl(url + "/CreateServlet?openId=" + openId); articles.add(article); // 点击奴星球 IGokitdogService service = new GokitdogServiceImpl(); ResponseList<Groups> list = service.getGroup(openId); List<Groups> groups = list.getSuccess(); for (int i = 0; i < groups.size(); i++) { String title = (i + 1) + "、" + groups.get(i).getGroupName() + " 点击查看大家的窝窝"; Article article1 = new Article(); article1.setTitle(title); article1.setDescription(title); article1.setPicUrl(url.replace(":80", "") + "/images/headPic.png"); article1.setUrl( url + "/XingqiuServlet?groupId=" + groups.get(i).getGroupId() + "&openId=" + openId); articles.add(article1); } SendCustomArticlesMsg(openId, articles); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); }
public static void DoQrCodeSan(WeixinRequest wr, BindingCallback listener) { IGokitdogService gokitSevice = new GokitdogServiceImpl(); String qrCode = wr.getBody().get("xml.EventKey"); if (qrCode.contains("qrscene")) { qrCode = qrCode.split("_")[1]; } logger.info("qrCode is " + qrCode); UserBindingDevice data = new UserBindingDevice(); data.setOpenId(wr.getOpenId()); data.setQrCode(qrCode); data.setIsUsed(true); AsynTaskQueue.shared().addTask(new BindingThread(data, listener, wr)); }
public static WeixinRequest WeixinRequsetAnalysis(final HttpServletRequest request) throws Exception { WeixinRequest mWeixinRequst = new WeixinRequest(); final String url = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); // 解释请求信息 StringBuffer readBuf = new StringBuffer(); String line; BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { readBuf.append(line); } String body = new String(readBuf.toString().getBytes("iso-8859-1"), "utf-8"); Map<String, String> map = null; map = XmlUtil.xml2Map(body); final String msgType = map.get("xml.MsgType"); final String openId = map.get("xml.FromUserName"); mWeixinRequst.setBody(map); mWeixinRequst.setOpenId(openId); mWeixinRequst.setUrl(url); // 微信请求后的事件 if (StringUtils.equalsIgnoreCase(msgType, "event")) { final String eventKey = map.get("xml.EventKey"); String event = map.get("xml.Event"); if (StringUtils.equalsIgnoreCase(event, "subscribe")) { if (map.get("xml.EventKey") != null && map.get("xml.EventKey").length() > 0) { mWeixinRequst.setRequstType(WeixinRequstType.qrCodeScan); } } else if (StringUtils.equalsIgnoreCase(event, "unsubscribe")) { } // 扫描后的事件 else if (StringUtils.equalsIgnoreCase(event, "scan")) { mWeixinRequst.setRequstType(WeixinRequstType.qrCodeScan); } else if (StringUtils.equalsIgnoreCase(event, "click")) { // 点击窝窝 if (eventKey.equalsIgnoreCase("wowo")) { // 点击窝窝 mWeixinRequst.setRequstType(WeixinRequstType.Wowo); } // 点击奴星球 else if (eventKey.equalsIgnoreCase("xingqiu")) { mWeixinRequst.setRequstType(WeixinRequstType.Xinqiu); } } else if (StringUtils.equalsIgnoreCase(event, "location")) { } } else if (StringUtils.equalsIgnoreCase(msgType, "text") || StringUtils.equalsIgnoreCase(msgType, "voice")) { } return mWeixinRequst; }