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) }