This commit is contained in:
jiangyong 2026-07-05 12:10:27 +08:00
parent e50a565e80
commit c726d792bd
1 changed files with 22 additions and 4 deletions

View File

@ -8,10 +8,23 @@ import (
"github.com/tidwall/gjson"
)
const (
LoginTypePassword = "password"
LoginTypeVerify = "verify"
)
type StaffCode struct {
Timestamp string `json:"timestamp"`
}
type StaffInfo struct {
type LoginReq struct {
Type string `json:"type"`
Username string `json:"username"`
Password string `json:"password"`
Timestamp string `json:"timestamp"`
}
type LoginRsp struct {
Username string `json:"username"`
Realname string `json:"realname"`
Phone string `json:"phone"`
@ -48,8 +61,13 @@ func (e *StaffUser) SendCode(username, scene string) (*StaffCode, error) {
return r, nil
}
func (e *StaffUser) Login(username, timestamp, code string) (*StaffInfo, error) {
reqBody := fmt.Sprintf(`{"username":"%s","timestamp":"%s","code":"%s"}`, username, timestamp, code)
func (e *StaffUser) Login(req *LoginReq) (*LoginRsp, error) {
var reqBody string
reqBody = fmt.Sprintf(`{"username":"%s","password":"%s", timestamp":"%s","type":"%s"}`,
req.Username, req.Password, req.Timestamp, req.Type)
reqUrl := e.GetBaseUrl() + "/ext/staff/user/login"
body, err := goutil.HttpPost(reqUrl, e.GetHeader(), []byte(reqBody))
if err != nil {
@ -60,7 +78,7 @@ func (e *StaffUser) Login(username, timestamp, code string) (*StaffInfo, error)
return nil, errors.New(string(body))
}
r := new(StaffInfo)
r := new(LoginRsp)
r.Realname = g.Get("data.realname").String()
r.Username = g.Get("data.username").String()
r.Phone = g.Get("data.phone").String()