/*微信图文回复验证token*/
@RequestMapping(value = "imgtext.form",method=RequestMethod.GET)
@ResponseBody
public String getimgtext(HttpServletRequest request,
HttpServletResponse response) throws UnsupportedEncodingException, AesException {
System.out.println("微信图文回复=======get");
String msgSignature = request.getParameter("signature");
String msgTimestamp = request.getParameter("timestamp");
String msgNonce = request.getParameter("nonce");
String echostr = request.getParameter("echostr");
if (WXPublicUtils.verifyUrl(msgSignature, msgTimestamp, msgNonce)) {
return echostr;
}
return null;
}
/*微信图文回复处理事件内容*/
@RequestMapping(value = "imgtext.form",method=RequestMethod.POST)
@ResponseBody
public void imgtext(HttpServletRequest request,
HttpServletResponse response) throws UnsupportedEncodingException, AesException {
System.out.println("微信图文回复=======");
// 设置utf-8编码防止中文乱码
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
PrintWriter out = null;
// 发送给微信端的的xml数据
String respXmlMsg = null;
// 返回xml数据对象
ResponseXml responseXml = new ResponseXml();
// xml请求解析
Map<String, String> requestMap;
try {
requestMap = MessageUtil.parseXml(request);// 解析xml对象
String fromUserName = requestMap.get("FromUserName");// 发送方帐号(open_id)
String toUserName = requestMap.get("ToUserName");// 公众帐号
String creatTime = requestMap.get("CreateTime");
String msgType = requestMap.get("MsgType");// 消息类型
String content = requestMap.get("Content");// text内容
String event = requestMap.get("Event");// event内容
String eventKey = requestMap.get("EventKey");
// 根据用户输入回复不同内容
if (msgType.equals("text")) {
} else if (msgType.equals("image")) {
}
if (msgType.equals("event")) {
if (event.equals("subscribe")) {
// 关注时 返回消息
respXmlMsg = responseXml.getReplyTuwenMessage(fromUserName, toUserName, "http://baike.baidu.com/view/6300265.htm",
"https://gss2.bdstatic.com/-fo3dSag_xI4khGkpoWK1HF6hhy/baike/w%3D268%3Bg%3D0/sign=bf7422c4d754564ee565e33f8be5fbbf/10dfa9ec8a13632794f0dce49b8fa0ec09fac7cc.jpg");
System.out.println(respXmlMsg);
} else if (event.equals("CLICK")) {
}
}
out = response.getWriter();
out.print(respXmlMsg);
} catch (Exception e) {
e.printStackTrace();
} finally {
out.close();
out = null;
}
}