diff --git a/models/config.go b/models/config.go index a08f585..39e808b 100644 --- a/models/config.go +++ b/models/config.go @@ -1,7 +1,7 @@ package srunModels import ( - srunTransfer "github.com/Mmx233/BitSrunLoginGo/v1" + "github.com/Mmx233/BitSrunLoginGo/v1" ) type Daemon struct { @@ -36,7 +36,7 @@ type Settings struct { } type Config struct { - Form srunTransfer.LoginForm `json:"form" yaml:"form" mapstructure:"form"` - Meta srunTransfer.LoginMeta `json:"meta" yaml:"meta" mapstructure:"meta"` - Settings Settings `json:"settings" yaml:"settings" mapstructure:"settings"` + Form BitSrun.LoginForm `json:"form" yaml:"form" mapstructure:"form"` + Meta BitSrun.LoginMeta `json:"meta" yaml:"meta" mapstructure:"meta"` + Settings Settings `json:"settings" yaml:"settings" mapstructure:"settings"` } diff --git a/models/login.go b/models/login.go deleted file mode 100644 index adb9681..0000000 --- a/models/login.go +++ /dev/null @@ -1,18 +0,0 @@ -package srunModels - -import ( - "github.com/Mmx233/BitSrunLoginGo/v1" -) - -type LoginInfo struct { - Ip string - Token string - EncryptedInfo string - Md5 string - EncryptedMd5 string - EncryptedChkstr string - LoginResult string - - Form *BitSrun.LoginForm - Meta *BitSrun.LoginMeta -} diff --git a/util/config.go b/util/config.go deleted file mode 100644 index dc3a89b..0000000 --- a/util/config.go +++ /dev/null @@ -1,22 +0,0 @@ -package util - -import ( - "github.com/Mmx233/BitSrunLoginGo/models" - "github.com/Mmx233/BitSrunLoginGo/v1" -) - -func GenerateLoginInfo(Form *BitSrun.LoginForm, Meta *BitSrun.LoginMeta) *srunModels.LoginInfo { - return &srunModels.LoginInfo{ - Meta: Meta, - Form: &BitSrun.LoginForm{ - UserName: func() string { - if Form.UserType == "" { - return Form.UserName - } else { - return Form.UserName + "@" + Form.UserType - } - }(), - PassWord: Form.PassWord, - }, - } -} diff --git a/util/XBase64.go b/v1/XBase64.go similarity index 98% rename from util/XBase64.go rename to v1/XBase64.go index c44d656..8f058eb 100644 --- a/util/XBase64.go +++ b/v1/XBase64.go @@ -1,4 +1,4 @@ -package util +package BitSrun import log "github.com/sirupsen/logrus" diff --git a/util/XEncode.go b/v1/XEncode.go similarity index 99% rename from util/XEncode.go rename to v1/XEncode.go index 3f0c64f..e2a3aaf 100644 --- a/util/XEncode.go +++ b/v1/XEncode.go @@ -1,4 +1,4 @@ -package util +package BitSrun import ( "math" diff --git a/v1/config.go b/v1/config.go new file mode 100644 index 0000000..81b2ba7 --- /dev/null +++ b/v1/config.go @@ -0,0 +1,17 @@ +package BitSrun + +func GenerateLoginInfo(Form *LoginForm, Meta *LoginMeta) *LoginContext { + return &LoginContext{ + Meta: Meta, + Form: &LoginForm{ + UserName: func() string { + if Form.UserType == "" { + return Form.UserName + } else { + return Form.UserName + "@" + Form.UserType + } + }(), + PassWord: Form.PassWord, + }, + } +} diff --git a/util/util.go b/v1/encode.go similarity index 95% rename from util/util.go rename to v1/encode.go index 2cf0ebc..6d518c3 100644 --- a/util/util.go +++ b/v1/encode.go @@ -1,4 +1,4 @@ -package util +package BitSrun import ( "crypto/md5" diff --git a/v1/login.go b/v1/login.go index c5f5c59..e6dc5c2 100644 --- a/v1/login.go +++ b/v1/login.go @@ -3,13 +3,12 @@ package BitSrun import ( "encoding/json" "errors" - "github.com/Mmx233/BitSrunLoginGo/util" log "github.com/sirupsen/logrus" ) func Login(c *Conf) error { c.initApi() - G := util.GenerateLoginInfo(c.LoginInfo.Form, c.LoginInfo.Meta) + G := GenerateLoginInfo(c.LoginInfo.Form, c.LoginInfo.Meta) log.Debugln("正在检查登录状态") @@ -63,15 +62,15 @@ func Login(c *Conf) error { if e != nil { return e } - G.EncryptedInfo = "{SRBX1}" + util.Base64(util.XEncode(string(info), G.Token)) - G.Md5 = util.Md5(G.Token) + G.EncryptedInfo = "{SRBX1}" + Base64(XEncode(string(info), G.Token)) + G.Md5 = Md5(G.Token) G.EncryptedMd5 = "{MD5}" + G.Md5 var chkstr = G.Token + G.Form.UserName + G.Token + G.Md5 chkstr += G.Token + G.Meta.Acid + G.Token + G.Ip chkstr += G.Token + G.Meta.N + G.Token + G.Meta.Type chkstr += G.Token + G.EncryptedInfo - G.EncryptedChkstr = util.Sha1(chkstr) + G.EncryptedChkstr = Sha1(chkstr) res, e = c.api.Login( G.Form.UserName, diff --git a/v1/models.go b/v1/models.go index a2a1f3f..8c68aab 100644 --- a/v1/models.go +++ b/v1/models.go @@ -38,3 +38,16 @@ type Conf struct { func (a *Conf) initApi() { a.api.Init(a.Https, a.LoginInfo.Form.Domain, a.Client) } + +type LoginContext struct { + Ip string + Token string + EncryptedInfo string + Md5 string + EncryptedMd5 string + EncryptedChkstr string + LoginResult string + + Form *LoginForm + Meta *LoginMeta +}