对接新供应链-唯品尚

This commit is contained in:
zhongqiang 2025-05-27 18:00:20 +08:00
parent be569bda75
commit fa19e791e0
3 changed files with 326 additions and 32 deletions

View File

@ -3,7 +3,7 @@ package weipinshang_api
type GetManyPostageRes struct {
Code int `json:"code"` // 0为成功其它为失败
Msg string `json:"msg"` // 请求接口消息
Data []FreightData `json:"data"` // 返回数据 data array
Data FreightData `json:"data"` // 返回数据 data array
}
type FreightData struct {
Freight string `json:"freight"` // 邮费 freight 是 string 邮费
@ -12,7 +12,7 @@ type FreightData struct {
type PreOrderRes struct {
Code int `json:"code"` // 0为成功其它为失败
Msg string `json:"msg"` // 请求接口消息
Data []PreOrderFreightData `json:"data"` // 返回数据 data array
Data PreOrderFreightData `json:"data"` // 返回数据 data array
}
type PreOrderFreightData struct {
Freight string `json:"freight"` // 邮费 freight 是 string 邮费
@ -20,15 +20,22 @@ type PreOrderFreightData struct {
}
type CreateOrderRes struct {
McOrderNo string `json:"mc_order_no"` //蜜仓子订单号
OrderAmount float64 `json:"order_amount"` // 子订单总金额
Code int `json:"code"` // 0为成功其它为失败
Msg string `json:"msg"` // 请求接口消息
Data []CreateOrderData `json:"data"` // 返回数据 data array
}
type CreateOrderData struct {
ThirdOrderNo string `json:"thirdOrderNo"` // 第三方订单号 本地订单号
OrderNo string `json:"orderNo"` // 主订单号
McOrderNo string `json:"mcOrderNo"` //蜜仓子订单号
OrderAmount float64 `json:"orderAmount"` // 子订单总金额
Sku []SkuData `json:"sku"` // 订单商品信息
}
type SkuData struct {
GoodSpecId string `json:"good_spec_id"` //商品ID(c_goods_id)
GoodsId string `json:"goods_id"` //商品ID(c_father_goods_id)
GoodName string `json:"good_name"` //商品名称
GoodSpecId string `json:"goodSpecId"` //商品ID(c_goods_id)
GoodsId string `json:"goodsId"` //商品ID(c_father_goods_id)
GoodName string `json:"goodName"` //商品名称
Num string `json:"num"` //数量
Price string `json:"price"` //单价
}
@ -68,6 +75,18 @@ type GetOrderInfoByItemNORes struct {
RefuseType string `json:"refuse_type"` // 售后类型【RETURN_MONEY 退款’,RETURN_GOODS 退货’】
}
type GetOrderInfoByThirdNORes struct {
Code int `json:"code"` // 0为成功其它为失败
Msg string `json:"msg"` // 请求接口消息
Data []OrderInfoData `json:"data"` // 返回数据 data array
}
type OrderInfoData struct {
OrderItemNo string `json:"order_item_no"` // 子订单号
SendStatus string `json:"send_status"` //发货状态【CHECKED订单被创建,INSTOCK已备货,SENDED已发货,RECEIVED已收货
DeliveryName string `json:"delivery_name"` // 快递公司
DeliveryNo string `json:"delivery_no"` // 快递单号
}
type IsRefundRes struct {
Code int `json:"code"` // 0为成功其它为失败
Msg string `json:"msg"` // 请求接口消息

View File

@ -25,17 +25,17 @@ func NewWeiPinShangClient(host, channelType, key string) *WeiPinShangClient {
}
}
func (w *WeiPinShangClient) GetManyPostage(getManyPostageReq GetManyPostageReq) (res *GetManyPostageRes, err error) {
func (w *WeiPinShangClient) GetManyPostage(getManyPostageReq *GetManyPostageReq) (res *GetManyPostageRes, err error) {
fmt.Println("getManyPostageReq", getManyPostageReq)
paramMap := make(map[string]any)
paramMap["goodsInfo"] = getManyPostageReq.GoodsInfo
paramMap["goodInfo"] = getManyPostageReq.GoodsInfo
paramMap["address"] = getManyPostageReq.Address
paramMap["province"] = getManyPostageReq.Province
paramMap["county"] = getManyPostageReq.County
paramMap["city"] = getManyPostageReq.City
postRes, err := w.WPSPost("/mcang/Mcang/getManyPostage", paramMap)
postRes, err := w.WPSPost("mcang/Mcang/getManyPostage", paramMap)
if err != nil {
return
}
@ -49,7 +49,7 @@ func (w *WeiPinShangClient) GetManyPostage(getManyPostageReq GetManyPostageReq)
return
}
func (w *WeiPinShangClient) PreOrder(preOrderReq PreOrderReq) (res *PreOrderRes, err error) {
func (w *WeiPinShangClient) PreOrder(preOrderReq *PreOrderReq) (res *PreOrderRes, err error) {
fmt.Println("preOrderReq", preOrderReq)
paramMap := make(map[string]any)
paramMap["lockCode"] = preOrderReq.LockCode
@ -61,9 +61,9 @@ func (w *WeiPinShangClient) PreOrder(preOrderReq PreOrderReq) (res *PreOrderRes,
paramMap["area"] = preOrderReq.Area
paramMap["city"] = preOrderReq.City
paramMap["goodsInfo"] = preOrderReq.GoodsInfo
paramMap["goodInfo"] = preOrderReq.GoodsInfo
paramMap["source"] = preOrderReq.Source
postRes, err := w.WPSPost("/mcang/Order/preOrder", paramMap)
postRes, err := w.WPSPost("mcang/Order/preOrder", paramMap)
if err != nil {
return
}
@ -77,13 +77,13 @@ func (w *WeiPinShangClient) PreOrder(preOrderReq PreOrderReq) (res *PreOrderRes,
return
}
func (w *WeiPinShangClient) CreateOrder(createOrderReq CreateOrderReq) (res *CreateOrderRes, err error) {
func (w *WeiPinShangClient) CreateOrder(createOrderReq *CreateOrderReq) (res *CreateOrderRes, err error) {
fmt.Println("createOrderReq", createOrderReq)
paramMap := make(map[string]any)
paramMap["lockCode"] = createOrderReq.LockCode
paramMap["orderNo"] = createOrderReq.OrderNo
paramMap["noticeUrl"] = createOrderReq.NoticeUrl
postRes, err := w.WPSPost("/mcang/Order/createOrder", paramMap)
postRes, err := w.WPSPost("mcang/Order/createOrder", paramMap)
if err != nil {
return
}
@ -101,7 +101,7 @@ func (w *WeiPinShangClient) GetOrderInfo(orderNo string) (res *GetOrderInfoRes,
fmt.Println("orderNo", orderNo)
paramMap := make(map[string]any)
paramMap["orderNo"] = orderNo
postRes, err := w.WPSPost("/mcang/Mcang/getOrderInfo", paramMap)
postRes, err := w.WPSPost("mcang/Mcang/getOrderInfo", paramMap)
if err != nil {
return
}
@ -117,9 +117,12 @@ func (w *WeiPinShangClient) GetOrderInfo(orderNo string) (res *GetOrderInfoRes,
func (w *WeiPinShangClient) GetOrderInfoByItemNO(mcOrderNo string) (res *GetOrderInfoByItemNORes, err error) {
fmt.Println("mcOrderNo", mcOrderNo)
paramMap := make(map[string]any)
paramMap["mcOrderNo"] = mcOrderNo
postRes, err := w.WPSPost("/mcang/Mcang/getOrderInfoByItemNO", paramMap)
//paramMap := make(map[string]any)
//paramMap["mcOrderNo"] = mcOrderNo
paramMap := map[string]any{
"mcOrderNo": mcOrderNo,
}
postRes, err := w.WPSPost("mcang/Order/getOrderInfoByItemNO", paramMap)
if err != nil {
return
}
@ -133,11 +136,29 @@ func (w *WeiPinShangClient) GetOrderInfoByItemNO(mcOrderNo string) (res *GetOrde
return
}
func (w *WeiPinShangClient) GetOrderInfoByThirdNO(orderNo string) (res *GetOrderInfoByThirdNORes, err error) {
fmt.Println("orderNo", orderNo)
paramMap := make(map[string]any)
paramMap["orderNo"] = orderNo
postRes, err := w.WPSPost("mcang/Order/getOrderInfoByThirdNO", paramMap)
if err != nil {
return
}
err = json.Unmarshal(postRes, &res)
if err != nil || res == nil {
err = fmt.Errorf("转换GetOrderInfoByThirdNORes结构体失败: %s", string(postRes))
return
}
return
}
func (w *WeiPinShangClient) IsRefund(mcOrderNo string) (res *IsRefundRes, err error) {
fmt.Println("mcOrderNo", mcOrderNo)
paramMap := make(map[string]any)
paramMap["mcOrderNo"] = mcOrderNo
postRes, err := w.WPSPost("/mcang/Refunds/IsRefund", paramMap)
postRes, err := w.WPSPost("mcang/Refunds/IsRefund", paramMap)
if err != nil {
return
}
@ -150,7 +171,7 @@ func (w *WeiPinShangClient) IsRefund(mcOrderNo string) (res *IsRefundRes, err er
return
}
func (w *WeiPinShangClient) CreateAfsApply(createAfsApplyReq CreateAfsApplyReq) (res *CreateAfsApplyRes, err error) {
func (w *WeiPinShangClient) CreateAfsApply(createAfsApplyReq *CreateAfsApplyReq) (res *CreateAfsApplyRes, err error) {
fmt.Println("createAfsApplyReq", createAfsApplyReq)
paramMap := make(map[string]any)
@ -168,7 +189,7 @@ func (w *WeiPinShangClient) CreateAfsApply(createAfsApplyReq CreateAfsApplyReq)
paramMap["pickwareCounty"] = createAfsApplyReq.PickwareCounty
paramMap["pickwareAddress"] = createAfsApplyReq.PickwareAddress
postRes, err := w.WPSPost("/mcang/Refunds/IsRefund", paramMap)
postRes, err := w.WPSPost("mcang/Refunds/IsRefund", paramMap)
if err != nil {
return
}
@ -185,7 +206,7 @@ func (w *WeiPinShangClient) OrderCancel(mcOrderNo string) (res *OrderCancelRes,
fmt.Println("mcOrderNo", mcOrderNo)
paramMap := make(map[string]any)
paramMap["mcOrderNo"] = mcOrderNo
postRes, err := w.WPSPost("/mcang/Refunds/IsRefund", paramMap)
postRes, err := w.WPSPost("mcang/Refunds/IsRefund", paramMap)
if err != nil {
return
}
@ -207,7 +228,7 @@ func (w *WeiPinShangClient) Sign(paramMap map[string]any) (res string, err error
}
md5Sum := md5.Sum([]byte(sumParamString))
md5Str := hex.EncodeToString(md5Sum[:])
md5Str = strings.ToUpper(md5Str)
md5Str = strings.ToLower(md5Str)
return md5Str, nil
}
@ -246,7 +267,7 @@ func (w *WeiPinShangClient) WPSPost(url string, paramMap map[string]any) (res []
return
}
//fmt.Printf("res: %s\n", string(res))
fmt.Printf("res: %s\n", string(res))
if !json.Valid(res) {
return nil, fmt.Errorf("响应不是有效的JSON格式: %s", string(res))

View File

@ -0,0 +1,254 @@
package weipinshang_api
import (
"log"
"testing"
)
func TestWeiPinShangClient_GetManyPostage(t *testing.T) {
type fields struct {
Host string
ChannelType string
Key string
}
//type args struct {
// ip string
//}
tests := []struct {
name string
fields fields
args GetManyPostageReq
wantRes *GetManyPostageRes
wantErr bool
}{
{
name: "test1",
fields: fields{
Host: "https://uat.api.weipinshang.net/",
ChannelType: "AILEHUI",
Key: "f654ea5bde7635c3f46191191e5c4c8e",
},
args: GetManyPostageReq{
GoodsInfo: "[{\"goodsId\":\"WPS592_00019\",\"goodSpecId\":\"WPS592_1105165115160944\",\"num\":1},{\"goodsId\":\"WPS505_00007\",\"goodSpecId\":\"WPS505_1007111249857536\",\"num\":1}]",
Province: "广东省",
Address: "奥园",
City: "广州市",
County: "番禺区",
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
h := &WeiPinShangClient{
Host: test.fields.Host,
ChannelType: test.fields.ChannelType,
Key: test.fields.Key,
}
gotRes, err := h.GetManyPostage(&test.args)
log.Println(gotRes, err)
if (err != nil) != test.wantErr {
t.Errorf("GetManyPostage() error = %v, wantErr %v", err, test.wantErr)
}
})
}
}
func TestWeiPinShangClient_PreOrder(t *testing.T) {
type fields struct {
Host string
ChannelType string
Key string
}
//type args struct {
// ip string
//}
tests := []struct {
name string
fields fields
args PreOrderReq
wantRes *PreOrderRes
wantErr bool
}{
{
name: "test1",
fields: fields{
Host: "https://uat.api.weipinshang.net/",
ChannelType: "AILEHUI",
Key: "f654ea5bde7635c3f46191191e5c4c8e",
},
args: PreOrderReq{
GoodsInfo: "[{\"goodsId\":\"WPS9_282520\",\"goodSpecId\":\"WPS9_1221183858889276\",\"num\":1}]",
Province: "广东省",
Address: "奥园",
City: "广州市",
Area: "番禺区",
ConsigneePhone: "15375390426",
ConsigneeContacts: "张三",
LockCode: "L1234567890",
Source: "AILEHUI",
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
h := &WeiPinShangClient{
Host: test.fields.Host,
ChannelType: test.fields.ChannelType,
Key: test.fields.Key,
}
gotRes, err := h.PreOrder(&test.args)
log.Println(gotRes, err)
if (err != nil) != test.wantErr {
t.Errorf("GetManyPostage() error = %v, wantErr %v", err, test.wantErr)
}
})
}
}
func TestWeiPinShangClient_CreateOrder(t *testing.T) {
type fields struct {
Host string
ChannelType string
Key string
}
//type args struct {
// ip string
//}
tests := []struct {
name string
fields fields
args CreateOrderReq
wantRes *CreateOrderRes
wantErr bool
}{
{
name: "test1",
fields: fields{
Host: "https://uat.api.weipinshang.net/",
ChannelType: "AILEHUI",
Key: "f654ea5bde7635c3f46191191e5c4c8e",
},
args: CreateOrderReq{
LockCode: "L1234567890",
OrderNo: "10000000000",
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
h := &WeiPinShangClient{
Host: test.fields.Host,
ChannelType: test.fields.ChannelType,
Key: test.fields.Key,
}
gotRes, err := h.CreateOrder(&test.args)
log.Println(gotRes, err)
if (err != nil) != test.wantErr {
t.Errorf("GetManyPostage() error = %v, wantErr %v", err, test.wantErr)
}
})
}
}
func TestWeiPinShangClient_GetOrderInfoByItemNO(t *testing.T) {
type fields struct {
Host string
ChannelType string
Key string
}
type args struct {
mcOrderNo string
}
tests := []struct {
name string
fields fields
args args
wantRes *GetOrderInfoByItemNORes
wantErr bool
}{
{
name: "test1",
fields: fields{
Host: "https://uat.api.weipinshang.net/",
ChannelType: "AILEHUI",
Key: "f654ea5bde7635c3f46191191e5c4c8e",
},
args: args{
mcOrderNo: "mc20250527174640537475",
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
h := &WeiPinShangClient{
Host: test.fields.Host,
ChannelType: test.fields.ChannelType,
Key: test.fields.Key,
}
gotRes, err := h.GetOrderInfoByItemNO(test.args.mcOrderNo)
log.Println(gotRes, err)
if (err != nil) != test.wantErr {
t.Errorf("GetManyPostage() error = %v, wantErr %v", err, test.wantErr)
}
})
}
}
func TestWeiPinShangClient_GetOrderInfoByThirdNO(t *testing.T) {
type fields struct {
Host string
ChannelType string
Key string
}
type args struct {
orderNo string
}
tests := []struct {
name string
fields fields
args args
wantRes *GetOrderInfoByThirdNORes
wantErr bool
}{
{
name: "test1",
fields: fields{
Host: "https://uat.api.weipinshang.net/",
ChannelType: "AILEHUI",
Key: "f654ea5bde7635c3f46191191e5c4c8e",
},
args: args{
orderNo: "10000000000",
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
h := &WeiPinShangClient{
Host: test.fields.Host,
ChannelType: test.fields.ChannelType,
Key: test.fields.Key,
}
gotRes, err := h.GetOrderInfoByThirdNO(test.args.orderNo)
log.Println(gotRes, err)
if (err != nil) != test.wantErr {
t.Errorf("GetManyPostage() error = %v, wantErr %v", err, test.wantErr)
}
})
}
}