fix some warnings in common modules

This commit is contained in:
BinaryWang
2016-09-01 10:18:24 +08:00
parent 66cd7cda43
commit 6f297ae95a
30 changed files with 185 additions and 178 deletions

View File

@ -34,8 +34,8 @@ public class WxCryptUtilTest {
String afterAesEncrypt2 = "jn1L23DB+6ELqJ+6bruv23M2GmYfkv0xBh2h+XTBOKVKcgDFHle6gqcZ1cZrk3e1qjPQ1F4RsLWzQRG9udbKWesxlkupqcEcW7ZQweImX9+wLMa0GaUzpkycA8+IamDBxn5loLgZpnS7fVAbExOkK5DYHBmv5tptA9tklE/fTIILHR8HLXa5nQvFb3tYPKAlHF3rtTeayNf0QuM+UW/wM9enGIDIJHF7CLHiDNAYxr+r+OrJCmPQyTy8cVWlu9iSvOHPT/77bZqJucQHQ04sq7KZI27OcqpQNSto2OdHCoTccjggX5Z9Mma0nMJBU+jLKJ38YB1fBIz+vBzsYjrTmFQ44YfeEuZ+xRTQwr92vhA9OxchWVINGC50qE/6lmkwWTwGX9wtQpsJKhP+oS7rvTY8+VdzETdfakjkwQ5/Xka042OlUb1/slTwo4RscuQ+RdxSGvDahxAJ6+EAjLt9d8igHngxIbf6YyqqROxuxqIeIch3CssH/LqRs+iAcILvApYZckqmA7FNERspKA5f8GoJ9sv8xmGvZ9Yrf57cExWtnX8aCMMaBropU/1k+hKP5LVdzbWCG0hGwx/dQudYR/eXp3P0XxjlFiy+9DMlaFExWUZQDajPkdPrEeOwofJb";
public void testNormal() throws ParserConfigurationException, SAXException, IOException {
WxCryptUtil pc = new WxCryptUtil(token, encodingAesKey, appId);
String encryptedXml = pc.encrypt(replyMsg);
WxCryptUtil pc = new WxCryptUtil(this.token, this.encodingAesKey, this.appId);
String encryptedXml = pc.encrypt(this.replyMsg);
System.out.println(encryptedXml);
@ -56,31 +56,31 @@ public class WxCryptUtilTest {
String nonce = root.getElementsByTagName("Nonce").item(0).getTextContent();
System.out.println(nonce);
String messageText = String.format(xmlFormat, cipherText);
String messageText = String.format(this.xmlFormat, cipherText);
System.out.println(messageText);
// 第三方收到企业号平台发送的消息
String plainMessage = pc.decrypt(cipherText);
System.out.println(plainMessage);
assertEquals(plainMessage, replyMsg);
assertEquals(plainMessage, this.replyMsg);
}
public void testAesEncrypt() {
WxCryptUtil pc = new WxCryptUtil(token, encodingAesKey, appId);
assertEquals(pc.encrypt(randomStr, replyMsg), afterAesEncrypt);
WxCryptUtil pc = new WxCryptUtil(this.token, this.encodingAesKey, this.appId);
assertEquals(pc.encrypt(this.randomStr, this.replyMsg), this.afterAesEncrypt);
}
public void testAesEncrypt2() {
WxCryptUtil pc = new WxCryptUtil(token, encodingAesKey, appId);
assertEquals(pc.encrypt(randomStr, replyMsg2), afterAesEncrypt2);
WxCryptUtil pc = new WxCryptUtil(this.token, this.encodingAesKey, this.appId);
assertEquals(pc.encrypt(this.randomStr, this.replyMsg2), this.afterAesEncrypt2);
}
public void testValidateSignatureError() throws ParserConfigurationException, SAXException,
IOException {
try {
WxCryptUtil pc = new WxCryptUtil(token, encodingAesKey, appId);
String afterEncrpt = pc.encrypt(replyMsg);
WxCryptUtil pc = new WxCryptUtil(this.token, this.encodingAesKey, this.appId);
String afterEncrpt = pc.encrypt(this.replyMsg);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
StringReader sr = new StringReader(afterEncrpt);
@ -91,8 +91,8 @@ public class WxCryptUtilTest {
NodeList nodelist1 = root.getElementsByTagName("Encrypt");
String encrypt = nodelist1.item(0).getTextContent();
String fromXML = String.format(xmlFormat, encrypt);
pc.decrypt("12345", timestamp, nonce, fromXML); // 这里签名错误
String fromXML = String.format(this.xmlFormat, encrypt);
pc.decrypt("12345", this.timestamp, this.nonce, fromXML); // 这里签名错误
} catch (RuntimeException e) {
assertEquals(e.getMessage(), "加密消息签名校验失败");
return;