微信公众号接入图灵机器人实现自动回复消息 (2)

应用常量

public final class AppConstants { /** * 应用id */ public static String APP_ID = ""; /** * 应用秘钥 */ public static String APP_SECRET = ""; /** * 令牌 */ public static String TOKEN = ""; /** * 图灵机器人应用key */ public static String API_KEY = ""; }

最后服务层处理来自文本消息

else if (MsgType.TEXT.getValue().equals(msgType)) { //点击菜单 //回复微信服务器成功 try { String result; result = textMessageHandle.processMessage(custermname, servername, content); writeText(result, response); } } catch (Exception e) { logger.error("接收来至微信服务器的消息出现错误", e); writeText(MessageUtil.ObjectToXml(new TextMessage(custermname, servername, "我竟无言以对!")), response); e.printStackTrace(); } private void writeText(String content, HttpServletResponse response) { Writer writer = null; try { response.setContentType("text/html"); response.setCharacterEncoding("UTF-8"); writer = response.getWriter(); writer.write(content); writer.flush(); } catch (IOException e) { logger.error("响应客户端文本内容出现异常", e); } finally { IOUtils.close(writer); } }

结果:

微信公众号接入图灵机器人实现自动回复消息

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zywdzf.html