From 22c2a919ef8bb64843487f7cda2887b7be57a807 Mon Sep 17 00:00:00 2001 From: "Zhang.H.N" Date: Mon, 17 Jan 2022 10:45:56 +0800 Subject: [PATCH] fix some bug --- pom.xml | 2 +- .../autocard/service/ClockinService.java | 2 +- .../gcszhn/autocard/utils/DigestUtils.java | 30 +++++++++++++++++++ .../java/org/gcszhn/autocard/AppTest.java | 4 +-- .../org/gcszhn/autocard/AutoClockinTest.java | 2 +- 5 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 src/main/java/org/gcszhn/autocard/utils/DigestUtils.java diff --git a/pom.xml b/pom.xml index 102b7c5..bd11d3c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.gcszhn autocard - 1.3.7 + 1.3.8 jar Auto Heathy Report for Zhejiang University diff --git a/src/main/java/org/gcszhn/autocard/service/ClockinService.java b/src/main/java/org/gcszhn/autocard/service/ClockinService.java index 9ad58fa..77dead4 100644 --- a/src/main/java/org/gcszhn/autocard/service/ClockinService.java +++ b/src/main/java/org/gcszhn/autocard/service/ClockinService.java @@ -110,7 +110,7 @@ public ArrayList getOldInfo(String username, String password) { case "date" : value=sdf.format(new Date());break; case "bztcyy": value="";break; //地区变更需要手动打卡一次,过滤上一次的地区变更原因 } - if (value==null||value.equals("")||value.toString().equals("[]")) return; //空数组不上报 + if (value==null||value.toString().equals("[]")) return; //空数组不上报 res.add(new BasicNameValuePair(name, String.valueOf(value))); }); } catch (Exception e) { diff --git a/src/main/java/org/gcszhn/autocard/utils/DigestUtils.java b/src/main/java/org/gcszhn/autocard/utils/DigestUtils.java new file mode 100644 index 0000000..cc0b232 --- /dev/null +++ b/src/main/java/org/gcszhn/autocard/utils/DigestUtils.java @@ -0,0 +1,30 @@ +/* + * Copyright © 2021 Zhang.H.N. + * + * Licensed under the Apache License, Version 2.0 (thie "License"); + * You may not use this file except in compliance with the license. + * You may obtain a copy of the License at + * + * http://wwww.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language govering permissions and + * limitations under the License. + */ +package org.gcszhn.autocard.utils; +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Base64; + + +public class DigestUtils { + public static String digest(String message, String algorithm) throws NoSuchAlgorithmException { + byte[] data = message.getBytes(StandardCharsets.UTF_8); + MessageDigest md = MessageDigest.getInstance(algorithm); + md.update(data); + return new String(Base64.getEncoder().encode(md.digest()), StandardCharsets.UTF_8); + } +} diff --git a/src/test/java/org/gcszhn/autocard/AppTest.java b/src/test/java/org/gcszhn/autocard/AppTest.java index 9356652..76afdd8 100644 --- a/src/test/java/org/gcszhn/autocard/AppTest.java +++ b/src/test/java/org/gcszhn/autocard/AppTest.java @@ -27,6 +27,6 @@ @RunWith(SpringRunner.class) @SpringBootTest public abstract class AppTest { - protected static final String trueZjuPassPortUser = "120xxxx"; - protected static final String trueZjuPassPortPass = "zjuxxxxx"; + protected static final String trueZjuPassPortUser = "220****"; + protected static final String trueZjuPassPortPass = "202****"; } diff --git a/src/test/java/org/gcszhn/autocard/AutoClockinTest.java b/src/test/java/org/gcszhn/autocard/AutoClockinTest.java index e985288..27a5871 100644 --- a/src/test/java/org/gcszhn/autocard/AutoClockinTest.java +++ b/src/test/java/org/gcszhn/autocard/AutoClockinTest.java @@ -39,7 +39,7 @@ public void getPageTest() { } @Test public void getOldInfoTest() { - Assert.assertNotNull(autoCard.getOldInfo(trueZjuPassPortUser, trueZjuPassPortPass)); + System.out.println(autoCard.getOldInfo(trueZjuPassPortUser, trueZjuPassPortPass)); } @Test public void submitReportTest() {