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

盛创汇联

上级 d51119f6
......@@ -18,8 +18,6 @@ import (
"time"
)
var server *Config
const Host = "https://schl-api.szbaoly.com"
type Config struct {
......@@ -43,19 +41,18 @@ type PubilcParams struct {
const pkgName = "schl"
func New(config *Config) {
server = config
return
func New(config *Config) *Config {
return config
}
func (c *Config) Post(ctx context.Context, URL string, bodyMap g.Map) (result string, err error) {
func (s *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.AppID = s.AppKey
pubilcParams.Timestamp = gtime.TimestampStr()
pubilcParams.Nonce = grand.S(16, false)
c.Sign(pubilcParams)
s.Sign(pubilcParams)
defer func() {
ctx = context.WithValue(ctx, "URI", URL)
......@@ -87,7 +84,7 @@ func (c *Config) Post(ctx context.Context, URL string, bodyMap g.Map) (result st
return
}
func (c *Config) Sign(pubilcParams *PubilcParams) {
func (s *Config) Sign(pubilcParams *PubilcParams) {
allMaps := make(map[string]string)
var arr = garray.New().Append("appid", "timestamp", "nonce")
for k, v := range gconv.MapStrStr(pubilcParams) {
......@@ -110,9 +107,9 @@ func (c *Config) Sign(pubilcParams *PubilcParams) {
paramsString += v + "=" + allMaps[v]
}
paramsString += "&key=" + server.AppSecret
paramsString += "&key=" + s.AppSecret
hmacSha256String := hmacSha256(paramsString, server.AppSecret)
hmacSha256String := hmacSha256(paramsString, s.AppSecret)
pubilcParams.Signature = strings.ToUpper(hmacSha256String)
return
......
......@@ -20,9 +20,9 @@ type BrandListRes struct {
} `json:"result"`
}
// List 获取商品品牌
func (*brandLogic) List(ctx context.Context) (res *BrandListRes, err error) {
result, err := server.Post(ctx, "/open/xdxt/api/v2/goods/listGoodsBrand", g.Map{})
// BrandList 获取商品品牌
func (s *Config) BrandList(ctx context.Context) (res *BrandListRes, err error) {
result, err := s.Post(ctx, "/open/xdxt/api/v2/goods/listGoodsBrand", g.Map{})
if err != nil {
return
}
......
......@@ -22,9 +22,9 @@ type CategoryListItem struct {
SupId int `json:"supId"`
}
// List 获取商品分类
func (*categoryLogic) List(ctx context.Context) (res *CategoryListRes, err error) {
result, err := server.Post(ctx, "/open/xdxt/api/v2/goods/listGoodsCategory", g.Map{})
// CategoryList 获取商品分类
func (s *Config) CategoryList(ctx context.Context) (res *CategoryListRes, err error) {
result, err := s.Post(ctx, "/open/xdxt/api/v2/goods/listGoodsCategory", g.Map{})
if err != nil {
return
}
......
package schl
type goodsLogic struct {
}
var Goods = goodsLogic{}
......@@ -27,9 +27,9 @@ type GoodsEventRes struct {
} `json:"result"`
}
func (*goodsLogic) Event(ctx context.Context) (res *GoodsEventRes, err error) {
func (s *Config) GoodsEvent(ctx context.Context) (res *GoodsEventRes, err error) {
result, err := server.Post(ctx, "/open/xdxt/api/v2/goods/listGoodsChangeEvent", g.Map{})
result, err := s.Post(ctx, "/open/xdxt/api/v2/goods/listGoodsChangeEvent", g.Map{})
if err != nil {
return
}
......
......@@ -71,12 +71,12 @@ type GoodsListSpec struct {
BillingName string `json:"billingName"`
BillingSpecName string `json:"billingSpecName"`
ZpTaxRate string `json:"zpTaxRate"`
Freight float64 `json:"freight"`
Freight float64 `json:"freight"`
}
func (*goodsLogic) List(ctx context.Context, req GoodsListReq) (res *GoodsListRes, err error) {
func (s *Config) GoodsList(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 := s.Post(ctx, "/open/xdxt/api/v2/goods/listGoods", gconv.Map(req))
if err != nil {
return
}
......
......@@ -34,9 +34,8 @@ type LogisticsTraceRes struct {
TraceId string `json:"traceId"`
}
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))
func (s *Config) LogisticsTrace(ctx context.Context, req LogisticsTraceReq) (res *LogisticsTraceRes, err error) {
result, err := s.Post(ctx, "/open/xdxt/api/v2/order/queryExpTrack", gconv.Map(req))
if err != nil {
return
}
......
package schl
type orderLogic struct {
}
var Order = orderLogic{}
......@@ -33,10 +33,10 @@ type OrderBeforeRes struct {
TraceId string `json:"traceId"`
}
// Before 订单运费
func (s *orderLogic) Before(ctx context.Context, req OrderBeforeReq) (res *OrderBeforeRes, err error) {
// OrderBefore 订单运费
func (s *Config) OrderBefore(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 := s.Post(ctx, "/open/xdxt/api/v2/order/orderFreightPreview", gconv.Map(req))
if err != nil {
return
}
......
......@@ -53,10 +53,10 @@ type OrderCreateRes struct {
} `json:"result"`
}
// Create 创建订单
func (s *orderLogic) Create(ctx context.Context, req OrderCreateReq) (res *OrderCreateRes, err error) {
// OrderCreate 创建订单
func (s *Config) OrderCreate(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 := s.Post(ctx, "/open/xdxt/api/v2/order/createOrder", gconv.Map(req))
if err != nil {
return
}
......
......@@ -27,9 +27,9 @@ type OrderEventRes struct {
} `json:"result"`
}
func (s *orderLogic) Event(ctx context.Context) (res *OrderEventRes, err error) {
func (s *Config) OrderEvent(ctx context.Context) (res *OrderEventRes, err error) {
result, err := server.Post(ctx, "/open/xdxt/api/v2/order/listOrderChangeEvent", g.Map{})
result, err := s.Post(ctx, "/open/xdxt/api/v2/order/listOrderChangeEvent", g.Map{})
if err != nil {
return
}
......
......@@ -63,9 +63,9 @@ type OrderListRes struct {
} `json:"result"`
}
func (s *orderLogic) List(ctx context.Context, req OrderListReq) (res *OrderListRes, err error) {
func (s *Config) OrderList(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 := s.Post(ctx, "/open/xdxt/api/v2/order/listOrderInfo", gconv.Map(req))
if err != nil {
return
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论