diff --git a/src/main/java/dev/surl/surl/util/CheckSumUtil.kt b/src/main/java/dev/surl/surl/util/CheckSumUtil.kt new file mode 100644 index 0000000..96ff05e --- /dev/null +++ b/src/main/java/dev/surl/surl/util/CheckSumUtil.kt @@ -0,0 +1,8 @@ +package dev.surl.surl.util + +import org.springframework.util.DigestUtils + +fun md5(str: String): String { + val cksum = DigestUtils.md5Digest(str.toByteArray()) + return cksum.joinToString("") { "%02x".format(it) } +} \ No newline at end of file diff --git a/src/main/java/dev/surl/surl/util/UIDUtil.kt b/src/main/java/dev/surl/surl/util/UIDUtil.kt new file mode 100644 index 0000000..b5b8e4c --- /dev/null +++ b/src/main/java/dev/surl/surl/util/UIDUtil.kt @@ -0,0 +1,15 @@ +package dev.surl.surl.util + +import java.util.concurrent.ThreadLocalRandom + +private val CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toCharArray() +private const val LENGTH = 16 + +fun genSurlUID(): String { + return genSurlUID(LENGTH) +} + +fun genSurlUID(length: Int): String { + val random = ThreadLocalRandom.current() + return CharArray(length) { CHARS[random.nextInt(CHARS.size)] }.concatToString() +} \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 54f3721..639b0c8 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,7 +1,7 @@ server: - port: 18888 + port: 18888 #服务端口 spring: application: - name: surl + name: surl # 应用名称 main: - banner-mode: off + banner-mode: off # 关闭banner diff --git a/src/test/java/dev/surl/surl/UtilTests.kt b/src/test/java/dev/surl/surl/UtilTests.kt new file mode 100644 index 0000000..a40a09a --- /dev/null +++ b/src/test/java/dev/surl/surl/UtilTests.kt @@ -0,0 +1,18 @@ +package dev.surl.surl + +import dev.surl.surl.util.genSurlUID +import dev.surl.surl.util.md5 +import org.junit.jupiter.api.Test + +class UtilTests { + @Test + fun md5Test() { + assert(md5("sd") == "6226f7cbe59e99a90b5cef6f94f966fd") + } + + @Test + fun randomUIDTest() { + println(genSurlUID()) + println(genSurlUID(8)) + } +} \ No newline at end of file