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

盛创汇联

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