File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
main/java/me/chanjar/weixin/common/util/crypto
test/java/me/chanjar/weixin/common/util/crypto Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 11package me .chanjar .weixin .common .util .crypto ;
22
33import org .apache .commons .codec .digest .DigestUtils ;
4+ import org .apache .commons .lang3 .StringUtils ;
45
56import java .util .Arrays ;
67
@@ -13,6 +14,10 @@ public class SHA1 {
1314 * 串接arr参数,生成sha1 digest
1415 */
1516 public static String gen (String ... arr ) {
17+ if (StringUtils .isAnyEmpty (arr )) {
18+ throw new IllegalArgumentException ("非法请求参数,有部分参数为空 : " + Arrays .toString (arr ));
19+ }
20+
1621 Arrays .sort (arr );
1722 StringBuilder sb = new StringBuilder ();
1823 for (String a : arr ) {
Original file line number Diff line number Diff line change 1+ package me .chanjar .weixin .common .util .crypto ;
2+
3+ import org .testng .annotations .Test ;
4+
5+ import static org .testng .Assert .assertEquals ;
6+ import static org .testng .Assert .assertNotNull ;
7+
8+ /**
9+ * <pre>
10+ * Created by BinaryWang on 2017/6/10.
11+ * </pre>
12+ *
13+ * @author <a href="https://github.com/binarywang">binarywang(Binary Wang)</a>
14+ */
15+ public class SHA1Test {
16+ @ Test
17+ public void testGen () throws Exception {
18+ final String result = SHA1 .gen ("123" , "345" );
19+ assertNotNull (result );
20+ assertEquals (result ,"9f537aeb751ec72605f57f94a2f6dc3e3958e1dd" );
21+ }
22+
23+ @ Test (expectedExceptions = {IllegalArgumentException .class })
24+ public void testGen_illegalArguments () {
25+ final String result = SHA1 .gen (null , "" , "345" );
26+ assertNotNull (result );
27+ }
28+
29+ @ Test
30+ public void testGenWithAmple () throws Exception {
31+ final String result = SHA1 .genWithAmple ("123" , "345" );
32+ assertNotNull (result );
33+ assertEquals (result ,"20b896ccbd5a72dde5dbe0878ff985e4069771c6" );
34+ }
35+
36+ }
You can’t perform that action at this time.
0 commit comments