提交 fe5073a4 authored 作者: zhanglibo's avatar zhanglibo

变更结构体

上级 40e3ca5b
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"crypto/sha256" "crypto/sha256"
"encoding/hex" "encoding/hex"
"github.com/gogf/gf/container/garray" "github.com/gogf/gf/container/garray"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g" "github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/gtime" "github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/util/gconv" "github.com/gogf/gf/util/gconv"
...@@ -30,32 +31,31 @@ func New(config *Config) { ...@@ -30,32 +31,31 @@ func New(config *Config) {
return return
} }
func (c *Config) Post(ctx context.Context, api string, bodyMap g.Map) (result string, err error) {
func (c *Config)Post(ctx context.Context, api string, bodyMap g.Map) (result string, err error) {
Start := gtime.TimestampMilli() Start := gtime.TimestampMilli()
pubilcParams := new(PubilcParams) pubilcParams := new(PubilcParams)
pubilcParams.AppID = c.AppKey pubilcParams.AppID = c.AppKey
pubilcParams.Timestamp = gtime.TimestampStr() pubilcParams.Timestamp = gtime.TimestampStr()
pubilcParams.Nonce = grand.S(16,false) pubilcParams.Nonce = grand.S(16, false)
secret := c.AppSecret secret := c.AppSecret
sign := c.Sign(ctx,*pubilcParams, bodyMap, secret) sign := c.Sign(ctx, *pubilcParams, bodyMap, secret)
defer func() { defer func() {
ctx = context.WithValue(ctx, "URI", api) ctx = context.WithValue(ctx, "URI", api)
if err != nil { if err != nil {
g.Log().Ctx(ctx).Cat("error").Async(true). g.Log().Ctx(ctx).Cat("error").Async(true).
Infof("参数【%v】错误【%v】响应时间:【%v ms】", bodyMap, err.Error(), gtime.TimestampMilli()-Start) Infof("参数【%v】错误【%v】响应时间:【%v ms】", gjson.New(bodyMap).MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
} else { } else {
g.Log().Ctx(ctx).Cat(pkgName).Async(true). g.Log().Ctx(ctx).Cat(pkgName).Async(true).
Infof("参数【%v】响应【%v】响应时间:【%v ms】", bodyMap, result, gtime.TimestampMilli()-Start) Infof("参数【%v】响应【%v】响应时间:【%v ms】", gjson.New(bodyMap).MustToJsonString(), result, gtime.TimestampMilli()-Start)
} }
}() }()
pubilcParams.Signature = sign pubilcParams.Signature = sign
pubilcParamsMap := gconv.Map(pubilcParams) pubilcParamsMap := gconv.Map(pubilcParams)
for k,v := range pubilcParamsMap{ for k, v := range pubilcParamsMap {
bodyMap[k] = v bodyMap[k] = v
} }
response, err := g.Client().Ctx(ctx). response, err := g.Client().Ctx(ctx).
...@@ -67,8 +67,7 @@ func (c *Config)Post(ctx context.Context, api string, bodyMap g.Map) (result str ...@@ -67,8 +67,7 @@ func (c *Config)Post(ctx context.Context, api string, bodyMap g.Map) (result str
return return
} }
func (c *Config) Sign(ctx context.Context, pubilcParams PubilcParams, params g.Map, secret string) (sign string) {
func (c *Config)Sign(ctx context.Context,pubilcParams PubilcParams,params g.Map , secret string)(sign string){
allMaps := make(map[string]string) allMaps := make(map[string]string)
var arr = garray.New().Append("appId", "timestamp", "nonce") var arr = garray.New().Append("appId", "timestamp", "nonce")
...@@ -79,11 +78,10 @@ func (c *Config)Sign(ctx context.Context,pubilcParams PubilcParams,params g.Map ...@@ -79,11 +78,10 @@ func (c *Config)Sign(ctx context.Context,pubilcParams PubilcParams,params g.Map
} }
allMaps["secret"] = secret allMaps["secret"] = secret
for k,v := range params{ for k, v := range params {
allMaps[k] = gconv.String(v) allMaps[k] = gconv.String(v)
} }
keys := make([]string, 0) keys := make([]string, 0)
for k := range allMaps { for k := range allMaps {
keys = append(keys, k) keys = append(keys, k)
...@@ -98,17 +96,14 @@ func (c *Config)Sign(ctx context.Context,pubilcParams PubilcParams,params g.Map ...@@ -98,17 +96,14 @@ func (c *Config)Sign(ctx context.Context,pubilcParams PubilcParams,params g.Map
paramsString += v + "=" + allMaps[v] paramsString += v + "=" + allMaps[v]
} }
paramsString += "&key="+secret paramsString += "&key=" + secret
hmacSha256String := hmacSha256(paramsString,secret) hmacSha256String := hmacSha256(paramsString, secret)
sign = strings.ToUpper(hmacSha256String) sign = strings.ToUpper(hmacSha256String)
return return
} }
func hmacSha256(data string, secret string) string { func hmacSha256(data string, secret string) string {
h := hmac.New(sha256.New, []byte(secret)) h := hmac.New(sha256.New, []byte(secret))
h.Write([]byte(data)) h.Write([]byte(data))
......
...@@ -112,15 +112,15 @@ type SyncOrderExpNoReq struct { ...@@ -112,15 +112,15 @@ type SyncOrderExpNoReq struct {
type SyncOrderExpNoRes struct { type SyncOrderExpNoRes struct {
CommonRes CommonRes
Result struct { Result []struct {
UnionId string `json:"unionId"` //平台订单编号 UnionId string `json:"unionId"` //平台订单编号
ExpNo string `json:"expNo"` //快递/物流单号 ExpNo []string `json:"expNo"` //快递/物流单号
} `json:"result"` } `json:"result"`
} }
type QueryExpTrackReq struct { type QueryExpTrackReq struct {
UnionId string `json:"unionId"` //平台订单编号,用于后续操作平台订单 UnionId string `json:"unionId"` //平台订单编号,用于后续操作平台订单
ExpNos []string `json:"expNos"` //订单对应的快递单号数组 ExpNos string `json:"expNo"` //订单对应的快递单号数组
BusinessId string `json:"businessId"` //业务订单编号(平台中所查看到的订单编号) BusinessId string `json:"businessId"` //业务订单编号(平台中所查看到的订单编号)
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论