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

盛创汇联

上级 43ef66e4
...@@ -12,13 +12,16 @@ import ( ...@@ -12,13 +12,16 @@ import (
"github.com/gogf/gf/text/gregex" "github.com/gogf/gf/text/gregex"
"github.com/gogf/gf/util/gconv" "github.com/gogf/gf/util/gconv"
"github.com/gogf/gf/util/grand" "github.com/gogf/gf/util/grand"
"regexp" "net/url"
"sort" "sort"
"strings" "strings"
"time"
) )
var server *Config var server *Config
const Host = "https://schl-api.szbaoly.com"
type Config struct { type Config struct {
ApiUrl string ApiUrl string
AppKey string AppKey string
...@@ -32,7 +35,7 @@ type CommonRes struct { ...@@ -32,7 +35,7 @@ type CommonRes struct {
} }
type PubilcParams struct { type PubilcParams struct {
AppID string `json:"appId"` AppID string `json:"appid"`
Nonce string `json:"nonce"` Nonce string `json:"nonce"`
Timestamp string `json:"timestamp"` Timestamp string `json:"timestamp"`
Signature string `json:"signature"` Signature string `json:"signature"`
...@@ -45,18 +48,17 @@ func New(config *Config) { ...@@ -45,18 +48,17 @@ 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, URL 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 c.Sign(pubilcParams)
sign := c.Sign(ctx, *pubilcParams, bodyMap, secret)
defer func() { defer func() {
ctx = context.WithValue(ctx, "URI", api) ctx = context.WithValue(ctx, "URI", URL)
if err != nil { if err != nil {
g.Log().Ctx(ctx).Cat(pkgName).Cat("error"). g.Log().Ctx(ctx).Cat(pkgName).Cat("error").
Infof("参数【%v】错误【%v】响应时间:【%v ms】", gjson.New(bodyMap).MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start) Infof("参数【%v】错误【%v】响应时间:【%v ms】", gjson.New(bodyMap).MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
...@@ -65,15 +67,16 @@ func (c *Config) Post(ctx context.Context, api string, bodyMap g.Map) (result st ...@@ -65,15 +67,16 @@ func (c *Config) Post(ctx context.Context, api string, bodyMap g.Map) (result st
Infof("参数【%v】响应【%v】响应时间:【%v ms】", gjson.New(bodyMap).MustToJsonString(), result, gtime.TimestampMilli()-Start) Infof("参数【%v】响应【%v】响应时间:【%v ms】", gjson.New(bodyMap).MustToJsonString(), result, gtime.TimestampMilli()-Start)
} }
}() }()
var value = url.Values{}
pubilcParams.Signature = sign value.Add("appid", pubilcParams.AppID)
value.Add("nonce", pubilcParams.Nonce)
pubilcParamsMap := gconv.Map(pubilcParams) value.Add("timestamp", pubilcParams.Timestamp)
for k, v := range pubilcParamsMap { value.Add("signature", pubilcParams.Signature)
bodyMap[k] = v
} response, err := g.Client().
response, err := g.Client().Ctx(ctx). Timeout(time.Second*3).
Post(c.ApiUrl+api, bodyMap) ContentJson().
Post(Host+URL+"?"+value.Encode(), bodyMap)
defer func() { defer func() {
_ = response.Close() _ = response.Close()
}() }()
...@@ -84,21 +87,14 @@ func (c *Config) Post(ctx context.Context, api string, bodyMap g.Map) (result st ...@@ -84,21 +87,14 @@ func (c *Config) Post(ctx context.Context, api string, bodyMap g.Map) (result st
return return
} }
func (c *Config) Sign(ctx context.Context, pubilcParams PubilcParams, params g.Map, secret string) (sign string) { func (c *Config) Sign(pubilcParams *PubilcParams) {
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")
for k, v := range gconv.MapStrStr(pubilcParams) { for k, v := range gconv.MapStrStr(pubilcParams) {
if arr.Contains(k) { if arr.Contains(k) {
allMaps[k] = v allMaps[k] = v
} }
} }
allMaps["secret"] = secret
for k, v := range params {
re3, _ := regexp.Compile(`\s`)
allMaps[k] = re3.ReplaceAllString(gconv.String(v), "")
}
keys := make([]string, 0) keys := make([]string, 0)
for k := range allMaps { for k := range allMaps {
...@@ -114,11 +110,11 @@ func (c *Config) Sign(ctx context.Context, pubilcParams PubilcParams, params g.M ...@@ -114,11 +110,11 @@ func (c *Config) Sign(ctx context.Context, pubilcParams PubilcParams, params g.M
paramsString += v + "=" + allMaps[v] paramsString += v + "=" + allMaps[v]
} }
paramsString += "&key=" + secret paramsString += "&key=" + server.AppSecret
hmacSha256String := hmacSha256(paramsString, secret) hmacSha256String := hmacSha256(paramsString, server.AppSecret)
sign = strings.ToUpper(hmacSha256String) pubilcParams.Signature = strings.ToUpper(hmacSha256String)
return return
} }
......
...@@ -22,7 +22,10 @@ type BrandListRes struct { ...@@ -22,7 +22,10 @@ type BrandListRes struct {
// List 获取商品品牌 // List 获取商品品牌
func (*brandLogic) List(ctx context.Context) (res *BrandListRes, err error) { func (*brandLogic) List(ctx context.Context) (res *BrandListRes, err error) {
result, err := server.Post(ctx, "/open/xdxt/api/v2/goods/listGoodsCategory", g.Map{}) result, err := server.Post(ctx, "/open/xdxt/api/v2/goods/listGoodsBrand", g.Map{})
if err != nil {
return
}
err = gjson.New(result).Scan(&res) err = gjson.New(result).Scan(&res)
return return
} }
...@@ -24,6 +24,9 @@ type CategoryListRes struct { ...@@ -24,6 +24,9 @@ type CategoryListRes struct {
// List 获取商品分类 // List 获取商品分类
func (*categoryLogic) List(ctx context.Context) (res *CategoryListRes, err error) { func (*categoryLogic) List(ctx context.Context) (res *CategoryListRes, err error) {
result, err := server.Post(ctx, "/open/xdxt/api/v2/goods/listGoodsCategory", g.Map{}) result, err := server.Post(ctx, "/open/xdxt/api/v2/goods/listGoodsCategory", g.Map{})
if err != nil {
return
}
err = gjson.New(result).Scan(&res) err = gjson.New(result).Scan(&res)
return return
} }
...@@ -23,6 +23,9 @@ type GoodsEventRes struct { ...@@ -23,6 +23,9 @@ type GoodsEventRes struct {
func (*goodsLogic) Event(ctx context.Context) (res *GoodsEventRes, err error) { func (*goodsLogic) Event(ctx context.Context) (res *GoodsEventRes, err error) {
result, err := server.Post(ctx, "/open/xdxt/api/v2/goods/listGoodsChangeEvent", g.Map{}) result, err := server.Post(ctx, "/open/xdxt/api/v2/goods/listGoodsChangeEvent", g.Map{})
if err != nil {
return
}
err = gjson.New(result).Scan(&res) err = gjson.New(result).Scan(&res)
return return
......
...@@ -9,14 +9,16 @@ import ( ...@@ -9,14 +9,16 @@ import (
type GoodsListReq struct { type GoodsListReq struct {
Current int `json:"current,omitempty"` Current int `json:"current,omitempty"`
Size int `json:"size,omitempty"` Size int `json:"size,omitempty"`
Query struct { Query GoodsListQuery `json:"query"`
}
type GoodsListQuery struct {
QueryType int `json:"queryType"` //1:全量商品查询 2:选品库商品查询 QueryType int `json:"queryType"` //1:全量商品查询 2:选品库商品查询
GoodsIds []int `json:"goodsIds,omitempty"` //商品id数组,长度最大为100 GoodsIds []int `json:"goodsIds,omitempty"` //商品id数组,长度最大为100
GoodsCode string `json:"goodsCode,omitempty"` //商品规格编码 GoodsCode string `json:"goodsCode,omitempty"` //商品规格编码
CategoryId1 int `json:"categoryId,omitempty"` //商品分类id CategoryId1 int `json:"categoryId,omitempty"` //商品分类id
CategoryId2 int `json:"twoCategoryId,omitempty"` //二级分类id CategoryId2 int `json:"twoCategoryId,omitempty"` //二级分类id
CategoryId3 int `json:"treeCategoryId,omitempty"` //二级分类id CategoryId3 int `json:"treeCategoryId,omitempty"` //二级分类id
} `json:"query"`
} }
type GoodsListRes struct { type GoodsListRes struct {
...@@ -70,10 +72,9 @@ type GoodsListRes struct { ...@@ -70,10 +72,9 @@ type GoodsListRes struct {
func (*goodsLogic) List(ctx context.Context, req GoodsListReq) (res *GoodsListRes, err error) { func (*goodsLogic) List(ctx context.Context, req GoodsListReq) (res *GoodsListRes, err error) {
result, err := server.Post(ctx, "/open/xdxt/api/v2/goods/listGoods", gconv.Map(req)) result, err := server.Post(ctx, "/open/xdxt/api/v2/goods/listGoods", gconv.Map(req))
err = gjson.New(result).Scan(&res)
if err != nil { if err != nil {
return return
} }
err = gjson.New(result).Scan(&res)
return return
} }
...@@ -37,10 +37,10 @@ type LogisticsTraceRes struct { ...@@ -37,10 +37,10 @@ type LogisticsTraceRes struct {
func (s *logisticsLogic) Trace(ctx context.Context, req LogisticsTraceReq) (res *LogisticsTraceRes, err error) { func (s *logisticsLogic) Trace(ctx context.Context, req LogisticsTraceReq) (res *LogisticsTraceRes, err error) {
result, err := server.Post(ctx, "/open/xdxt/api/v2/order/queryExpTrack", gconv.Map(req)) result, err := server.Post(ctx, "/open/xdxt/api/v2/order/queryExpTrack", gconv.Map(req))
err = gjson.New(result).Scan(&res)
if err != nil { if err != nil {
return return
} }
err = gjson.New(result).Scan(&res)
return return
} }
...@@ -35,10 +35,10 @@ type OrderBeforeRes struct { ...@@ -35,10 +35,10 @@ type OrderBeforeRes struct {
func (s *orderLogic) Before(ctx context.Context, req OrderBeforeReq) (res *OrderBeforeRes, err error) { func (s *orderLogic) Before(ctx context.Context, req OrderBeforeReq) (res *OrderBeforeRes, err error) {
result, err := server.Post(ctx, "/open/xdxt/api/v2/order/orderFreightPreview", gconv.Map(req)) result, err := server.Post(ctx, "/open/xdxt/api/v2/order/orderFreightPreview", gconv.Map(req))
err = gjson.New(result).Scan(&res)
if err != nil { if err != nil {
return return
} }
err = gjson.New(result).Scan(&res)
return return
} }
...@@ -55,10 +55,10 @@ type OrderCreateRes struct { ...@@ -55,10 +55,10 @@ type OrderCreateRes struct {
func (s *orderLogic) Create(ctx context.Context, req OrderCreateReq) (res *OrderCreateRes, err error) { func (s *orderLogic) Create(ctx context.Context, req OrderCreateReq) (res *OrderCreateRes, err error) {
result, err := server.Post(ctx, "/open/xdxt/api/v2/order/createOrder", gconv.Map(req)) result, err := server.Post(ctx, "/open/xdxt/api/v2/order/createOrder", gconv.Map(req))
err = gjson.New(result).Scan(&res)
if err != nil { if err != nil {
return return
} }
err = gjson.New(result).Scan(&res)
return return
} }
...@@ -30,10 +30,9 @@ type OrderEventRes struct { ...@@ -30,10 +30,9 @@ type OrderEventRes struct {
func (s *orderLogic) Event(ctx context.Context) (res *OrderEventRes, err error) { func (s *orderLogic) Event(ctx context.Context) (res *OrderEventRes, err error) {
result, err := server.Post(ctx, "/open/xdxt/api/v2/order/listOrderChangeEvent", g.Map{}) result, err := server.Post(ctx, "/open/xdxt/api/v2/order/listOrderChangeEvent", g.Map{})
err = gjson.New(result).Scan(&res)
if err != nil { if err != nil {
return return
} }
err = gjson.New(result).Scan(&res)
return return
} }
...@@ -7,66 +7,68 @@ import ( ...@@ -7,66 +7,68 @@ import (
) )
type OrderListReq struct { type OrderListReq struct {
UnionNos []int `json:"unionNos,omitempty"` UnionNos []string `json:"unionNos,omitempty"` //平台订单号数组,最大长度为100
PlatformOrderNos []int `json:"platformOrderNos,omitempty"` PlatformOrderNos []string `json:"platformOrderNos,omitempty"` //商户平台订单号数组,最大长度为100
} }
type OrderListRes struct { type OrderListRes struct {
CommonRes CommonRes
Result []struct { Result []struct {
UnionNo string `json:"unionNo"` UnionNo string `json:"unionNo"` //平台订单号
PlatformOrderNo string `json:"platformOrderNo"` PlatformOrderNo string `json:"platformOrderNo"` //商户平台订单号
TotalNum int `json:"totalNum"` TotalAmount float64 `json:"totalAmount"` //订单商品总金额
TotalAmount int `json:"totalAmount"` TotalFreightAmount float64 `json:"totalFreightAmount"` //订单总运费 如开票则含13%税金
TotalFreightAmount float64 `json:"totalFreightAmount"` TotalNum int `json:"totalNum"` //订单商品总数
PayAmount float64 `json:"payAmount"` Province string `json:"province"` //收件人省份
PayNo string `json:"payNo"` City string `json:"city"` //收件人城市
CustName string `json:"custName"` District string `json:"district"` //收件人地区
CustMobile string `json:"custMobile"` AddressDetail string `json:"addressDetail"` //收件人详细地址
Province string `json:"province"` CreateTime string `json:"createTime"` //创建时间
City string `json:"city"` PayTime string `json:"payTime"` //支付时间
District string `json:"district"` PayNo string `json:"payNo"` //支付流水号
AddressDetail string `json:"addressDetail"` CustMobile string `json:"custMobile"` //收件人名称
Remark string `json:"remark"` CustName string `json:"custName"` //收件人名称
CreateTime string `json:"createTime"`
PayTime string `json:"payTime"`
OrderList []struct { OrderList []struct {
SuborderId int `json:"suborderId"` FreightAmount float64 `json:"freightAmount"` //子单运费
TotalGoodsAmount int `json:"totalGoodsAmount"` FreightPayer int `json:"freightPayer"`
FreightAmount float64 `json:"freightAmount"` InvoiceType int `json:"invoiceType"`
TotalAmount float64 `json:"totalAmount"`
State int `json:"state"`
OrderDetailList []struct {
OrderDetailId int `json:"orderDetailId"`
SpecCode string `json:"specCode"`
SpecName string `json:"specName"`
SpecInfo string `json:"specInfo"`
Num int `json:"num"`
UnitPrice int `json:"unitPrice"`
TotalAmount int `json:"totalAmount"`
} `json:"orderDetailList"`
OrderDeliveredList []struct { OrderDeliveredList []struct {
ExpCode string `json:"expCode"` ExpCode string `json:"expCode"`
ExpName string `json:"expName"` ExpName string `json:"expName"`
ExpNo string `json:"expNo"` ExpNo string `json:"expNo"`
PackageList []struct { PackageList []struct {
OrderDetailId int `json:"orderDetailId"`
DeliveredNum int `json:"deliveredNum"` DeliveredNum int `json:"deliveredNum"`
DeliveredTime string `json:"deliveredTime"` DeliveredTime string `json:"deliveredTime"`
OrderDetailId int `json:"orderDetailId"`
} `json:"packageList"` } `json:"packageList"`
} `json:"orderDeliveredList"` } `json:"orderDeliveredList"`
OrderDetailList []struct {
Num int `json:"num"`
OrderDetailId int `json:"orderDetailId"`
SpecCode string `json:"specCode"`
SpecInfo string `json:"specInfo"`
SpecName string `json:"specName"`
TaxAmount float64 `json:"taxAmount"`
TotalAmount float64 `json:"totalAmount"`
TotalTaxAmount float64 `json:"totalTaxAmount"`
UnitPrice float64 `json:"unitPrice"`
} `json:"orderDetailList"`
State int `json:"state"` //订单状态 -2:已退款 1:已支付 2:已发货 3:已完成
SuborderId int `json:"suborderId"` //子订单id
TotalAmount float64 `json:"totalAmount"` //子单总金额
TotalGoodsAmount float64 `json:"totalGoodsAmount"` //子单商品总金额
TotalTaxAmount float64 `json:"totalTaxAmount"`
} `json:"orderList"` } `json:"orderList"`
PayAmount float64 `json:"payAmount"`
} `json:"result"` } `json:"result"`
TraceId string `json:"traceId"`
} }
func (s *orderLogic) List(ctx context.Context, req OrderListReq) (res *OrderListRes, err error) { func (s *orderLogic) List(ctx context.Context, req OrderListReq) (res *OrderListRes, err error) {
result, err := server.Post(ctx, "/open/xdxt/api/v2/order/listOrderInfo", gconv.Map(req)) result, err := server.Post(ctx, "/open/xdxt/api/v2/order/listOrderInfo", gconv.Map(req))
err = gjson.New(result).Scan(&res)
if err != nil { if err != nil {
return return
} }
err = gjson.New(result).Scan(&res)
return return
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论