|
|
package AuthService
|
|
|
|
|
|
import (
|
|
|
"dsDataex/MyService/Auth/AuthDAO"
|
|
|
"dsDataex/Utils/MD5Util"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
/**
|
|
|
* @Author zhangjun
|
|
|
* @Description
|
|
|
* @Date 2020-06-12 10:28
|
|
|
* @Param systemId string 接入系统code
|
|
|
* @Param systemToken string 系统验证Token
|
|
|
* @Param authTime string 系统验证时间
|
|
|
* @return bool 成功/失败
|
|
|
* @return string 结果说明
|
|
|
* @return string 系统票据
|
|
|
**/
|
|
|
func CreateToken(systemID string,systemToken string,authTime string) (bool, string, string){
|
|
|
|
|
|
success,result,data,_:= AuthDAO.GetbyCode(systemID)
|
|
|
|
|
|
if success==false{
|
|
|
|
|
|
return false,result,""
|
|
|
}else {
|
|
|
|
|
|
systemKey:= data["system_key"].(string)
|
|
|
id:= data["id"].(string)
|
|
|
|
|
|
if systemToken==MD5Util.MD5V1(MD5Util.MD5V1(systemID + authTime) + systemKey){
|
|
|
|
|
|
nowTime := time.Now()
|
|
|
authToken := "DSDataex_Token_"+MD5Util.MD5V1(systemID + nowTime.Format("2004-01-02 15:04:05") + systemKey)
|
|
|
|
|
|
AuthDAO.Update(id,authToken,nowTime)
|
|
|
|
|
|
return true,"接入系统Token验证成功",authToken
|
|
|
}else {
|
|
|
|
|
|
return false,"接入系统Token验证失败,请确认Token生成策略是否正确",""
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return true,"",""
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @Author zhangjun
|
|
|
* @Description
|
|
|
* @Date 2020-06-12 10:30
|
|
|
* @Param systemid string 接入系统code
|
|
|
* @Param authToken string 系统票据
|
|
|
* @return bool 成功/失败
|
|
|
* @return string 结果说明
|
|
|
**/
|
|
|
func CheckToken(systemID string,authToken string) (bool, string,string){
|
|
|
|
|
|
success,result,data,_:= AuthDAO.GetbyCode(systemID)
|
|
|
|
|
|
if success==false{
|
|
|
|
|
|
return false,result,""
|
|
|
}else {
|
|
|
myToken:= data["auth_token"].(string)
|
|
|
|
|
|
if myToken==authToken{
|
|
|
|
|
|
return true,"接入系统票据验证成功",data["id"].(string)
|
|
|
}else {
|
|
|
|
|
|
return false,"接入系统票据验证失败",""
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func CheckAccessToken(systemID string,accessTime string,accessToken string) (bool, string,string){
|
|
|
|
|
|
success,result,data,_:= AuthDAO.GetbyCode(systemID)
|
|
|
|
|
|
if success==false{
|
|
|
|
|
|
return false,result,""
|
|
|
}else {
|
|
|
myToken:= data["auth_token"].(string)
|
|
|
|
|
|
var testToken=MD5Util.MD5V1(systemID + accessTime + myToken)
|
|
|
|
|
|
if testToken==accessToken{
|
|
|
|
|
|
return true,"接入系统票据验证成功",data["id"].(string)
|
|
|
}else {
|
|
|
|
|
|
return false,"接入系统票据验证失败",data["id"].(string)
|
|
|
}
|
|
|
}
|
|
|
} |