提交 76772bd0 authored 作者: zhanglibo's avatar zhanglibo

淘特

上级 4cb05bd4
package itao
import (
"context"
"crypto/hmac"
"crypto/sha1"
"encoding/hex"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/util/gconv"
"sort"
"strings"
"time"
)
type Config struct {
ApiUrl string
AppKey string
AppSecret string
AccessToken string
}
var server *Config
const PkgName = "itao"
func New(req *Config) {
server = req
return
}
type CommonRes struct {
Success bool `json:"success"`
ErrorCode string `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
}
func (s *Config) CreateSign(signStr string) (sign string) {
//拼接参数
appSecret := []byte(s.AppSecret)
mac := hmac.New(sha1.New, appSecret)
mac.Write([]byte(signStr))
mdStr := hex.EncodeToString(mac.Sum(nil))
sign = strings.ToUpper(mdStr)
return
}
func (s *Config) sign(method string, param g.Map) g.Map {
var keys []string
mewparam := param
for k := range mewparam {
keys = append(keys, k)
}
sort.Strings(keys)
var signStr string
for _, v := range keys {
if v != "_aop_signature" {
signStr += v
signStr += gconv.String(mewparam[v])
}
}
//拼接参数
signStr = "param2/1/" + method + "/" + s.AppKey + signStr
g.Dump(signStr)
param["_aop_signature"] = s.CreateSign(signStr)
//param["_aop_signature"] = "A4D5F82A89A7515CB66A1AF3AC97C02AF6223C90"
return param
}
func (s *Config) Post(ctx context.Context, method string, params g.Map) (str string, err error) {
Start := gtime.TimestampMilli()
allparams := s.sign(method, params)
Url := s.ApiUrl + method + "/" + s.AppKey
Request := g.Client()
Request.SetHeader("Content-Type", "application/x-www-form-urlencoded")
resp, err := Request.Timeout(time.Second*5).Post(Url, allparams)
defer func() {
paramStr := gjson.New(params).MustToJsonString()
ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", Url)
if err != nil {
g.Log().Cat(PkgName).Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%vms】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else {
g.Log().Cat(PkgName).Ctx(ctx).Infof("参数【%v】响应【%v】响应时间【%vms】", paramStr, str, gtime.TimestampMilli()-Start)
}
}()
str = resp.ReadAllString()
return
}
package itao
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type addressItao struct {
}
var Address = addressItao{}
type AddressDivisionReq struct {
Province string `json:"prov,omitempty"`
City string `json:"city,omitempty"`
Area string `json:"distinct,omitempty"`
Town string `json:"town,omitempty"`
Page int `json:"pageIndex"`
Size int `json:"pageSize"`
}
type AddressDivisionRes struct {
Result struct {
Result struct {
Divisions []struct {
DivisionId int `json:"divisionId"`
DivisionLeaf bool `json:"divisionLeaf"`
DivisionToken string `json:"divisionToken"`
Level int `json:"level"`
Names struct {
EN string `json:"EN"`
CN string `json:"CN"`
} `json:"names"`
} `json:"divisions"`
PageIndex int `json:"pageIndex"`
PageSize int `json:"pageSize"`
ParentToken string `json:"parentToken"`
TotalCount int `json:"totalCount"`
TotalPage int `json:"totalPage"`
} `json:"result"`
Success bool `json:"success"`
} `json:"result"`
}
func (s addressItao) Division(ctx context.Context, req AddressDivisionReq) (res *AddressDivisionRes, err error) {
method := "com.alibaba.c2m/ltao.delivery.queryDivision"
result, err := server.Post(ctx, method, g.Map{
"param": req,
})
_ = gjson.New(result).Scan(&res)
return
}
package itao
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type goodsItao struct {
}
var Goods = goodsItao{}
type GoodsDetailRes struct {
Result struct {
Result struct {
DebugInfoMap struct {
TraceId string `json:"traceId"`
} `json:"debugInfoMap"`
EnterNewLink string `json:"enterNewLink"`
Item struct {
CategoryId []string `json:"categoryId"`
CategoryName []string `json:"categoryName"`
City string `json:"city"`
FastPostFee int `json:"fastPostFee"`
Images []string `json:"images"`
ItemId string `json:"itemId"`
ItemServices []struct {
Desc string `json:"desc"`
Title string `json:"title"`
VideoUrl string `json:"videoUrl,omitempty"`
ActionTitle string `json:"actionTitle,omitempty"`
ActionUrl string `json:"actionUrl,omitempty"`
} `json:"itemServices"`
MainPic string `json:"mainPic"`
OrdinaryPostFee int `json:"ordinaryPostFee"`
Props []struct {
Content string `json:"content"`
Word string `json:"word"`
} `json:"props"`
Prov string `json:"prov"`
Receipt bool `json:"receipt"`
SoldQuantity int `json:"soldQuantity"`
Status int `json:"status"`
Title string `json:"title"`
} `json:"item"`
Seller struct {
ShopName string `json:"shopName"`
} `json:"seller"`
SkuBase struct {
Props []interface{} `json:"props"`
Skus []interface{} `json:"skus"`
} `json:"skuBase"`
SkuCore struct {
DefaultSkuId int `json:"defaultSkuId"`
Sku2Info map[string]GoodsItem `json:"sku2info"`
} `json:"skuCore"`
} `json:"result"`
} `json:"result"`
}
//Detail 详情[实时]
func (goodsItao) Detail(ctx context.Context, GoodsID string) (res *GoodsDetailRes, err error) {
method := "com.alibaba.c2m/ltao.detail.jnpiter.getDetail"
result, err := server.Post(ctx, method, g.Map{
"parameters": g.Map{
"itemIds": GoodsID,
},
})
_ = gjson.New(result).Scan(&res)
return
}
type GoodsDynamicRes struct {
Result struct {
Data []struct {
DebugInfoMap struct {
TraceId string `json:"traceId"`
} `json:"debugInfoMap"`
EnterNewLink string `json:"enterNewLink"`
Sku2Info map[string]GoodsItem `json:"sku2info"`
} `json:"data"`
ItemIds string `json:"itemIds"`
Time int `json:"time"`
} `json:"result"`
}
type GoodsItem struct {
QuantityVague string `json:"quantityVague"`
OriginalPrice string `json:"originalPrice"`
TjbMarketPrice string `json:"tjbMarketPrice"`
}
//Dynamic 详情[动态]
func (goodsItao) Dynamic(ctx context.Context, GoodsID string) (res *GoodsDynamicRes, err error) {
method := "com.alibaba.c2m/ltao.detail.csp.getDetailDynamic"
result, err := server.Post(ctx, method, g.Map{
"parameters": g.Map{
"itemIds": GoodsID,
},
})
_ = gjson.New(result).Scan(&res)
return
}
type GoodBatchRes struct {
Result struct {
Data []struct {
DebugInfoMap struct {
TraceId string `json:"traceId"`
} `json:"debugInfoMap"`
EnterNewLink string `json:"enterNewLink"`
Item struct {
CategoryId []string `json:"categoryId"`
CategoryName []string `json:"categoryName"`
City string `json:"city"`
FastPostFee int `json:"fastPostFee"`
Images []string `json:"images"`
ItemId string `json:"itemId"`
ItemServices []struct {
Desc string `json:"desc"`
Title string `json:"title"`
VideoUrl string `json:"videoUrl,omitempty"`
ActionTitle string `json:"actionTitle,omitempty"`
ActionUrl string `json:"actionUrl,omitempty"`
} `json:"itemServices"`
MainPic string `json:"mainPic"`
OrdinaryPostFee int `json:"ordinaryPostFee"`
Props []struct {
Content string `json:"content"`
Word string `json:"word"`
} `json:"props"`
Prov string `json:"prov"`
Receipt bool `json:"receipt"`
SoldQuantity int `json:"soldQuantity"`
Status int `json:"status"`
Title string `json:"title"`
} `json:"item"`
Seller struct {
ShopName string `json:"shopName"`
} `json:"seller"`
Sku2Info map[string]GoodsItem `json:"sku2info"`
SkuBase struct {
Props []interface{} `json:"props"`
Skus []interface{} `json:"skus"`
} `json:"skuBase"`
} `json:"data"`
ItemIds string `json:"itemIds"`
Time int `json:"time"`
} `json:"result"`
}
//Batch 详情[批量]
func (goodsItao) Batch(ctx context.Context, GoodsID string) (res *GoodBatchRes, err error) {
method := "com.alibaba.c2m/ltao.detail.csp.getDetail"
result, err := server.Post(ctx, method, g.Map{
"parameters": g.Map{
"itemIds": GoodsID,
},
})
_ = gjson.New(result).Scan(&res)
return
}
package itao
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type logisticsItao struct {
}
var Logistics = logisticsItao{}
type LogisticsDetailReq struct {
OrderSn string `json:"tradeId"`
}
type LogisticsDetailRes struct {
}
//Detail 详情[实时]
func (logisticsItao) Detail(ctx context.Context, req LogisticsDetailReq) (res *LogisticsDetailRes, err error) {
method := "com.alibaba.c2m/ltao.logistics.queryDetail"
result, err := server.Post(ctx, method, g.Map{
"request": req,
})
_ = gjson.New(result).Scan(&res)
return
}
package itao
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type orderItao struct {
}
var Order = orderItao{}
type OrderBeforeReq struct {
Address OrderAddress `json:"deliveryAddressInfo"`
List []OrderItem `json:"itemRequestList"`
}
type OrderAddress struct {
AddressDetail string `json:"addressDetail"`
City string `json:"city"`
CityId int64 `json:"cityId"`
Area string `json:"district"`
AreaId int64 `json:"districtId"`
FullName string `json:"fullName"`
Mobile string `json:"mobile"`
Prov string `json:"prov"`
ProvId int64 `json:"provId"`
Town string `json:"town"`
TownId int64 `json:"townId"`
}
type OrderItem struct {
Info struct {
ItemId int64 `json:"itemId"`
SkuId int64 `json:"skuId"`
} `json:"itemInfo"`
Quantity int `json:"quantity"`
}
type OrderBeforeRes struct {
Result struct {
Result struct {
ExtensionResp struct {
TradeId string `json:"tradeId"`
} `json:"extensionResp"`
InvalidOrderGroups []interface{} `json:"invalidOrderGroups"`
OriginPriceFee int `json:"originPriceFee"`
PriceFee int `json:"priceFee"`
PromotionResp OrderPromotion `json:"promotionResp"`
Quantity int `json:"quantity"`
RealPayPrice int `json:"realPayPrice"`
ReceiveMethodInfo struct {
DeliveryAddressId int `json:"deliveryAddressId"`
Options []interface{} `json:"options"`
} `json:"receiveMethodInfo"`
ValidOrderGroups []struct {
DeliveryMethodInfo struct {
DeliveryMethodOptionList []struct {
FareCent int `json:"fareCent"`
Id string `json:"id"`
ServiceType int `json:"serviceType"`
} `json:"deliveryMethodOptionList"`
SelectedId string `json:"selectedId"`
} `json:"deliveryMethodInfo"`
Image string `json:"image"`
OrderLineRenders []struct {
ItemInfo struct {
ItemId int64 `json:"itemId"`
SkuId int `json:"skuId"`
} `json:"itemInfo"`
ItemPayPrice int `json:"itemPayPrice"`
OrderLineId int `json:"orderLineId"`
Quantity int `json:"quantity"`
} `json:"orderLineRenders"`
OrderPayPrice int `json:"orderPayPrice"`
Quantity int `json:"quantity"`
SellerToken string `json:"sellerToken"`
Title string `json:"title"`
} `json:"validOrderGroups"`
} `json:"result"`
Success bool `json:"success"`
} `json:"result"`
}
type OrderPromotion struct {
CrossShopPromotions []struct {
Discount int `json:"discount"`
IdValues []string `json:"idValues"`
PromotionKey string `json:"promotionKey"`
} `json:"crossShopPromotions"`
InvalidPromotions []interface {
} `json:"invalidPromotions"`
ItemPromotions []struct {
HasPromotion bool `json:"hasPromotion"`
IdValues []interface {
} `json:"idValues"`
OrderLineId int `json:"orderLineId"`
PromotionPriceMap struct {
LtaoMonthPkCard int `json:"ltaoMonthPkCard"`
} `json:"promotionPriceMap"`
} `json:"itemPromotions"`
ShopPromotions []struct {
Discount int `json:"discount"`
GoldStandardDiscount int `json:"goldStandardDiscount"`
HasShopPromotion bool `json:"hasShopPromotion"`
IdValues []interface {
} `json:"idValues"`
OutId string `json:"outId"`
SellerToken string `json:"sellerToken"`
} `json:"shopPromotions"`
}
//Before 前置校验
func (s orderItao) Before(ctx context.Context, req OrderBeforeReq) (res *OrderBeforeRes, err error) {
method := "com.alibaba.c2m/ltao.trade.renderOrder"
result, err := server.Post(ctx, method, g.Map{
"request": req,
})
_ = gjson.New(result).Scan(&res)
return
}
type OrderCreateReq struct {
Address OrderAddress `json:"deliveryAddressInfo"`
List []OrderCreateItem `json:"orderDTOs"`
PromotionResp OrderPromotion `json:"promotionResp"`
}
type OrderCreateItem struct {
DTO []OrderCreateDto `json:"orderLineDTOs"`
OrderSn string `json:"outId"`
Token string `json:"sellerToken"`
}
type OrderCreateDto struct {
GoodsID int64 `json:"itemId"`
SkuId int64 `json:"skuId"`
Quantity int `json:"buyQuantity"`
GoodsSn string `json:"orderLineId"`
}
type OrderCreateRes struct {
Result struct {
Result struct {
AlipaySuccess bool `json:"alipaySuccess"`
EnablingOrdersResult struct {
Model struct {
AlipayTradeIds []string `json:"alipayTradeIds"`
OrderIds []int64 `json:"orderIds"`
RedirectUrl string `json:"redirectUrl"`
} `json:"model"`
} `json:"enablingOrdersResult"`
ExtensionResult struct {
TraceId string `json:"traceId"`
} `json:"extensionResult"`
PartSuccess bool `json:"partSuccess"`
Success bool `json:"success"`
} `json:"result"`
Success bool `json:"success"`
} `json:"result"`
}
//Create 下单
func (s orderItao) Create(ctx context.Context, req OrderCreateReq) (res *OrderCreateRes, err error) {
method := "com.alibaba.c2m/ltao.trade.createAndEnableOrder"
result, err := server.Post(ctx, method, g.Map{
"request": req,
})
_ = gjson.New(result).Scan(&res)
return
}
type OrderDetailRes struct {
Result struct {
Result struct {
BizOrderId int64 `json:"bizOrderId"`
BuyAmount int `json:"buyAmount"`
BuyerToken string `json:"buyerToken"`
Detail int `json:"detail"`
DetailOrderList []struct {
BizOrderId int64 `json:"bizOrderId"`
BuyAmount int `json:"buyAmount"`
BuyerToken string `json:"buyerToken"`
Detail int `json:"detail"`
GmtCreate string `json:"gmtCreate"`
ItemInfo struct {
ItemId int64 `json:"itemId"`
Pic string `json:"pic"`
Price string `json:"price"`
SkuId int `json:"skuId"`
Title string `json:"title"`
} `json:"itemInfo"`
LogisticsOrderId int64 `json:"logisticsOrderId"`
LogisticsStatus int `json:"logisticsStatus"`
Main int `json:"main"`
ParentId int64 `json:"parentId"`
PayFee int `json:"payFee"`
PayOrderId int64 `json:"payOrderId"`
PayStatus int `json:"payStatus"`
PostFee int `json:"postFee"`
RefundStatus int `json:"refundStatus"`
SellerToken string `json:"sellerToken"`
Status int `json:"status"`
} `json:"detailOrderList"`
GmtCreate string `json:"gmtCreate"`
ItemInfo struct {
ItemId int64 `json:"itemId"`
Pic string `json:"pic"`
Price string `json:"price"`
SkuId int `json:"skuId"`
Title string `json:"title"`
} `json:"itemInfo"`
LogisticsOrderId int64 `json:"logisticsOrderId"`
LogisticsStatus int `json:"logisticsStatus"`
//1 - 未发货 -> 等待卖家发货
//2 - 已发货 -> 等待买家确认收货
//3 - 已收货 -> 交易成功
//4 - 已经退货 -> 交易失败
//5 - 部分收货 -> 交易成功
//6 - 部分发货中
//8 - 还未创建物流订单
Main int `json:"main"`
ParentId int64 `json:"parentId"`
PayFee int `json:"payFee"`
PayOrderId int64 `json:"payOrderId"`
PayStatus int `json:"payStatus"`
//1 - 未冻结/未付款 -> 等待买家付款
//2 - 已冻结/已付款 -> 等待卖家发货
//4 - 已退款 -> 交易关闭
//6 - 已转交易 -> 交易成功
//7 - 没有创建外部交易
//8 - 交易被关闭
//9 - 不可付款
PostFee int `json:"postFee"`
RefundStatus int `json:"refundStatus"`
SellerToken string `json:"sellerToken"`
Status int `json:"status"`
} `json:"result"`
Success bool `json:"success"`
} `json:"result"`
}
//Detail 详情
func (s orderItao) Detail(ctx context.Context, req string) (res *OrderDetailRes, err error) {
method := "com.alibaba.c2m/ltao.trade.queryOrder"
result, err := server.Post(ctx, method, g.Map{
"request": g.Map{
"bizOrderId": req,
},
})
_ = gjson.New(result).Scan(&res)
return
}
...@@ -15,6 +15,7 @@ const ( ...@@ -15,6 +15,7 @@ const (
Wpc = 12 //唯品会 Wpc = 12 //唯品会
Ikc = 13 //爱库存 Ikc = 13 //爱库存
Dwd = 14 //好食期 Dwd = 14 //好食期
Itao = 15 //淘特
) )
var ( var (
...@@ -75,6 +76,10 @@ func GetUpstreamList() (res interface{}, err error) { ...@@ -75,6 +76,10 @@ func GetUpstreamList() (res interface{}, err error) {
"key": Dwd, "key": Dwd,
"name": GetUpstreamName(Dwd), "name": GetUpstreamName(Dwd),
}, },
g.Map{
"key": Itao,
"name": GetUpstreamName(Itao),
},
} }
return return
} }
...@@ -101,6 +106,8 @@ func GetUpstreamName(source int) string { ...@@ -101,6 +106,8 @@ func GetUpstreamName(source int) string {
return "特卖二仓" return "特卖二仓"
case Dwd: case Dwd:
return "好食期" return "好食期"
case Itao:
return "淘特"
default: default:
return "未知来源" return "未知来源"
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论