From 92f1d85ddc449ce7452f9d52f8b081e6b69c720b Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期三, 27 一月 2021 15:29:08 +0800 Subject: [PATCH] update .gitignore --- utils/src/main/java/com/qq/weixin/mp/aes/XMLParse.java | 158 ++++++++++++++++++++++++++-------------------------- 1 files changed, 79 insertions(+), 79 deletions(-) diff --git a/utils/src/main/java/com/qq/weixin/mp/aes/XMLParse.java b/utils/src/main/java/com/qq/weixin/mp/aes/XMLParse.java index 76f9680..15f225f 100644 --- a/utils/src/main/java/com/qq/weixin/mp/aes/XMLParse.java +++ b/utils/src/main/java/com/qq/weixin/mp/aes/XMLParse.java @@ -1,79 +1,79 @@ -/** - * 瀵瑰叕浼楀钩鍙板彂閫佺粰鍏紬璐﹀彿鐨勬秷鎭姞瑙e瘑绀轰緥浠g爜. - * - * @copyright Copyright (c) 1998-2014 Tencent Inc. - */ - -// ------------------------------------------------------------------------ - -package com.qq.weixin.mp.aes; - -import java.io.StringReader; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; - -/** - * XMLParse class - * - * 鎻愪緵鎻愬彇娑堟伅鏍煎紡涓殑瀵嗘枃鍙婄敓鎴愬洖澶嶆秷鎭牸寮忕殑鎺ュ彛. - */ -class XMLParse { - - /** - * 鎻愬彇鍑簒ml鏁版嵁鍖呬腑鐨勫姞瀵嗘秷鎭� - * - * @param xmltext - * 寰呮彁鍙栫殑xml瀛楃涓� - * @return 鎻愬彇鍑虹殑鍔犲瘑娑堟伅瀛楃涓� - * @throws AesException - */ - public static Object[] extract(String xmltext) throws AesException { - Object[] result = new Object[3]; - try { - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - DocumentBuilder db = dbf.newDocumentBuilder(); - StringReader sr = new StringReader(xmltext); - InputSource is = new InputSource(sr); - Document document = db.parse(is); - - Element root = document.getDocumentElement(); - NodeList nodelist1 = root.getElementsByTagName("Encrypt"); - NodeList nodelist2 = root.getElementsByTagName("ToUserName"); - result[0] = 0; - result[1] = nodelist1.item(0).getNodeValue(); - result[2] = nodelist2.item(0).getNodeValue(); - return result; - } catch (Exception e) { - e.printStackTrace(); - throw new AesException(AesException.ParseXmlError); - } - } - - /** - * 鐢熸垚xml娑堟伅 - * - * @param encrypt - * 鍔犲瘑鍚庣殑娑堟伅瀵嗘枃 - * @param signature - * 瀹夊叏绛惧悕 - * @param timestamp - * 鏃堕棿鎴� - * @param nonce - * 闅忔満瀛楃涓� - * @return 鐢熸垚鐨剎ml瀛楃涓� - */ - public static String generate(String encrypt, String signature, String timestamp, String nonce) { - - String format = "<xml>\n" + "<Encrypt><![CDATA[%1$s]]></Encrypt>\n" - + "<MsgSignature><![CDATA[%2$s]]></MsgSignature>\n" + "<TimeStamp>%3$s</TimeStamp>\n" - + "<Nonce><![CDATA[%4$s]]></Nonce>\n" + "</xml>"; - return String.format(format, encrypt, signature, timestamp, nonce); - - } -} +/** + * 瀵瑰叕浼楀钩鍙板彂閫佺粰鍏紬璐﹀彿鐨勬秷鎭姞瑙e瘑绀轰緥浠g爜. + * + * @copyright Copyright (c) 1998-2014 Tencent Inc. + */ + +// ------------------------------------------------------------------------ + +package com.qq.weixin.mp.aes; + +import java.io.StringReader; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; + +/** + * XMLParse class + * + * 鎻愪緵鎻愬彇娑堟伅鏍煎紡涓殑瀵嗘枃鍙婄敓鎴愬洖澶嶆秷鎭牸寮忕殑鎺ュ彛. + */ +class XMLParse { + + /** + * 鎻愬彇鍑簒ml鏁版嵁鍖呬腑鐨勫姞瀵嗘秷鎭� + * + * @param xmltext + * 寰呮彁鍙栫殑xml瀛楃涓� + * @return 鎻愬彇鍑虹殑鍔犲瘑娑堟伅瀛楃涓� + * @throws AesException + */ + public static Object[] extract(String xmltext) throws AesException { + Object[] result = new Object[3]; + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + StringReader sr = new StringReader(xmltext); + InputSource is = new InputSource(sr); + Document document = db.parse(is); + + Element root = document.getDocumentElement(); + NodeList nodelist1 = root.getElementsByTagName("Encrypt"); + NodeList nodelist2 = root.getElementsByTagName("ToUserName"); + result[0] = 0; + result[1] = nodelist1.item(0).getNodeValue(); + result[2] = nodelist2.item(0).getNodeValue(); + return result; + } catch (Exception e) { + e.printStackTrace(); + throw new AesException(AesException.ParseXmlError); + } + } + + /** + * 鐢熸垚xml娑堟伅 + * + * @param encrypt + * 鍔犲瘑鍚庣殑娑堟伅瀵嗘枃 + * @param signature + * 瀹夊叏绛惧悕 + * @param timestamp + * 鏃堕棿鎴� + * @param nonce + * 闅忔満瀛楃涓� + * @return 鐢熸垚鐨剎ml瀛楃涓� + */ + public static String generate(String encrypt, String signature, String timestamp, String nonce) { + + String format = "<xml>\n" + "<Encrypt><![CDATA[%1$s]]></Encrypt>\n" + + "<MsgSignature><![CDATA[%2$s]]></MsgSignature>\n" + "<TimeStamp>%3$s</TimeStamp>\n" + + "<Nonce><![CDATA[%4$s]]></Nonce>\n" + "</xml>"; + return String.format(format, encrypt, signature, timestamp, nonce); + + } +} -- Gitblit v1.8.0