示例#1
0
  /**
   * 回复微信服务器"文本消息"
   *
   * @param request
   * @param response
   * @param content
   * @param toUserName
   * @param fromUserName
   * @throws DocumentException
   * @throws IOException
   */
  public void replyTextMessage(
      HttpServletRequest request,
      HttpServletResponse response,
      String content,
      String toUserName,
      String fromUserName)
      throws DocumentException, IOException {
    Long createTime = Calendar.getInstance().getTimeInMillis() / 1000;
    StringBuffer sb = new StringBuffer();
    sb.append("<xml>");
    sb.append("<ToUserName><![CDATA[" + fromUserName + "]]></ToUserName>");
    sb.append("<FromUserName><![CDATA[" + toUserName + "]]></FromUserName>");
    sb.append("<CreateTime>" + createTime + "</CreateTime>");
    sb.append("<MsgType><![CDATA[text]]></MsgType>");
    sb.append("<Content><![CDATA[" + content + "]]></Content>");
    sb.append("</xml>");
    String replyMsg = sb.toString();

    String returnvaleue = "";
    try {
      WXBizMsgCrypt pc =
          new WXBizMsgCrypt(COMPONENT_TOKEN, COMPONENT_ENCODINGAESKEY, COMPONENT_APPID);
      returnvaleue = pc.encryptMsg(replyMsg, createTime.toString(), "easemob");
      //            System.out.println("------------------加密后的返回内容 returnvaleue: "+returnvaleue);
    } catch (AesException e) {
      e.printStackTrace();
    }
    output(response, returnvaleue);
  }
示例#2
0
  public static void main(String[] args) {
    Long createTime = Calendar.getInstance().getTimeInMillis() / 1000;
    String replyMsg = "LOCATIONfrom_callback";

    String returnvaleue = "";
    try {
      WXBizMsgCrypt pc =
          new WXBizMsgCrypt(COMPONENT_TOKEN, COMPONENT_ENCODINGAESKEY, COMPONENT_APPID);
      returnvaleue = pc.encryptMsg(replyMsg, createTime.toString(), "easemob");
      System.out.println(returnvaleue);
    } catch (AesException e) {
      e.printStackTrace();
    }
  }