first commit
This commit is contained in:
45
pkg/client/http_api/user.go
Normal file
45
pkg/client/http_api/user.go
Normal file
@ -0,0 +1,45 @@
|
||||
package http_api
|
||||
|
||||
import (
|
||||
"servicebase/pkg/log"
|
||||
"servicebase/pkg/res"
|
||||
"servicebase/pkg/utils"
|
||||
"errors"
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
type InnerLoginReq struct {
|
||||
Mobile string `json:"mobile"`
|
||||
Signature string `json:"signature"`
|
||||
}
|
||||
|
||||
type InnerLoginRes struct {
|
||||
Code string
|
||||
Result res.AccessTokenDTO
|
||||
Msg string
|
||||
}
|
||||
|
||||
func InnerLogin(url, secret, mobile string) (token string, e error) {
|
||||
var req = map[string]string{
|
||||
"mobile": mobile,
|
||||
}
|
||||
sign := utils.CreateApiSign(req, secret)
|
||||
req["Signature"] = sign
|
||||
client := resty.New()
|
||||
_ = client
|
||||
var res InnerLoginRes
|
||||
resp, err := client.R().
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetBody(req).
|
||||
SetResult(&res). // or SetResult(AuthSuccess{}).
|
||||
Post(url)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
log.InfoF("%++v %v", res, string(resp.Body()))
|
||||
if res.Code == "8000" {
|
||||
return res.Result.AccessToken, nil
|
||||
}
|
||||
return "", errors.New("登录失败:" + res.Msg)
|
||||
}
|
||||
Reference in New Issue
Block a user