protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String pathInfo = req.getPathInfo(); HttpSession session = req.getSession(); if (session == null) { resp.setStatus(401); return; } String username = (String) session.getAttribute("username"); if (username == null) { resp.setStatus(401); return; } Map userMap = loadUserSettingsMap(username); if (userMap == null) { resp.setStatus(401); return; } if (pathInfo.equals("/")) { resp.setContentType("application/json; charset=UTF-8"); resp.getWriter().write(JSONUtil.write(userMap)); return; } String key = pathInfo.substring(1); String value = (String) userMap.get(key); Map jsonObject = new HashMap(); jsonObject.put(key, value); resp.setContentType("application/json; charset=UTF-8"); resp.getWriter().write(JSONUtil.write(jsonObject)); }
public static void main(String[] args) { /* File file= null; file = new File("C:\\Users\\angelwsin\\Downloads\\1418264418901.jpg"); Map<String,String> params = new HashMap<String,String>(); params.put("access_token", TokenService.acessToken()); params.put("type", "image"); System.out.println(upload("https://api.weixin.qq.com/cgi-bin/media/upload", file, params,true));*/ WXCustTextRespMessage text = new WXCustTextRespMessage(); text.setTouser("owFQ-uBg7admIgc7wgcXzkiZa5Mk"); text.setMsgtype(WXBaseMessage.MSG_TEXT); WXCustTextMessage t = new WXCustTextMessage(); t.setContent("你是狗"); text.setText(t); Map<String, String> params = new HashMap<String, String>(); System.out.println(TokenService.acessToken()); params.put("access_token", TokenService.acessToken()); params.put("body", JSONUtil.encode(text)); System.out.println( doPost("https://api.weixin.qq.com/cgi-bin/message/custom/send", null, params, true)); }
/* (non-Javadoc) * @see java.lang.Object#toString() */ public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("RhinoRequest: ").append(JSONUtil.write(toJSON())); // $NON-NLS-1$ return buffer.toString(); }