該公眾號(hào)暫時(shí)無法提供服務(wù)請(qǐng)稍后再試。怎么回事。
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("您響應(yīng)的消息是:"+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();
}
}
}
2017-11-19
請(qǐng)問解決了嗎
2017-11-07
我也是這個(gè)問題?
2017-06-29
有解決了的不
2017-06-26
這四個(gè)參數(shù)為空
2017-06-19
沒有轉(zhuǎn)換成xml