Ejemplo n.º 1
0
 /**
  * 客服接口测试(需认证)
  *
  * @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());
   }
 }
Ejemplo n.º 2
0
 /**
  * 快速回复用户消息
  *
  * @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());
   }
 }
Ejemplo n.º 3
0
 /**
  * 粉丝信息获取(需认证)
  *
  * @return
  */
 @RequestMapping("/getuserinfo.do")
 @ResponseBody
 public String getuserinfo(HttpServletRequest request) {
   String openid = request.getParameter("openid").toString();
   try {
     String resultret = "";
     logger.info(
         "当前登录人ID:" + request.getSession().getAttribute(SessionConstant.USERID).toString());
     String userId = request.getSession().getAttribute(SessionConstant.USERID).toString();
     Map<String, String> usermap = null;
     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)) {
         WeixinUserInfo user = AdvancedUtil.getUserInfo(accesstoken, openid);
         System.out.println("OpenID:" + user.getOpenId());
         System.out.println("关注状态:" + user.getSubscribe());
         System.out.println("关注时间:" + user.getSubscribeTime());
         System.out.println("昵称:" + user.getNickname());
         System.out.println("性别:" + user.getSex());
         System.out.println("国家:" + user.getCountry());
         System.out.println("省份:" + user.getProvince());
         System.out.println("城市:" + user.getCity());
         System.out.println("语言:" + user.getLanguage());
         System.out.println("头像:" + user.getHeadImgUrl());
         resultret =
             "关注状态:"
                 + user.getSubscribe()
                 + ";关注时间:"
                 + user.getSubscribeTime()
                 + ";昵称:"
                 + user.getNickname()
                 + ";性别:"
                 + user.getSex()
                 + ";国家:"
                 + user.getCountry()
                 + ";省份:"
                 + user.getProvince()
                 + ";城市:"
                 + user.getCity()
                 + ";语言:"
                 + user.getLanguage()
                 + ";头像:"
                 + user.getHeadImgUrl();
       }
     }
     // 处理查询结果
     String jsonmsg = "{datas:[{\"resultret\":\"" + resultret + "\"}]}";
     return CommonMsg.getObjectJson(StatusCode.SUCCESS, jsonmsg);
   } catch (Exception e) {
     e.printStackTrace();
     return CommonMsg.getMsgJson(StatusCode.FAIL, e.getMessage());
   }
 }
Ejemplo n.º 4
0
  /**
   * 粉丝列表获取(需认证)
   *
   * @return
   */
  @RequestMapping("/getuserlist.do")
  @ResponseBody
  public String getuserlist(HttpServletRequest request) {
    try {
      String resultret = "";
      logger.info(
          "当前登录人ID:" + request.getSession().getAttribute(SessionConstant.USERID).toString());
      String userId = request.getSession().getAttribute(SessionConstant.USERID).toString();
      Map<String, String> usermap = null;
      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)) {
          WeixinUserList weixinUserList = AdvancedUtil.getUserList(accesstoken, "");
          System.out.println("总关注用户数:" + weixinUserList.getTotal());
          System.out.println("本次获取用户数:" + weixinUserList.getCount());
          System.out.println("OpenID列表:" + weixinUserList.getOpenIdList().toString());
          System.out.println("next_openid:" + weixinUserList.getNextOpenId());

          resultret =
              "总关注用户数:"
                  + weixinUserList.getTotal()
                  + ";本次获取用户数:"
                  + weixinUserList.getCount()
                  + ";OpenID列表:"
                  + weixinUserList.getOpenIdList().toString();
        }
      }
      // 处理查询结果
      String jsonmsg = "{datas:[{\"resultret\":\"" + resultret + "\"}]}";
      return CommonMsg.getObjectJson(StatusCode.SUCCESS, jsonmsg);
    } catch (Exception e) {
      e.printStackTrace();
      return CommonMsg.getMsgJson(StatusCode.FAIL, e.getMessage());
    }
  }