JingHelsing
2015-08-06 15:25
这个是在tunnel中的报错,是400错误,也是post请求,应该可以进断点的啊,也进不去,照着老师写的一字不差的做的,那个createTime也在后面加了“”字符串了,仔细检查了几遍,不知道原因出在哪,因为后台也没用报错
package com.ssxt.weixin.servlet; import java.io.IOException; import java.io.PrintWriter; import java.util.Date; import java.util.Map; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.dom4j.DocumentException; import com.ssxt.weixin.po.TextMessage; import com.ssxt.weixin.util.CheckUtil; import com.ssxt.weixin.util.MessageUtil; public class WeixinServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // TODO Auto-generated method stub //super.doGet(req, resp); String signature = req.getParameter("signature"); String timestamp = req.getParameter("timestamp"); String nonce = req.getParameter("nonce"); String echostr = req.getParameter("echostr"); PrintWriter out = resp.getWriter(); if(CheckUtil.checkSignature(signature, timestamp, nonce)) { out.print(echostr); } //System.out.println("1"); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // TODO Auto-generated method stub //super.doPost(req, resp); //System.out.println("2"); req.setCharacterEncoding("UTF-8"); resp.setCharacterEncoding("UTF-8"); PrintWriter out = resp.getWriter(); try { Map<String, String> map = MessageUtil.xmlToMap(req); System.out.println("map="+map); String fromUserName = map.get("FromUserName"); String toUserName = map.get("ToUserName"); String msgType = map.get("MsgType"); String content = map.get("Content"); String message = null; if("text".equals(msgType)) { TextMessage text = new TextMessage(); text.setFromUserName(toUserName); text.setToUserName(fromUserName); text.setMsgType("text"); text.setCreateTime(new Date().getTime() + ""); text.setContent("您发送的消息是:" + content); message = MessageUtil.textMessageToXml(text); } System.out.println(message); out.print(message); } catch (DocumentException e) { // TODO: handle exception e.printStackTrace(); } finally { out.close(); } } }
已经解决了,是项目在eclipse中重新部署问题,需要clean一下
初识Java微信公众号开发
158335 学习 · 469 问题
相似问题