improve: 优化包引用
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
package srunModels
|
package srunModels
|
||||||
|
|
||||||
import (
|
import (
|
||||||
srunTransfer "github.com/Mmx233/BitSrunLoginGo/v1"
|
"github.com/Mmx233/BitSrunLoginGo/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Daemon struct {
|
type Daemon struct {
|
||||||
@@ -36,7 +36,7 @@ type Settings struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Form srunTransfer.LoginForm `json:"form" yaml:"form" mapstructure:"form"`
|
Form BitSrun.LoginForm `json:"form" yaml:"form" mapstructure:"form"`
|
||||||
Meta srunTransfer.LoginMeta `json:"meta" yaml:"meta" mapstructure:"meta"`
|
Meta BitSrun.LoginMeta `json:"meta" yaml:"meta" mapstructure:"meta"`
|
||||||
Settings Settings `json:"settings" yaml:"settings" mapstructure:"settings"`
|
Settings Settings `json:"settings" yaml:"settings" mapstructure:"settings"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
@@ -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,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package util
|
package BitSrun
|
||||||
|
|
||||||
import log "github.com/sirupsen/logrus"
|
import log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package util
|
package BitSrun
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
"math"
|
||||||
17
v1/config.go
Normal file
17
v1/config.go
Normal file
@@ -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,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package util
|
package BitSrun
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
@@ -3,13 +3,12 @@ package BitSrun
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/Mmx233/BitSrunLoginGo/util"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Login(c *Conf) error {
|
func Login(c *Conf) error {
|
||||||
c.initApi()
|
c.initApi()
|
||||||
G := util.GenerateLoginInfo(c.LoginInfo.Form, c.LoginInfo.Meta)
|
G := GenerateLoginInfo(c.LoginInfo.Form, c.LoginInfo.Meta)
|
||||||
|
|
||||||
log.Debugln("正在检查登录状态")
|
log.Debugln("正在检查登录状态")
|
||||||
|
|
||||||
@@ -63,15 +62,15 @@ func Login(c *Conf) error {
|
|||||||
if e != nil {
|
if e != nil {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
G.EncryptedInfo = "{SRBX1}" + util.Base64(util.XEncode(string(info), G.Token))
|
G.EncryptedInfo = "{SRBX1}" + Base64(XEncode(string(info), G.Token))
|
||||||
G.Md5 = util.Md5(G.Token)
|
G.Md5 = Md5(G.Token)
|
||||||
G.EncryptedMd5 = "{MD5}" + G.Md5
|
G.EncryptedMd5 = "{MD5}" + G.Md5
|
||||||
|
|
||||||
var chkstr = G.Token + G.Form.UserName + G.Token + 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.Acid + G.Token + G.Ip
|
||||||
chkstr += G.Token + G.Meta.N + G.Token + G.Meta.Type
|
chkstr += G.Token + G.Meta.N + G.Token + G.Meta.Type
|
||||||
chkstr += G.Token + G.EncryptedInfo
|
chkstr += G.Token + G.EncryptedInfo
|
||||||
G.EncryptedChkstr = util.Sha1(chkstr)
|
G.EncryptedChkstr = Sha1(chkstr)
|
||||||
|
|
||||||
res, e = c.api.Login(
|
res, e = c.api.Login(
|
||||||
G.Form.UserName,
|
G.Form.UserName,
|
||||||
|
|||||||
13
v1/models.go
13
v1/models.go
@@ -38,3 +38,16 @@ type Conf struct {
|
|||||||
func (a *Conf) initApi() {
|
func (a *Conf) initApi() {
|
||||||
a.api.Init(a.Https, a.LoginInfo.Form.Domain, a.Client)
|
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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user