/** * 客服接口测试(需认证) * * @return */ @RequestMapping("/testInvoke.do") @ResponseBody public String testkfjk(HttpServletRequest request) { try { int resultret = -1; // 组装文本客服消息 String jsonTextMsg = AdvancedUtil.makeTextCustomMessage( request.getParameter("openid").toString(), request.getParameter("textcontent").toString()); // 发送客服消息 logger.info( "当前登录人ID:" + request.getSession().getAttribute(SessionConstant.USERID).toString()); String userId = request.getSession().getAttribute(SessionConstant.USERID).toString(); Map<String, String> usermap = new HashMap<String, String>(); String wxid = ""; usermap = this.commonService.getWXaccount(userId); // SessionConstant.USERID取值 if (usermap != null) { wxid = usermap.get("wxid"); String accesstoken = ""; accesstoken = CommonUtil.getToken(wxid); if (!"".equals(accesstoken)) { AdvancedUtil.sendCustomMessage(accesstoken, jsonTextMsg); resultret = 1; } } return CommonMsg.getMsgJson(StatusCode.SUCCESS, String.valueOf(resultret)); } catch (Exception e) { e.printStackTrace(); return CommonMsg.getMsgJson(StatusCode.FAIL, e.getMessage()); } }
/** * 快速回复用户消息 * * @param * @return */ @RequestMapping("/replymessageInvoke.do") @ResponseBody public String replyMsg(HttpServletRequest request) { Map<String, String> usermap = new HashMap<String, String>(); try { int resultret = -1; // 组装文本客服消息 String jsonTextMsg = AdvancedUtil.makeTextCustomMessage( request.getParameter("openid").toString(), request.getParameter("messagecontent").toString()); // 发送客服消息 logger.info( "当前登录人ID:" + request.getSession().getAttribute(SessionConstant.USERID).toString()); String userId = request.getSession().getAttribute(SessionConstant.USERID).toString(); String wxid = ""; usermap = this.commonService.getWXaccount(userId); // SessionConstant.USERID取值 if (usermap != null) { wxid = usermap.get("wxid"); String accesstoken = ""; accesstoken = CommonUtil.getToken(wxid); if (!"".equals(accesstoken)) { Boolean ret = AdvancedUtil.sendCustomMessage(accesstoken, jsonTextMsg); if (ret == true) { resultret = 1; try { // 更新数据库中的 ifreply和replycontent Map<String, Object> params = new HashMap<String, Object>(); params.put("wxid", wxid); params.put("msgid", System.currentTimeMillis()); params.put("ifreply", "1"); params.put("oldmsgid", request.getParameter("msgid").toString()); params.put("msg_type", "text"); params.put("text_content", request.getParameter("messagecontent").toString()); this.commonService.saveWXMessage(params); } catch (Exception e) { logger.debug("更新数据库中回复内容失败,失败原因:" + e); } } else { resultret = -1; } } } return CommonMsg.getMsgJson(StatusCode.SUCCESS, String.valueOf(resultret)); } catch (Exception e) { e.printStackTrace(); return CommonMsg.getMsgJson(StatusCode.FAIL, e.getMessage()); } }