public class WeiXinServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public WeiXinServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String signature = request.getParameter("signature");
String timestamp = request.getParameter("timestamp");
String nonce = request.getParameter("nonce");
String echostr = request.getParameter("echostr");
PrintWriter out=response.getWriter();
if(CheckUtil.checkSignature(signature, timestamp, nonce, echostr)){
out.print(echostr);
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
PrintWriter out=response.getWriter();
try {
Map<String, String> map = MessageUtil.xmlToMap(request);
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);
}
out.print(message);
System.out.println("-------------------------");
System.out.println(message);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
out.close();
}
}
}
请问解决了吗
我也是这个问题
有解决了的不
这四个参数为空
没有转换成xml