提交 39d52ade authored 作者: zhanglibo's avatar zhanglibo

天猫sdk

上级 aa50a3d0
...@@ -19,16 +19,9 @@ import ( ...@@ -19,16 +19,9 @@ import (
const Source = 7 const Source = 7
type Config struct { type Config struct {
ApiUrl string AppKey string
AppKey string AppSecret string
AppSecret string BizUid string
BizId string
Version string
SignatureMethod string
RegionId string
SignatureVersion string
Format string
BizUid string
} }
var server *Config var server *Config
...@@ -92,7 +85,7 @@ func hmacsha1Base64(str string) string { ...@@ -92,7 +85,7 @@ func hmacsha1Base64(str string) string {
return base64.StdEncoding.EncodeToString(mac.Sum(nil)) return base64.StdEncoding.EncodeToString(mac.Sum(nil))
} }
func post(ctx context.Context, method string, params map[string]string) (str string) { func post(ctx context.Context, method string, params map[string]string) (str string, err error) {
Start := gtime.TimestampMilli() Start := gtime.TimestampMilli()
curtime := time.Now().UTC() curtime := time.Now().UTC()
params["Action"] = method params["Action"] = method
...@@ -137,3 +130,9 @@ func convert(pre string, req []g.Map) (res map[string]string) { ...@@ -137,3 +130,9 @@ func convert(pre string, req []g.Map) (res map[string]string) {
} }
return return
} }
type CommonRes struct {
Code string `json:"Code"`
Message string `json:"Message"`
RequestId string `json:"RequestId"`
}
...@@ -7,9 +7,9 @@ import ( ...@@ -7,9 +7,9 @@ import (
) )
//Regist 注册单个淘宝账号接口(同步) //Regist 注册单个淘宝账号接口(同步)
func (s *Config) Regist(ctx context.Context, thirdPartyUserId interface{}) (res *TmCommon, err error) { func (s *Config) Regist(ctx context.Context, thirdPartyUserId interface{}) (res *CommonRes, err error) {
method := "RegistAnonymousTbAccount" method := "RegistAnonymousTbAccount"
result := post(ctx, method, map[string]string{ result, err := post(ctx, method, map[string]string{
"BizUid": s.BizUid, "BizUid": s.BizUid,
"ThirdPartyUserId": gconv.String(thirdPartyUserId), "ThirdPartyUserId": gconv.String(thirdPartyUserId),
}) })
......
...@@ -25,7 +25,7 @@ type DeliverInfoRes struct { ...@@ -25,7 +25,7 @@ type DeliverInfoRes struct {
} `json:"LogisticsDetailList"` } `json:"LogisticsDetailList"`
} `json:"LogisticsDetailList"` } `json:"LogisticsDetailList"`
LogisticsCompanyName string `json:"LogisticsCompanyName"` //本单物流公司名称 LogisticsCompanyName string `json:"LogisticsCompanyName"` //本单物流公司名称
logisticsCompanyCode string `json:"logisticsCompanyCode"` //本单物流公司Code LogisticsCompanyCode string `json:"logisticsCompanyCode"` //本单物流公司Code
MailNo string `json:"MailNo"` //运单号 MailNo string `json:"MailNo"` //运单号
DataProviderTitle string `json:"DataProviderTitle"` //数据来源说明,如:本数据由菜鸟裹裹提供 DataProviderTitle string `json:"DataProviderTitle"` //数据来源说明,如:本数据由菜鸟裹裹提供
} `json:"Data"` } `json:"Data"`
...@@ -33,7 +33,7 @@ type DeliverInfoRes struct { ...@@ -33,7 +33,7 @@ type DeliverInfoRes struct {
} }
//Info 物流查询接口 //Info 物流查询接口
func (s *deliverTm) Info(ctx context.Context, AppID interface{}, LmOrderId string) (res *DeliverInfoRes) { func (s *deliverTm) Info(ctx context.Context, AppID interface{}, LmOrderId string) (res *DeliverInfoRes, err error) {
method := "queryLogistics" method := "queryLogistics"
...@@ -44,7 +44,7 @@ func (s *deliverTm) Info(ctx context.Context, AppID interface{}, LmOrderId strin ...@@ -44,7 +44,7 @@ func (s *deliverTm) Info(ctx context.Context, AppID interface{}, LmOrderId strin
"ThirdPartyUserId": gconv.String(AppID), "ThirdPartyUserId": gconv.String(AppID),
} }
result := post(ctx, method, request) result, err := post(ctx, method, request)
_ = json.Unmarshal([]byte(result), &res) _ = json.Unmarshal([]byte(result), &res)
return return
} }
...@@ -41,7 +41,7 @@ func (s *goodsTm) Inventory(ctx context.Context, DivisionCode string, req []Good ...@@ -41,7 +41,7 @@ func (s *goodsTm) Inventory(ctx context.Context, DivisionCode string, req []Good
method := "queryItemInventory" method := "queryItemInventory"
request := convert("ItemList", gconv.Maps(req)) request := convert("ItemList", gconv.Maps(req))
request["DivisionCode"] = DivisionCode request["DivisionCode"] = DivisionCode
result := post(ctx, method, request) result, err := post(ctx, method, request)
_ = json.Unmarshal([]byte(result), &res) _ = json.Unmarshal([]byte(result), &res)
return return
......
package tm
type RenderOrderRes struct {
Code string `json:"Code"`
Message string `json:"Message"`
RequestId string `json:"RequestId"`
Success bool `json:"Success"`
Model struct {
RenderOrderInfos struct {
RenderOrderInfos []struct {
LmItemInfos struct {
LmItemInfos []struct {
ItemId int64 `json:"ItemId"`
Quantity int `json:Quantity`
CanSell bool `json:CanSell`
SkuId int64 `json:SkuId`
Message string `json:Message`
ItemName string `json:ItemName`
} `json:"LmItemInfos"`
} `json:"LmItemInfos"`
DeliveryInfos struct {
DeliveryInfos []struct {
ServiceType int `json:"ServiceType"`
Id string `json:"Id"`
PostFee int64 `json:"PostFee"`
DisplayName string `json:"string"`
} `json:"DeliveryInfos"`
} `json:"DeliveryInfos"`
} `json:"RenderOrderInfos"`
} `json:"RenderOrderInfos"`
} `json:"Model"`
}
type TmCommon struct {
Code string `json:"Code"`
Message string `json:"Message"`
RequestId string `json:"RequestId"`
}
type BatchRegistAnonymousTbAccountRes struct {
Code string `json:"Code"`
Message string `json:"Message"`
RequestId string `json:"RequestId"`
BatchId string `json:"BatchId"`
}
type LeavePictureList struct {
Picture string `json:"Picture"` //图片地址
Desc string `json:"Desc"` //图片描述
}
type GetCustomServiceUrlRes struct {
Code string `json:"Code"`
Message string `json:"Message"`
RequestId string `json:"RequestId"`
UrlData struct {
ReturnUrl string `json:"ReturnUrl"`
} `json:"UrlData"`
}
type SubmitReturnGoodLogisticsRes struct {
Code string `json:"Code"`
Message string `json:"Message"`
RequestId string `json:"RequestId"`
}
type SubmitReturnCancelRes struct {
Code string `json:"Code"`
Message string `json:"Message"`
RequestId string `json:"RequestId"`
}
type BeforeData struct {
Reasons []Reasons `json:"reasons"`
ServiceType []ServiceType `json:"serviceType"`
MaxRefundFeeData struct {
MaxRefundFee int64 `json:"MaxRefundFee"` //本单最大可退款金额
MinRefundFee int64 `json:"MinRefundFee"` //本单最小可退款金额
} `json:"MaxRefundFeeData"`
}
type Reasons struct {
Id int64 `json:"id"` //原因id
Name string `json:"name"` //原因
NeedVoucher bool `json:"needVoucher"` //凭证是否必须上传
NoRefundCarriage bool `json:"noRefundCarriage"` //是否支持退运费
Tip string `json:"tip"` //提示
ServiceType string `json:"serviceType"` //提示
RefundDescRequired bool `json:"refundDescRequired"` //是否要求留言
}
type ServiceType struct {
Code string `json:"code"`
Name string `json:"name"`
}
type Detail struct {
RefundCarriage int64 `json:"refundCarriage"` //运费的实际退款金额,单位:分
RejectReason string `json:"rejectReason"` // 拒绝原因
SellerReceiveAddress string `json:"sellerReceiveAddress"` //卖家地址
RefundPayment int64 `json:"refundPayment"` //实际退款金额,单位:分
SellerMobile string `json:"sellerMobile "` //收货人手机
SellerRealName string `json:"sellerRealName"` //收货人姓名
SellerTel string `json:"sellerTel"` //收货人电话
GoodsStatus int `json:"goodsStatus"` //状态1:买家未收到货 2:买家已收到货 3:买家已退货
RefundGoods bool `json:"refundGoods"` //是否要求退货
OnlyRefund bool `json:"onlyRefund"` //是否仅退款
RejectTimes int `json:"rejectTimes"` //退款单被拒绝的次数
Status string `json:"status"` //
}
...@@ -26,8 +26,39 @@ type OrderAddress struct { ...@@ -26,8 +26,39 @@ type OrderAddress struct {
AddressDetail string `json:"AddressDetail"` AddressDetail string `json:"AddressDetail"`
} }
type OrderBeforeRes struct {
Code string `json:"Code"`
Message string `json:"Message"`
RequestId string `json:"RequestId"`
Success bool `json:"Success"`
Model struct {
RenderOrderInfos struct {
RenderOrderInfos []struct {
LmItemInfos struct {
LmItemInfos []struct {
ItemId int64 `json:"ItemId"`
Quantity int `json:"Quantity"`
CanSell bool `json:"CanSell"`
SkuId int64 `json:"SkuId"`
Message string `json:"Message"`
ItemName string `json:"ItemName"`
} `json:"LmItemInfos"`
} `json:"LmItemInfos"`
DeliveryInfos struct {
DeliveryInfos []struct {
ServiceType int `json:"ServiceType"`
Id string `json:"Id"`
PostFee int64 `json:"PostFee"`
DisplayName string `json:"string"`
} `json:"DeliveryInfos"`
} `json:"DeliveryInfos"`
} `json:"RenderOrderInfos"`
} `json:"RenderOrderInfos"`
} `json:"Model"`
}
//Before 验证订单商品 //Before 验证订单商品
func (s *orderTm) Before(ctx context.Context, addr OrderAddress, itemLists []OrderGoodsItem) (res *RenderOrderRes) { func (s *orderTm) Before(ctx context.Context, addr OrderAddress, itemLists []OrderGoodsItem) (res *OrderBeforeRes, err error) {
method := "renderOrder" method := "renderOrder"
request := convert("ItemList", gconv.Maps(itemLists)) request := convert("ItemList", gconv.Maps(itemLists))
...@@ -35,7 +66,7 @@ func (s *orderTm) Before(ctx context.Context, addr OrderAddress, itemLists []Ord ...@@ -35,7 +66,7 @@ func (s *orderTm) Before(ctx context.Context, addr OrderAddress, itemLists []Ord
request["BizUid"] = server.BizUid request["BizUid"] = server.BizUid
request["AccountType"] = typeEp request["AccountType"] = typeEp
result := post(ctx, method, request) result, err := post(ctx, method, request)
_ = json.Unmarshal([]byte(result), &res) _ = json.Unmarshal([]byte(result), &res)
return return
...@@ -69,7 +100,7 @@ type OrderCreateRes struct { ...@@ -69,7 +100,7 @@ type OrderCreateRes struct {
} }
//Create 下单接口 //Create 下单接口
func (s *Config) Create(ctx context.Context, req OrderCreateReq) (res *OrderCreateRes) { func (s *Config) Create(ctx context.Context, req OrderCreateReq) (res *OrderCreateRes, err error) {
method := "createOrderV2" method := "createOrderV2"
request := convert("ItemList", gconv.Maps(req.ItemLists)) request := convert("ItemList", gconv.Maps(req.ItemLists))
...@@ -79,7 +110,7 @@ func (s *Config) Create(ctx context.Context, req OrderCreateReq) (res *OrderCrea ...@@ -79,7 +110,7 @@ func (s *Config) Create(ctx context.Context, req OrderCreateReq) (res *OrderCrea
request["AccountType"] = typeAnony request["AccountType"] = typeAnony
request["ThirdPartyUserId"] = gconv.String(req.AppID) request["ThirdPartyUserId"] = gconv.String(req.AppID)
result := post(ctx, method, request) result, err := post(ctx, method, request)
_ = json.Unmarshal([]byte(result), &res) _ = json.Unmarshal([]byte(result), &res)
return return
} }
...@@ -91,9 +122,9 @@ type OrderPayReq struct { ...@@ -91,9 +122,9 @@ type OrderPayReq struct {
} }
//Pay 订单支付 //Pay 订单支付
func (s *Config) Pay(ctx context.Context, req OrderPayReq) (res *OrderCreateRes) { func (s *Config) Pay(ctx context.Context, req OrderPayReq) (res *OrderCreateRes, err error) {
method := "enableOrder" method := "enableOrder"
result := post(ctx, method, map[string]string{ result, err := post(ctx, method, map[string]string{
"BizUid": server.BizUid, "BizUid": server.BizUid,
"LmOrderId": req.LmOrderId, "LmOrderId": req.LmOrderId,
"OutTradeId": req.ChannelOrder, "OutTradeId": req.ChannelOrder,
...@@ -177,7 +208,7 @@ type OrderListRes struct { ...@@ -177,7 +208,7 @@ type OrderListRes struct {
} }
//List 列表 //List 列表
func (s *orderTm) List(ctx context.Context, req OrderListReq) (res *OrderListRes) { func (s *orderTm) List(ctx context.Context, req OrderListReq) (res *OrderListRes, err error) {
method := "queryOrderList" method := "queryOrderList"
var filterOption = OrderFilter{ var filterOption = OrderFilter{
...@@ -201,7 +232,7 @@ func (s *orderTm) List(ctx context.Context, req OrderListReq) (res *OrderListRes ...@@ -201,7 +232,7 @@ func (s *orderTm) List(ctx context.Context, req OrderListReq) (res *OrderListRes
"ThirdPartyUserId": gconv.String(req.AppID), "ThirdPartyUserId": gconv.String(req.AppID),
} }
result := post(ctx, method, request) result, err := post(ctx, method, request)
_ = gjson.New(result).Scan(&res) _ = gjson.New(result).Scan(&res)
return return
} }
...@@ -212,10 +243,10 @@ type OrderCancelReq struct { ...@@ -212,10 +243,10 @@ type OrderCancelReq struct {
} }
//Cancel 仅适⽤下单[Create]未⽀付[Pay]的订单 //Cancel 仅适⽤下单[Create]未⽀付[Pay]的订单
func (s *orderTm) Cancel(ctx context.Context, req OrderCancelReq) (res *OrderListRes) { func (s *orderTm) Cancel(ctx context.Context, req OrderCancelReq) (res *OrderListRes, err error) {
method := "cancelOrder" method := "cancelOrder"
result := post(ctx, method, map[string]string{ result, err := post(ctx, method, map[string]string{
"BizUid": server.BizUid, "BizUid": server.BizUid,
"LmOrderId": req.LmOrderId, "LmOrderId": req.LmOrderId,
"AccountType": typeAnony, "AccountType": typeAnony,
......
...@@ -20,7 +20,7 @@ type RefundSubmitReq struct { ...@@ -20,7 +20,7 @@ type RefundSubmitReq struct {
} }
//Submit 提交退货物流信息接口 //Submit 提交退货物流信息接口
func (s *refundTm) Submit(ctx context.Context, req RefundSubmitReq) (res *SubmitReturnGoodLogisticsRes) { func (s *refundTm) Submit(ctx context.Context, req RefundSubmitReq) (res *CommonRes, err error) {
method := "submitReturnGoodLogistics" method := "submitReturnGoodLogistics"
request := map[string]string{ request := map[string]string{
...@@ -33,13 +33,13 @@ func (s *refundTm) Submit(ctx context.Context, req RefundSubmitReq) (res *Submit ...@@ -33,13 +33,13 @@ func (s *refundTm) Submit(ctx context.Context, req RefundSubmitReq) (res *Submit
"AccountType": typeAnony, "AccountType": typeAnony,
} }
result := post(ctx, method, request) result, err := post(ctx, method, request)
_ = json.Unmarshal([]byte(result), &res) _ = json.Unmarshal([]byte(result), &res)
return return
} }
//Cancel 取消退款申请接口 //Cancel 取消退款申请接口
func (s *refundTm) Cancel(ctx context.Context, AppID uint, subLmOrderId, disputeId string) (res *SubmitReturnCancelRes) { func (s *refundTm) Cancel(ctx context.Context, AppID uint, subLmOrderId, disputeId string) (res *CommonRes, err error) {
method := "cancelRefund" method := "cancelRefund"
request := map[string]string{ request := map[string]string{
...@@ -50,7 +50,7 @@ func (s *refundTm) Cancel(ctx context.Context, AppID uint, subLmOrderId, dispute ...@@ -50,7 +50,7 @@ func (s *refundTm) Cancel(ctx context.Context, AppID uint, subLmOrderId, dispute
"AccountType": typeAnony, "AccountType": typeAnony,
} }
result := post(ctx, method, request) result, err := post(ctx, method, request)
_ = json.Unmarshal([]byte(result), &res) _ = json.Unmarshal([]byte(result), &res)
return return
} }
...@@ -85,7 +85,7 @@ type RefundBeforeRes struct { ...@@ -85,7 +85,7 @@ type RefundBeforeRes struct {
} }
// Before 前置 // Before 前置
func (s *refundTm) Before(ctx context.Context, req RefundBeforeReq) (res *RefundBeforeRes) { func (s *refundTm) Before(ctx context.Context, req RefundBeforeReq) (res *RefundBeforeRes, err error) {
method := "initApplyRefund" method := "initApplyRefund"
request := map[string]string{ request := map[string]string{
...@@ -97,21 +97,26 @@ func (s *refundTm) Before(ctx context.Context, req RefundBeforeReq) (res *Refund ...@@ -97,21 +97,26 @@ func (s *refundTm) Before(ctx context.Context, req RefundBeforeReq) (res *Refund
"AccountType": typeAnony, "AccountType": typeAnony,
} }
result := post(ctx, method, request) result, err := post(ctx, method, request)
_ = json.Unmarshal([]byte(result), &res) _ = json.Unmarshal([]byte(result), &res)
return return
} }
type RefundApplyReq struct { type RefundApplyReq struct {
AppID interface{} AppID interface{}
SubLmOrderId string //子订单号 SubLmOrderId string //子订单号
BizClaimType string //退款类型 BizClaimType string //退款类型
ApplyRefundFee string //申请退款金额 ApplyRefundFee string //申请退款金额
ApplyRefundCount string //退货数量 ApplyRefundCount string //退货数量
ApplyReasonTextId string //退款原因ID ApplyReasonTextId string //退款原因ID
LeaveMessage string //留言 LeaveMessage string //留言
LeavePictureList []*LeavePictureList //凭证,某些原因要求必须有凭证。 LeavePictureList []*RefundApplyPicture //凭证,某些原因要求必须有凭证。
GoodsStatus string //当退款类型:仅退款时,货物状态:为4未 发货。所有状态:4: 未发货, 6: 已发货, 1: 未收到货, 2: 已收到货, 3:已寄回, 5: 卖家确 认收货 GoodsStatus string //当退款类型:仅退款时,货物状态:为4未 发货。所有状态:4: 未发货, 6: 已发货, 1: 未收到货, 2: 已收到货, 3:已寄回, 5: 卖家确 认收货
}
type RefundApplyPicture struct {
Picture string `json:"Picture"` //图片地址
Desc string `json:"Desc"` //图片描述
} }
type RefundApplyRes struct { type RefundApplyRes struct {
...@@ -126,7 +131,7 @@ type RefundApplyRes struct { ...@@ -126,7 +131,7 @@ type RefundApplyRes struct {
} }
//Apply 申请 //Apply 申请
func (s *refundTm) Apply(ctx context.Context, req *RefundApplyReq) (res *RefundApplyRes) { func (s *refundTm) Apply(ctx context.Context, req *RefundApplyReq) (res *RefundApplyRes, err error) {
method := "applyRefund" method := "applyRefund"
request := convert("LeavePictureList", gconv.Maps(req.LeavePictureList)) request := convert("LeavePictureList", gconv.Maps(req.LeavePictureList))
...@@ -141,7 +146,7 @@ func (s *refundTm) Apply(ctx context.Context, req *RefundApplyReq) (res *RefundA ...@@ -141,7 +146,7 @@ func (s *refundTm) Apply(ctx context.Context, req *RefundApplyReq) (res *RefundA
request["AccountType"] = typeAnony request["AccountType"] = typeAnony
request["ThirdPartyUserId"] = gconv.String(req.AppID) request["ThirdPartyUserId"] = gconv.String(req.AppID)
result := post(ctx, method, request) result, err := post(ctx, method, request)
_ = json.Unmarshal([]byte(result), &res) _ = json.Unmarshal([]byte(result), &res)
return return
} }
...@@ -181,7 +186,7 @@ type RefundInfoRes struct { ...@@ -181,7 +186,7 @@ type RefundInfoRes struct {
} }
//Info 详情 //Info 详情
func (s *refundTm) Info(ctx context.Context, AppID uint, subLmOrderId string) (res *RefundInfoRes) { func (s *refundTm) Info(ctx context.Context, AppID uint, subLmOrderId string) (res *RefundInfoRes, err error) {
method := "queryRefundApplicationDetail" method := "queryRefundApplicationDetail"
request := map[string]string{ request := map[string]string{
...@@ -191,7 +196,7 @@ func (s *refundTm) Info(ctx context.Context, AppID uint, subLmOrderId string) (r ...@@ -191,7 +196,7 @@ func (s *refundTm) Info(ctx context.Context, AppID uint, subLmOrderId string) (r
"AccountType": typeAnony, "AccountType": typeAnony,
} }
result := post(ctx, method, request) result, err := post(ctx, method, request)
_ = json.Unmarshal([]byte(result), &res) _ = json.Unmarshal([]byte(result), &res)
return return
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论