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

云众

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