增加String的MD5算法,修改登录借口
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
package com.synebula.gaea.app
|
||||
|
||||
import com.synebula.gaea.data.message.Message
|
||||
|
||||
|
||||
interface ILogin {
|
||||
/**
|
||||
* 定义登录方法。
|
||||
*
|
||||
* @param name 登录名
|
||||
* @param password 登录密码
|
||||
* @return StatusMessage, data 内容为 map 其中 key account中存储用户账户名称
|
||||
*/
|
||||
fun login(name: String, password: String): Message<Any>
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.synebula.gaea.app
|
||||
|
||||
import org.springframework.http.HttpMessage
|
||||
|
||||
/**
|
||||
* 用户登入登出接口定义
|
||||
*/
|
||||
interface ISignInOut {
|
||||
/**
|
||||
* 定义登录方法。
|
||||
*
|
||||
* @param name 登录名
|
||||
* @param password 登录密码
|
||||
* @return StatusMessage, data 内容为 map 其中 key account中存储用户账户名称
|
||||
*/
|
||||
fun signIn(name: String, password: String): HttpMessage
|
||||
|
||||
/**
|
||||
* 登出
|
||||
*
|
||||
* @param user 登出的用户
|
||||
*/
|
||||
fun signOut(user: String): HttpMessage
|
||||
}
|
||||
@@ -1,9 +1,32 @@
|
||||
package com.synebula.gaea.extension
|
||||
|
||||
import java.math.BigInteger
|
||||
import java.security.MessageDigest
|
||||
import java.security.NoSuchAlgorithmException
|
||||
|
||||
/**
|
||||
* 首字母小写
|
||||
*/
|
||||
fun String.firstCharLowerCase(): String {
|
||||
if (Character.isLowerCase(this.elementAt(0)))
|
||||
return this
|
||||
return if (Character.isLowerCase(this.elementAt(0)))
|
||||
this
|
||||
else
|
||||
return StringBuilder().append(Character.toLowerCase(this.elementAt(0)))
|
||||
StringBuilder().append(Character.toLowerCase(this.elementAt(0)))
|
||||
.append(this.substring(1)).toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字符串的MD值
|
||||
*/
|
||||
fun String.toMd5(): String {
|
||||
val secretBytes = try {
|
||||
MessageDigest.getInstance("md5").digest(this.toByteArray())
|
||||
} catch (e: NoSuchAlgorithmException) {
|
||||
throw RuntimeException("没有这个md5算法!")
|
||||
}
|
||||
var md5code = BigInteger(1, secretBytes).toString(16)
|
||||
for (i in 0 until 32 - md5code.length) {
|
||||
md5code = "0$md5code"
|
||||
}
|
||||
return md5code
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user