问答详情
源自:5-4 消息的接收与响应2

该公众号暂时无法提供服务请稍后再试。怎么回事。

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();

}

}


}


提问者:慕函数9179735 2017-06-18 23:04

个回答

  • XinQing_Andy
    2017-11-19 07:24:59

    请问解决了吗


  • 小罗yz
    2017-11-07 01:20:26

    我也是这个问题 

    http://img3.mukewang.com/5a0099cc0001462905000377.jpg

    http://img3.mukewang.com/5a0099cc00015e6d06240158.jpg


  • 慕村0096219
    2017-06-29 16:31:09

    有解决了的不

  • 小皮丘
    2017-06-26 18:09:52

    这四个参数为空

    http://img.mukewang.com/5950dd5800010eb012000711.jpg

  • jUrMiNhOnG0
    2017-06-19 16:42:14

    没有转换成xml