47 lines
1007 B
Go
47 lines
1007 B
Go
package http_api
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"gitea.ddegame.cn/open/servicebase/pkg/log"
|
|
"gitea.ddegame.cn/open/servicebase/pkg/res"
|
|
"gitea.ddegame.cn/open/servicebase/pkg/utils"
|
|
|
|
"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)
|
|
}
|