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

盛创汇联

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