提交 ca4aeb06 authored 作者: 张立波's avatar 张立波

云众

上级 241a2e03
......@@ -27,8 +27,6 @@ type Client struct {
Source int
}
var server *Client
const Url = "https://supply.yunzmall.com/supplyapi"
const pkgName = "yunzmall"
const CacheKey = "yunzmall:token:"
......@@ -59,7 +57,7 @@ func (s *Client) post(ctx context.Context, method string, params g.Map, xToken .
}
Request.SetHeader("x-token", token)
}
AppSign, err := sign(AppNonce, AppTimestamp, params)
AppSign, err := s.sign(AppNonce, AppTimestamp, params)
if err != nil {
return
}
......@@ -100,7 +98,7 @@ func (s *Client) get(ctx context.Context, method string, params g.Map, xToken ..
}
Request.SetHeader("x-token", token)
}
AppSign, err := sign(AppNonce, AppTimestamp, params)
AppSign, err := s.sign(AppNonce, AppTimestamp, params)
if err != nil {
return
}
......@@ -133,7 +131,7 @@ func (s *Client) get(ctx context.Context, method string, params g.Map, xToken ..
return
}
func sign(nonce string, timestamp string, param g.Map) (res string, err error) {
func (s *Client) sign(nonce string, timestamp string, param g.Map) (res string, err error) {
var keys []string
keys = append(keys, "App-Nonce-Str")
keys = append(keys, "App-Timestamp")
......@@ -151,8 +149,8 @@ func sign(nonce string, timestamp string, param g.Map) (res string, err error) {
for _, v := range keys {
array.Append(fmt.Sprintf("%s=%s", v, gconv.String(mewparam[v])))
}
array.Append(fmt.Sprintf("%s=%s", "appKey", server.AppKey))
array.Append(fmt.Sprintf("%s=%s", "appSecret", server.AppSecret))
array.Append(fmt.Sprintf("%s=%s", "appKey", s.AppKey))
array.Append(fmt.Sprintf("%s=%s", "appSecret", s.AppSecret))
var str = array.Join("&")
str, err = gregex.ReplaceString(`\s`, "", str)
if err != nil {
......
......@@ -21,8 +21,8 @@ type TokenGetRes struct {
func (s *Client) GetToken(ctx context.Context) (res *TokenGetRes, err error) {
var method = "/app/application/getToken"
result, err := s.post(ctx, method, g.Map{
"app_key": server.AppKey,
"app_secret": server.AppSecret,
"app_key": s.AppKey,
"app_secret": s.AppSecret,
}, true)
if err != nil {
return
......@@ -39,7 +39,7 @@ func (s *Client) RefreshToken(ctx context.Context) (res string, err error) {
defer func() {
_ = conn.Close()
}()
_, _ = conn.DoVar("SELECT", server.DB)
_, _ = conn.DoVar("SELECT", s.DB)
var result *TokenGetRes
result, err = s.GetToken(ctx)
if err != nil {
......@@ -65,7 +65,7 @@ func (s *Client) AccessToken(ctx context.Context) (res string, err error) {
defer func() {
_ = conn.Close()
}()
_, _ = conn.DoVar("SELECT", server.DB)
_, _ = conn.DoVar("SELECT", s.DB)
cache, _ := conn.DoVar("HGETALL", CacheKey)
g.Log().Line(true).Info(cache.String())
if cache.IsEmpty() {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论