feat: 重构配置层,添加 json 支持

This commit is contained in:
Mmx233
2023-08-28 22:03:03 +08:00
parent 2a098e00dd
commit 6f283a93f5
19 changed files with 318 additions and 272 deletions

View File

@@ -1,18 +1,18 @@
package srun
type LoginForm struct {
Domain string `json:"domain"`
UserName string `json:"username"`
Domain string `json:"domain" yaml:"domain"`
Username string `json:"username" yaml:"username"`
//运营商类型
UserType string `json:"user_type"`
PassWord string `json:"password"`
UserType string `json:"user_type" yaml:"userType"`
Password string `json:"password" yaml:"password"`
}
type LoginMeta struct {
N string `json:"n"`
Type string `json:"type"`
Acid string `json:"acid"`
Enc string `json:"enc"`
N string `json:"n" yaml:"n"`
Type string `json:"type" yaml:"type"`
Acid string `json:"acid" yaml:"acid"`
Enc string `json:"enc" yaml:"enc"`
}
type LoginInfo struct {

View File

@@ -63,10 +63,10 @@ func (c Srun) DoLogin(clientIP string) error {
log.Debugln("正在获取 Token")
if c.LoginInfo.Form.UserType != "" {
c.LoginInfo.Form.UserName += "@" + c.LoginInfo.Form.UserType
c.LoginInfo.Form.Username += "@" + c.LoginInfo.Form.UserType
}
res, e := c.api.GetChallenge(c.LoginInfo.Form.UserName, clientIP)
res, e := c.api.GetChallenge(c.LoginInfo.Form.Username, clientIP)
if e != nil {
return e
}
@@ -80,8 +80,8 @@ func (c Srun) DoLogin(clientIP string) error {
log.Debugln("发送登录请求")
info, e := json.Marshal(map[string]string{
"username": c.LoginInfo.Form.UserName,
"password": c.LoginInfo.Form.PassWord,
"username": c.LoginInfo.Form.Username,
"password": c.LoginInfo.Form.Password,
"ip": clientIP,
"acid": c.LoginInfo.Meta.Acid,
"enc_ver": c.LoginInfo.Meta.Enc,
@@ -93,14 +93,14 @@ func (c Srun) DoLogin(clientIP string) error {
Md5Str := Md5(tokenStr)
EncryptedMd5 := "{MD5}" + Md5Str
EncryptedChkstr := Sha1(
tokenStr + c.LoginInfo.Form.UserName + tokenStr + Md5Str +
tokenStr + c.LoginInfo.Form.Username + tokenStr + Md5Str +
tokenStr + c.LoginInfo.Meta.Acid + tokenStr + clientIP +
tokenStr + c.LoginInfo.Meta.N + tokenStr + c.LoginInfo.Meta.Type +
tokenStr + EncryptedInfo,
)
res, e = c.api.Login(
c.LoginInfo.Form.UserName,
c.LoginInfo.Form.Username,
EncryptedMd5,
c.LoginInfo.Meta.Acid,
clientIP,