This commit is contained in:
2022-03-17 15:55:27 +08:00
commit bd5a9fad97
92 changed files with 13861 additions and 0 deletions

67
logic/auth/zhaobi/auth.go Normal file
View File

@@ -0,0 +1,67 @@
package acc
import (
"encoding/json"
"errors"
"time"
"gitlab.33.cn/btrade/auto_trade_tools/reqtypes"
"gitlab.33.cn/btrade/auto_trade_tools/util"
)
type talkClient struct {
url string
timeout time.Duration
}
func (a *talkClient) DoAuth(token string) (uid string, err error) {
var (
bytes []byte
)
headers := map[string]string{}
headers["Authorization"] = token
bytes, err = util.HttpReq(&reqtypes.HttpParams{
Method: "GET",
ReqUrl: a.url,
HeaderMap: headers,
Timeout: a.timeout,
})
if err != nil {
return
}
var res map[string]interface{}
err = json.Unmarshal(bytes, &res)
if err != nil {
return
}
if e, ok := res["error"]; ok {
err = errors.New(e.(string))
return
}
if _, ok := res["data"]; !ok {
err = errors.New("invalid auth res")
return
}
data, ok := res["data"].(map[string]interface{})
if !ok {
err = errors.New("invalid auth data format")
return
}
if _, ok := data["user_id"]; !ok {
err = errors.New("invalid auth data")
return
}
uid, ok = data["user_id"].(string)
if !ok {
err = errors.New("invalid auth data id format")
return
}
return
}