Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
36664d298e | ||
![]() |
0bbbfa3c1e | ||
![]() |
169996cc8a | ||
![]() |
6d3891390f | ||
![]() |
5574b1ba4e | ||
![]() |
0b6b76c708 | ||
![]() |
4c27cecde1 | ||
![]() |
1b97811c6a | ||
![]() |
2483d9c305 | ||
![]() |
e936dd6622 | ||
![]() |
3e765809e1 | ||
![]() |
ecfa733a9b | ||
![]() |
448d47d0cb | ||
![]() |
fa3ae27283 | ||
![]() |
094d4abdf4 | ||
![]() |
c9190ea4d4 | ||
![]() |
9fbd72fa16 | ||
![]() |
b535467e6f | ||
![]() |
3957f3b5b9 | ||
![]() |
79f36b239b | ||
![]() |
20a3b65f01 |
10
go.mod
10
go.mod
@@ -3,3 +3,13 @@ module git.ssgfgtfy.com/public/ssgf_utils
|
|||||||
go 1.18.0
|
go 1.18.0
|
||||||
|
|
||||||
require github.com/pkg/errors v0.9.1
|
require github.com/pkg/errors v0.9.1
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||||
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
github.com/redis/go-redis/v9 v9.10.0 // indirect
|
||||||
|
github.com/stretchr/testify v1.10.0 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
)
|
||||||
|
15
go.sum
15
go.sum
@@ -1,2 +1,17 @@
|
|||||||
|
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||||
|
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||||
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/redis/go-redis/v9 v9.10.0 h1:FxwK3eV8p/CQa0Ch276C7u2d0eNC9kCmAYQ7mCXCzVs=
|
||||||
|
github.com/redis/go-redis/v9 v9.10.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=
|
||||||
|
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||||
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package ip_tool
|
package ip_tool
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -15,12 +16,14 @@ import (
|
|||||||
type HuaChenIpClient struct {
|
type HuaChenIpClient struct {
|
||||||
AppCode string
|
AppCode string
|
||||||
Host string
|
Host string
|
||||||
|
cache ICacheAdapter
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHuaChenIpClient(appCode string) *HuaChenIpClient {
|
func NewHuaChenIpClient(appCode string, cache ICacheAdapter) *HuaChenIpClient {
|
||||||
return &HuaChenIpClient{
|
return &HuaChenIpClient{
|
||||||
AppCode: appCode,
|
AppCode: appCode,
|
||||||
Host: "https://c2ba.api.huachen.cn",
|
Host: "https://c2ba.api.huachen.cn",
|
||||||
|
cache: cache,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,6 +90,37 @@ func (h *HuaChenIpClient) GetIpInfo(ip string) (res *ApiResult, err error) {
|
|||||||
return &apiResult, nil
|
return &apiResult, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *HuaChenIpClient) GetIpInfoFormCache(ctx context.Context, ip string, ttl time.Duration) (res *ApiResult, err error) {
|
||||||
|
getCache, err := h.cache.Get(ctx, h.ipKey(ip))
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "获取缓存失败,ip:%s", ip)
|
||||||
|
}
|
||||||
|
if getCache != nil {
|
||||||
|
return getCache, nil
|
||||||
|
}
|
||||||
|
res, err = h.GetIpInfo(ip)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "获取ip:%s信息失败,", ip)
|
||||||
|
}
|
||||||
|
|
||||||
|
var infoJson []byte
|
||||||
|
infoJson, err = json.Marshal(res)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "无法将IP信息转换为JSON,ip:%s", ip)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = h.cache.Set(ctx, h.ipKey(ip), string(infoJson), ttl)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "缓存ip:%s信息失败,", ip)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// ipKey 生成Redis key
|
||||||
|
func (h *HuaChenIpClient) ipKey(ip string) string {
|
||||||
|
return fmt.Sprintf("ip:%s", ip)
|
||||||
|
}
|
||||||
|
|
||||||
type ApiResult struct {
|
type ApiResult struct {
|
||||||
Ret int `json:"ret"`
|
Ret int `json:"ret"`
|
||||||
Msg string `json:"msg"`
|
Msg string `json:"msg"`
|
||||||
|
@@ -1,8 +1,14 @@
|
|||||||
package ip_tool
|
package ip_tool
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/redis/go-redis/v9"
|
||||||
"log"
|
"log"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHuaChenIpClient_GetIpInfo(t *testing.T) {
|
func TestHuaChenIpClient_GetIpInfo(t *testing.T) {
|
||||||
@@ -42,3 +48,73 @@ func TestHuaChenIpClient_GetIpInfo(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHuaChenIpClient_GetIpInfo1(t *testing.T) {
|
||||||
|
rdb := redis.NewClient(&redis.Options{
|
||||||
|
Addr: "",
|
||||||
|
Password: "",
|
||||||
|
DB: 1,
|
||||||
|
})
|
||||||
|
|
||||||
|
// 创建IP缓存实例
|
||||||
|
ipCache := NewRedisCache(rdb)
|
||||||
|
h := &HuaChenIpClient{
|
||||||
|
AppCode: "",
|
||||||
|
Host: "https://c2ba.api.huachen.cn",
|
||||||
|
cache: ipCache,
|
||||||
|
}
|
||||||
|
gotRes, err := h.GetIpInfoFormCache(context.Background(), "8.138.116.112")
|
||||||
|
log.Println(gotRes, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
type RedisCache struct {
|
||||||
|
client *redis.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRedisCache(client *redis.Client) *RedisCache {
|
||||||
|
return &RedisCache{client: client}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RedisCache) Set(ctx context.Context, ip string, info string, ttl time.Duration) error {
|
||||||
|
if ip == "" {
|
||||||
|
return errors.New("ip不能为空")
|
||||||
|
}
|
||||||
|
|
||||||
|
return r.client.Set(ctx, ip, info, ttl).Err()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get 从Redis获取IP信息
|
||||||
|
func (r *RedisCache) Get(ctx context.Context, ip string) (*ApiResult, error) {
|
||||||
|
if ip == "" {
|
||||||
|
return nil, errors.New("ip不能为空")
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := r.client.Get(ctx, ip).Bytes()
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, redis.Nil) {
|
||||||
|
return nil, nil // 键不存在,返回nil而不是错误
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("无法获取IP信息: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var info ApiResult
|
||||||
|
if err = json.Unmarshal(data, &info); err != nil {
|
||||||
|
return nil, fmt.Errorf("无法解析IP信息: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &info, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exists 检查IP是否存在缓存中
|
||||||
|
func (r *RedisCache) Exists(ctx context.Context, ip string) (bool, error) {
|
||||||
|
if ip == "" {
|
||||||
|
return false, errors.New("ip不能为空")
|
||||||
|
}
|
||||||
|
|
||||||
|
exists, err := r.client.Exists(ctx, ip).Result()
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Errorf("无法检查IP是否存在: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return exists > 0, nil
|
||||||
|
}
|
||||||
|
13
ip_tool/ip_cache.go
Normal file
13
ip_tool/ip_cache.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package ip_tool
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Cache 定义缓存接口,遵循接口隔离原则
|
||||||
|
type ICacheAdapter interface {
|
||||||
|
Set(ctx context.Context, ip string, info string, ttl time.Duration) error
|
||||||
|
Get(ctx context.Context, ip string) (*ApiResult, error)
|
||||||
|
Exists(ctx context.Context, ip string) (bool, error)
|
||||||
|
}
|
107
weipinshang/goods_api.go
Normal file
107
weipinshang/goods_api.go
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
package wps
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
// GetGoodBrand 查询商品的品牌
|
||||||
|
func (c *WeiPinShangClient) GetGoodBrand(req GoodBrandReq) (*GoodBrandList, error) {
|
||||||
|
param := StructToMapString(req)
|
||||||
|
out := GoodBrandRes{}
|
||||||
|
err := c.PostAndParse(GetGoodBrandURL, param, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if out.Code != 0 {
|
||||||
|
return nil, fmt.Errorf(out.Msg)
|
||||||
|
}
|
||||||
|
res := out.Data
|
||||||
|
return &res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGoodsClassify 查询商品分类
|
||||||
|
func (c *WeiPinShangClient) GetGoodsClassify(req GetGoodsClassifyReq) (*[]GoodsClassify, error) {
|
||||||
|
param := StructToMapString(req)
|
||||||
|
out := GetGoodsClassifyRes{}
|
||||||
|
err := c.PostAndParse(GetGoodsClassifyURL, param, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if out.Code != 0 {
|
||||||
|
return nil, fmt.Errorf(out.Msg)
|
||||||
|
}
|
||||||
|
res := out.Data
|
||||||
|
return &res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGoodsList 获取全部商品列表接口
|
||||||
|
func (c *WeiPinShangClient) GetGoodsList(req GetGoodsListReq) (*GetGoodsList, error) {
|
||||||
|
param := StructToMapString(req)
|
||||||
|
out := GetGoodsListRes{}
|
||||||
|
err := c.PostAndParse(GetGoodsListURL, param, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if out.Code != 0 {
|
||||||
|
return nil, fmt.Errorf(out.Msg)
|
||||||
|
}
|
||||||
|
res := out.Data
|
||||||
|
return &res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGoodsdept (推荐使用)获取后台已选商品列表接口
|
||||||
|
func (c *WeiPinShangClient) GetGoodsdept(req GetGoodsdeptReq) (*Goodsdept, error) {
|
||||||
|
param := StructToMapString(req)
|
||||||
|
out := GetGoodsdeptRes{}
|
||||||
|
err := c.PostAndParse(GetGoodsdeptURL, param, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if out.Code != 0 {
|
||||||
|
return nil, fmt.Errorf(out.Msg)
|
||||||
|
}
|
||||||
|
res := out.Data
|
||||||
|
return &res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetDetailsGoods 获取批量商品详情
|
||||||
|
func (c *WeiPinShangClient) GetDetailsGoods(req GetDetailsGoodsReq) (*[]GoodsItem, error) {
|
||||||
|
param := StructToMapString(req)
|
||||||
|
out := GetDetailsGoodsRes{}
|
||||||
|
err := c.PostAndParse(GetDetailsGoodsUrl, param, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if out.Code != 0 {
|
||||||
|
return nil, fmt.Errorf(out.Msg)
|
||||||
|
}
|
||||||
|
res := out.Data
|
||||||
|
return &res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGoodsDetails 获取单个商品详情接口
|
||||||
|
func (c *WeiPinShangClient) GetGoodsDetails(req GetGoodsDetailsReq) (*GoodsItem, error) {
|
||||||
|
param := StructToMapString(req)
|
||||||
|
out := GetGoodsDetailsRes{}
|
||||||
|
err := c.PostAndParse(GetGoodsDetailsURL, param, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if out.Code != 0 {
|
||||||
|
return nil, fmt.Errorf(out.Msg)
|
||||||
|
}
|
||||||
|
res := out.Data
|
||||||
|
return &res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *WeiPinShangClient) GetGoodsStock(req GetGoodsStockReq) (*[]GoodsStock, error) {
|
||||||
|
param := StructToMapString(req)
|
||||||
|
out := GetGoodsStockRes{}
|
||||||
|
err := c.PostAndParse(GetGoodsStockURL, param, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if out.Code != 0 {
|
||||||
|
return nil, fmt.Errorf(out.Msg)
|
||||||
|
}
|
||||||
|
res := out.Data
|
||||||
|
return &res, err
|
||||||
|
}
|
112
weipinshang/goods_api_test.go
Normal file
112
weipinshang/goods_api_test.go
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
package wps_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
wps "git.ssgfgtfy.com/public/ssgf_utils/weipinshang"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func setupMockServer(path string, method string, response string, t *testing.T) *httptest.Server {
|
||||||
|
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
assert.Equal(t, "/"+path, r.URL.Path)
|
||||||
|
assert.Equal(t, method, r.Method)
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
w.Write([]byte(response))
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
func newClientWithServer(ts *httptest.Server) *wps.WeiPinShangClient {
|
||||||
|
return wps.NewWeiPinShangClient(wps.WpsConfig{
|
||||||
|
BaseURL: wps.DevHost,
|
||||||
|
ChannelType: "AILEHUI",
|
||||||
|
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetGoodBrand(t *testing.T) {
|
||||||
|
ts := setupMockServer(wps.GetGoodBrandURL, http.MethodPost, `{"code":200,"data":{"brands":[]}}`, t)
|
||||||
|
defer ts.Close()
|
||||||
|
client := newClientWithServer(ts)
|
||||||
|
res, err := client.GetGoodBrand(wps.GoodBrandReq{
|
||||||
|
PageNo: "2",
|
||||||
|
PageSize: "2",
|
||||||
|
CBrandName: "测试",
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NotNil(t, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetGoodsClassify(t *testing.T) {
|
||||||
|
ts := setupMockServer(wps.GetGoodsClassifyURL, http.MethodPost, `{"code":200,"data":{"classify":[]}}`, t)
|
||||||
|
defer ts.Close()
|
||||||
|
|
||||||
|
client := newClientWithServer(ts)
|
||||||
|
res, err := client.GetGoodsClassify(wps.GetGoodsClassifyReq{
|
||||||
|
CLevel: "2",
|
||||||
|
CParentCode: "13315",
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NotNil(t, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetGoodsList(t *testing.T) {
|
||||||
|
ts := setupMockServer(wps.GetGoodsListURL, http.MethodPost, `{"code":200,"data":{"goods":[]}}`, t)
|
||||||
|
defer ts.Close()
|
||||||
|
|
||||||
|
client := newClientWithServer(ts)
|
||||||
|
res, err := client.GetGoodsList(wps.GetGoodsListReq{
|
||||||
|
PageNo: "1",
|
||||||
|
PageSize: "10",
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NotNil(t, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetGoodsdept(t *testing.T) {
|
||||||
|
ts := setupMockServer(wps.GetGoodsdeptURL, http.MethodPost, `{"code":200,"data":{"list":[]}}`, t)
|
||||||
|
defer ts.Close()
|
||||||
|
|
||||||
|
client := newClientWithServer(ts)
|
||||||
|
res, err := client.GetGoodsdept(wps.GetGoodsdeptReq{})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NotNil(t, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetDetailsGoods(t *testing.T) {
|
||||||
|
ts := setupMockServer(wps.GetDetailsGoodsUrl, http.MethodPost, `{"code":200,"data":{"details":[]}}`, t)
|
||||||
|
defer ts.Close()
|
||||||
|
|
||||||
|
client := newClientWithServer(ts)
|
||||||
|
res, err := client.GetDetailsGoods(wps.GetDetailsGoodsReq{
|
||||||
|
FatherId: "WPS9_282520,WPS9_282450",
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NotNil(t, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetGoodsDetails(t *testing.T) {
|
||||||
|
ts := setupMockServer(wps.GetGoodsDetailsURL, http.MethodPost, `{"code":200,"data":{"goodsInfo":{}}}`, t)
|
||||||
|
defer ts.Close()
|
||||||
|
|
||||||
|
client := newClientWithServer(ts)
|
||||||
|
res, err := client.GetGoodsDetails(wps.GetGoodsDetailsReq{
|
||||||
|
FatherId: "WPS9_282520",
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NotNil(t, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetGoodsStock(t *testing.T) {
|
||||||
|
ts := setupMockServer(wps.GetGoodsStockURL, http.MethodPost, `{"code":200,"data":{"stocks":[]}}`, t)
|
||||||
|
defer ts.Close()
|
||||||
|
|
||||||
|
client := newClientWithServer(ts)
|
||||||
|
res, err := client.GetGoodsStock(wps.GetGoodsStockReq{
|
||||||
|
FatherId: "WPS9_282520",
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NotNil(t, res)
|
||||||
|
}
|
201
weipinshang/model.go
Normal file
201
weipinshang/model.go
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
package wps
|
||||||
|
|
||||||
|
//type BaseRes struct {
|
||||||
|
// Code int64 `json:"code"` //返回编码[0为成功,其它为失败]
|
||||||
|
// Msg string `json:"msg"` //返回信息[请求接口消息]
|
||||||
|
// Data interface{} `json:"data"` //返回数据
|
||||||
|
//}
|
||||||
|
|
||||||
|
// GoodBrandReq 查询商品的品牌
|
||||||
|
type GoodBrandReq struct {
|
||||||
|
PageNo string `json:"pageNo"` //页码
|
||||||
|
PageSize string `json:"pageSize"` //条数
|
||||||
|
CBrandName string `json:"c_brand_name"` //品牌名称 模糊查询
|
||||||
|
}
|
||||||
|
|
||||||
|
type GoodBrandRes struct {
|
||||||
|
Code int64 `json:"code"` //返回编码[0为成功,其它为失败]
|
||||||
|
Msg string `json:"msg"` //返回信息[请求接口消息]
|
||||||
|
Data GoodBrandList `json:"data"` //返回数据
|
||||||
|
}
|
||||||
|
|
||||||
|
type GoodBrandList struct {
|
||||||
|
PageIndex interface{} `json:"pageIndex"` //有时是字符串,有时是int
|
||||||
|
PageCount int `json:"pageCount"`
|
||||||
|
DataCount int `json:"dataCount"`
|
||||||
|
List []GoodBrand `json:"list"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GoodBrand struct {
|
||||||
|
CId int `json:"c_id"` //自增id
|
||||||
|
CBrandName string `json:"c_brand_name"` //名称
|
||||||
|
CBrandLogoUrl string `json:"c_brand_logo_url"` //logo地址
|
||||||
|
CCreateTime string `json:"c_create_time"`
|
||||||
|
CUpdateTime string `json:"c_update_time"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGoodsClassifyReq 查询商品分类
|
||||||
|
type GetGoodsClassifyReq struct {
|
||||||
|
CLevel string `json:"c_level"` //分类层级,1为一级分类 2为二级分类 3为三级分类(不传默认为1)
|
||||||
|
CParentCode string `json:"c_parent_code"` //上级分类code
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetGoodsClassifyRes struct {
|
||||||
|
Code int64 `json:"code"` //返回编码[0为成功,其它为失败]
|
||||||
|
Msg string `json:"msg"` //返回信息[请求接口消息]
|
||||||
|
Data []GoodsClassify `json:"data"` //返回数据
|
||||||
|
}
|
||||||
|
|
||||||
|
type GoodsClassify struct {
|
||||||
|
CId int `json:"c_id"` //自增id
|
||||||
|
CName string `json:"c_name"` //名称
|
||||||
|
CCode string `json:"c_code"` //分类code
|
||||||
|
CLevel int `json:"c_level"` //层级
|
||||||
|
CParentCode string `json:"c_parent_code"` //上级code
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGoodsListReq 获取全部商品列表接口(若使用该接口 需跟对接人说明,开启商品消息全推)
|
||||||
|
type GetGoodsListReq struct {
|
||||||
|
PageNo string `json:"pageNo"` //页码 [默认查询第1页]
|
||||||
|
PageSize string `json:"pageSize"` //显示条数 [默认显示10条 最大值100]
|
||||||
|
IsSort int `json:"is_sort"` //排序 [不传默认为正序,传1为倒序]
|
||||||
|
ProfitSpace int `json:"profitSpace"` //利润空间 [1=>5%以下,2=>5%-10%,3=>10%-20%,4=>20%-50%,5=>50%-100%,6=>100%-200%,7=>200%-500%,8=>500%-700%,9=>700%-900%,10=>900%以上]
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetGoodsListRes struct {
|
||||||
|
Code int64 `json:"code"` //返回编码[0为成功,其它为失败]
|
||||||
|
Msg string `json:"msg"` //返回信息[请求接口消息]
|
||||||
|
Data GetGoodsList `json:"data"` //返回数据
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetGoodsList struct {
|
||||||
|
PageIndex string `json:"pageIndex"`
|
||||||
|
PageCount int `json:"pageCount"`
|
||||||
|
DataCount int `json:"dataCount"`
|
||||||
|
List []Goods `json:"list"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Goods struct {
|
||||||
|
CId int `json:"c_id"` // 序号(商品ID)
|
||||||
|
CFatherGoodsId string `json:"c_father_goods_id"` // 商品父类ID
|
||||||
|
CGoodsName string `json:"c_goods_name"` // 商品名称
|
||||||
|
CGoodsImage string `json:"c_goods_image"` // 商品图片(1张商品主图)
|
||||||
|
CClassId int `json:"c_class_id"` // 分类ID(一级)
|
||||||
|
CClassDesc string `json:"c_class_desc"` // 分类描述(一级)
|
||||||
|
CClass2Id int `json:"c_class2_id"` // 二级分类ID
|
||||||
|
CClass2Desc string `json:"c_class2_desc"` // 二级分类描述
|
||||||
|
CBrandId int `json:"c_brand_id"` // 品牌ID
|
||||||
|
CBrandName string `json:"c_brand_name"` // 品牌名称
|
||||||
|
CNoDeliveryArea string `json:"c_no_delivery_area"` // 不发货地区,为 "0" 或 "" 表示不限
|
||||||
|
CStartDatetime string `json:"c_start_datetime"` // 上架时间(格式:yyyy-MM-dd HH:mm:ss)
|
||||||
|
CStopDatetime string `json:"c_stop_datetime"` // 下架时间(格式:yyyy-MM-dd HH:mm:ss)
|
||||||
|
COriginalPrice string `json:"c_original_price"` // 商品原价(吊牌价)
|
||||||
|
CSalePrice string `json:"c_sale_price"` // 建议售价
|
||||||
|
CInPrice string `json:"c_in_price"` // 进货价格
|
||||||
|
CGoodsStockValid int `json:"c_goods_stock_valid"` // 当前有效库存(下单库存,不足时下单失败)
|
||||||
|
CGoodsStockStart int `json:"c_goods_stock_start"` // 原始库存(商品录入时库存)
|
||||||
|
CSpecifications string `json:"c_specifications"` // 商品详细规格(商品属性描述)
|
||||||
|
CCompanyCode string `json:"c_company_code"` // 供应商编码
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGoodsdeptReq (推荐使用)获取后台已选商品列表接口
|
||||||
|
type GetGoodsdeptReq struct {
|
||||||
|
PageNo string `json:"pageNo"` //页码 [默认查询第1页]
|
||||||
|
PageSize string `json:"pageSize"` //显示条数 [默认显示10条 最大值100]
|
||||||
|
ProfitSpace int `json:"profitSpace"` //利润空间 [1=>5%以下,2=>5%-10%,3=>10%-20%,4=>20%-50%,5=>50%-100%,6=>100%-200%,7=>200%-500%,8=>500%-700%,9=>700%-900%,10=>900%以上]
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetGoodsdeptRes struct {
|
||||||
|
Code int64 `json:"code"` //返回编码[0为成功,其它为失败]
|
||||||
|
Msg string `json:"msg"` //返回信息[请求接口消息]
|
||||||
|
Data Goodsdept `json:"data"` //返回数据
|
||||||
|
}
|
||||||
|
|
||||||
|
type Goodsdept struct {
|
||||||
|
PageIndex interface{} `json:"pageIndex"`
|
||||||
|
PageCount int `json:"pageCount"`
|
||||||
|
DataCount int `json:"dataCount"`
|
||||||
|
List []Goods `json:"list"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetDetailsGoodsReq 获取批量商品详情接口
|
||||||
|
type GetDetailsGoodsReq struct {
|
||||||
|
FatherId string `json:"father_id"` //商品父级ID Spu编码
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetDetailsGoodsRes struct {
|
||||||
|
Code int64 `json:"code"` //返回编码[0为成功,其它为失败]
|
||||||
|
Msg string `json:"msg"` //返回信息[请求接口消息]
|
||||||
|
Data []GoodsItem `json:"data"` //返回数据
|
||||||
|
}
|
||||||
|
|
||||||
|
type GoodsItem struct {
|
||||||
|
CExhibitionID string `json:"c_exhibition_id"` // 会场ID(特卖商品时有值)
|
||||||
|
CFatherGoodsID string `json:"c_father_goods_id"` // 父级商品ID
|
||||||
|
CGoodsName string `json:"c_goods_name"` // 商品名称
|
||||||
|
CGoodsDescription string `json:"c_goods_description"` // 商品描述
|
||||||
|
CNoDeliveryArea string `json:"c_no_delivery_area"` // 不发货地区,为"0"或""表示不限
|
||||||
|
COriginalPrice string `json:"c_original_price"` // 商品原价(吊牌价)
|
||||||
|
CInPrice string `json:"c_in_price"` // 商品进价
|
||||||
|
CSalePrice string `json:"c_sale_price"` // 商品建议售价
|
||||||
|
CGoodsImage string `json:"c_goods_image"` // 商品主图
|
||||||
|
CDetailsImages string `json:"c_details_images"` // 商品详情图(多图用“;”分隔)
|
||||||
|
CBannerImages string `json:"c_banner_images"` // 商品banner图(多图用“;”分隔)
|
||||||
|
CBrandID int `json:"c_brand_id"` // 品牌ID
|
||||||
|
CBrandIcon string `json:"c_brand_icon"` // 品牌图标
|
||||||
|
CBrandName string `json:"c_brand_name"` // 品牌名称
|
||||||
|
CClassID int `json:"c_class_id"` // 一级分类ID
|
||||||
|
CClassDesc string `json:"c_class_desc"` // 一级分类描述
|
||||||
|
CClass2ID int `json:"c_class2_id"` // 二级分类ID
|
||||||
|
CClass2Desc string `json:"c_class2_desc"` // 二级分类描述
|
||||||
|
CClass3ID int `json:"c_class3_id"` // 三级分类ID
|
||||||
|
CClass3Desc string `json:"c_class3_desc"` // 三级分类描述
|
||||||
|
CIsShow int `json:"c_is_show"` // 商品状态:0下架,1上架
|
||||||
|
CStartDatetime string `json:"c_start_datetime"` // 上架时间
|
||||||
|
CStopDatetime string `json:"c_stop_datetime"` // 下架时间
|
||||||
|
CSpecifications string `json:"c_specifications"` // 商品详细规格(商品属性描述)
|
||||||
|
CCompanyCode string `json:"c_company_code"` // 供应商编码
|
||||||
|
GoodsSku []GoodsSkuItem `json:"goods_sku"` // 商品SKU列表
|
||||||
|
}
|
||||||
|
|
||||||
|
// 商品SKU信息
|
||||||
|
type GoodsSkuItem struct {
|
||||||
|
CFatherGoodsID string `json:"c_father_goods_id"` // 父级商品ID
|
||||||
|
CGoodsID string `json:"c_goods_id"` // 商品ID
|
||||||
|
CGoodsName string `json:"c_goods_name"` // 商品规格名称
|
||||||
|
COriginalPrice string `json:"c_original_price"` // 商品市场价
|
||||||
|
CInPrice string `json:"c_in_price"` // 商品进价
|
||||||
|
CSalePrice string `json:"c_sale_price"` // 商品建议售价
|
||||||
|
CGoodsColor string `json:"c_goods_color"` // 商品颜色
|
||||||
|
CGoodsSize string `json:"c_goods_size"` // 商品尺寸
|
||||||
|
CGoodsImage string `json:"c_goods_image"` // 商品列表图片
|
||||||
|
CGoodsStockStart int `json:"c_goods_stock_start"` // 初始总库存
|
||||||
|
CGoodsStockValid int `json:"c_goods_stock_valid"` // 有效库存(下单库存参考)
|
||||||
|
CBuyMinNum int `json:"c_buy_min_num"` // 最小购买数量
|
||||||
|
CBuyMaxNum int `json:"c_buy_max_num"` // 最大购买数量
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetGoodsDetailsReq struct {
|
||||||
|
FatherId string `json:"father_id"` //商品父级ID Spu编码
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetGoodsDetailsRes struct {
|
||||||
|
Code int64 `json:"code"` //返回编码[0为成功,其它为失败]
|
||||||
|
Msg string `json:"msg"` //返回信息[请求接口消息]
|
||||||
|
Data GoodsItem `json:"data"` //返回数据
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetGoodsStockReq struct {
|
||||||
|
FatherId string `json:"father_id"` //商品父级ID Spu编码
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetGoodsStockRes struct {
|
||||||
|
Code int64 `json:"code"` //返回编码[0为成功,其它为失败]
|
||||||
|
Msg string `json:"msg"` //返回信息[请求接口消息]
|
||||||
|
Data []GoodsStock `json:"data"` //返回数据
|
||||||
|
}
|
||||||
|
|
||||||
|
type GoodsStock struct {
|
||||||
|
CGoodsId string `json:"c_goods_id"`
|
||||||
|
CStock int `json:"c_stock"`
|
||||||
|
}
|
223
weipinshang/wei_pin_shang_client.go
Normal file
223
weipinshang/wei_pin_shang_client.go
Normal file
@@ -0,0 +1,223 @@
|
|||||||
|
package wps
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/md5"
|
||||||
|
"encoding/hex"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"reflect"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DevHost = "https://uat.api.weipinshang.net/"
|
||||||
|
ReleaseHost = "https://api.weipinshang.net/"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
GetGoodBrandURL = "mcang/Mcang/goodBrand" //查询商品的品牌
|
||||||
|
GetGoodsClassifyURL = "mcang/Mcang/getGoodsClassify" //查询商品分类
|
||||||
|
GetGoodsListURL = "mcang/Mcang/getGoodsList" //获取全部商品列表接口
|
||||||
|
GetGoodsdeptURL = "mcang/Mcang/getGoodsdept" //(推荐使用)获取后台已选商品列表接口
|
||||||
|
GetDetailsGoodsUrl = "mcang/Mcang/getDetailsGoods" //获取批量商品详情接口
|
||||||
|
GetGoodsDetailsURL = "mcang/Mcang/getGoodsDetails" //获取单个商品详情接口
|
||||||
|
GetGoodsStockURL = "mcang/Mcang/getGoodsStock" //获取单个商品详情接口
|
||||||
|
)
|
||||||
|
|
||||||
|
// Config 客户端配置
|
||||||
|
type WpsConfig struct {
|
||||||
|
ChannelType string
|
||||||
|
Key string
|
||||||
|
BaseURL string
|
||||||
|
Timeout time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
// WeiPinShangClient 客户端结构体
|
||||||
|
type WeiPinShangClient struct {
|
||||||
|
ChannelType string
|
||||||
|
Key string
|
||||||
|
BaseURL string
|
||||||
|
HttpClient *http.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewWeiPinShangClient 创建客户端
|
||||||
|
func NewWeiPinShangClient(cfg WpsConfig) *WeiPinShangClient {
|
||||||
|
if cfg.ChannelType == "" {
|
||||||
|
cfg.ChannelType = "AILEHUI"
|
||||||
|
}
|
||||||
|
if cfg.BaseURL == "" {
|
||||||
|
cfg.BaseURL = ReleaseHost
|
||||||
|
}
|
||||||
|
if cfg.Key == "" {
|
||||||
|
cfg.Key = "f654ea5bde7635c3f46191191e5c4c8e"
|
||||||
|
}
|
||||||
|
if cfg.Timeout == 0 {
|
||||||
|
cfg.Timeout = 10 * time.Second
|
||||||
|
}
|
||||||
|
return &WeiPinShangClient{
|
||||||
|
ChannelType: cfg.ChannelType,
|
||||||
|
Key: cfg.Key,
|
||||||
|
BaseURL: cfg.BaseURL,
|
||||||
|
HttpClient: &http.Client{Timeout: cfg.Timeout},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sign 生成签名
|
||||||
|
func (c *WeiPinShangClient) sign(params map[string]string) string {
|
||||||
|
keys := make([]string, 0, len(params))
|
||||||
|
for k := range params {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
|
|
||||||
|
var sb strings.Builder
|
||||||
|
for _, k := range keys {
|
||||||
|
v := params[k]
|
||||||
|
if v == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
sb.WriteString(k)
|
||||||
|
sb.WriteString("=")
|
||||||
|
sb.WriteString(v)
|
||||||
|
sb.WriteString("&")
|
||||||
|
}
|
||||||
|
signStr := strings.TrimRight(sb.String(), "&") + c.ChannelType + c.Key
|
||||||
|
hash := md5.Sum([]byte(signStr))
|
||||||
|
return hex.EncodeToString(hash[:])
|
||||||
|
}
|
||||||
|
|
||||||
|
// buildHeaders 构建请求头
|
||||||
|
func (c *WeiPinShangClient) buildHeaders(params map[string]string) http.Header {
|
||||||
|
headers := http.Header{}
|
||||||
|
headers.Set("channelType", c.ChannelType)
|
||||||
|
headers.Set("md5", c.sign(params))
|
||||||
|
headers.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
return headers
|
||||||
|
}
|
||||||
|
|
||||||
|
// buildRequest 构造请求对象
|
||||||
|
func (c *WeiPinShangClient) buildRequest(method, endpoint string, params map[string]string) (*http.Request, error) {
|
||||||
|
var (
|
||||||
|
req *http.Request
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
if method == http.MethodPost {
|
||||||
|
form := url.Values{}
|
||||||
|
for k, v := range params {
|
||||||
|
form.Set(k, v)
|
||||||
|
}
|
||||||
|
req, err = http.NewRequest(method, c.BaseURL+endpoint, strings.NewReader(form.Encode()))
|
||||||
|
} else {
|
||||||
|
query := url.Values{}
|
||||||
|
for k, v := range params {
|
||||||
|
query.Set(k, v)
|
||||||
|
}
|
||||||
|
req, err = http.NewRequest(method, fmt.Sprintf("%s%s?%s", c.BaseURL, endpoint, query.Encode()), nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("构建请求失败,地址:%s,err:%v", endpoint, err.Error())
|
||||||
|
}
|
||||||
|
req.Header = c.buildHeaders(params)
|
||||||
|
return req, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// doRequest 执行请求并返回字符串响应
|
||||||
|
func (c *WeiPinShangClient) doRequest(req *http.Request) (string, error) {
|
||||||
|
resp, err := c.HttpClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return "", errors.Wrap(err, "HTTP request failed")
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return "", fmt.Errorf("HTTP status error: %s", resp.Status)
|
||||||
|
}
|
||||||
|
|
||||||
|
body, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("读取response body失败。err:%v", err.Error())
|
||||||
|
}
|
||||||
|
return string(body), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Post 发起 POST 请求
|
||||||
|
func (c *WeiPinShangClient) Post(endpoint string, params map[string]string) (string, error) {
|
||||||
|
req, err := c.buildRequest(http.MethodPost, endpoint, params)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return c.doRequest(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get 发起 GET 请求
|
||||||
|
func (c *WeiPinShangClient) Get(endpoint string, params map[string]string) (string, error) {
|
||||||
|
req, err := c.buildRequest(http.MethodGet, endpoint, params)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return c.doRequest(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAndParse 发起 GET 请求并解析 JSON 响应
|
||||||
|
func (c *WeiPinShangClient) GetAndParse(endpoint string, params map[string]string, out interface{}) error {
|
||||||
|
respStr, err := c.Get(endpoint, params)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return json.Unmarshal([]byte(respStr), out)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PostAndParse 发起 POST 请求并解析 JSON 响应
|
||||||
|
func (c *WeiPinShangClient) PostAndParse(endpoint string, params map[string]string, out interface{}) error {
|
||||||
|
respStr, err := c.Post(endpoint, params)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return json.Unmarshal([]byte(respStr), out)
|
||||||
|
}
|
||||||
|
|
||||||
|
func StructToMapString(obj interface{}) map[string]string {
|
||||||
|
result := make(map[string]string)
|
||||||
|
|
||||||
|
v := reflect.ValueOf(obj)
|
||||||
|
t := reflect.TypeOf(obj)
|
||||||
|
|
||||||
|
// 支持结构体指针
|
||||||
|
if v.Kind() == reflect.Ptr {
|
||||||
|
v = v.Elem()
|
||||||
|
t = t.Elem()
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < v.NumField(); i++ {
|
||||||
|
field := t.Field(i)
|
||||||
|
valueField := v.Field(i)
|
||||||
|
|
||||||
|
// 只导出可访问的字段
|
||||||
|
if !valueField.CanInterface() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断是否为零值
|
||||||
|
if reflect.DeepEqual(valueField.Interface(), reflect.Zero(valueField.Type()).Interface()) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
key := field.Tag.Get("json")
|
||||||
|
if key == "" {
|
||||||
|
key = field.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
result[key] = fmt.Sprintf("%v", valueField.Interface())
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
@@ -1,7 +1,7 @@
|
|||||||
package weipinshang_api
|
package weipinshang_api
|
||||||
|
|
||||||
type CreateAfsApplyReq struct {
|
type CreateAfsApplyReq struct {
|
||||||
McOrderNo int `json:"mcOrderNo"` // 子订单号 是 int 下单时候返回子订单号 20190704124955600363
|
McOrderNo string `json:"mcOrderNo"` // 子订单号 是 int 下单时候返回子订单号 20190704124955600363
|
||||||
CustomerExpect int `json:"customerExpect"` // 售后类型 是 int [退货(10)、仅退款(40)] 10
|
CustomerExpect int `json:"customerExpect"` // 售后类型 是 int [退货(10)、仅退款(40)] 10
|
||||||
QuestionDesc string `json:"questionDesc"` // 原因描述 否 String [产品问题描述,最多600字符] 看下面请求示例
|
QuestionDesc string `json:"questionDesc"` // 原因描述 否 String [产品问题描述,最多600字符] 看下面请求示例
|
||||||
QuestionPic string `json:"questionPic"` //问题描述图片 否 String [问题描述图片.最多2000字符] 支持多张图片,用逗号分隔(英文逗号)
|
QuestionPic string `json:"questionPic"` //问题描述图片 否 String [问题描述图片.最多2000字符] 支持多张图片,用逗号分隔(英文逗号)
|
||||||
@@ -35,8 +35,8 @@ type PreOrderReq struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GoodsInfo struct {
|
type GoodsInfo struct {
|
||||||
GoodSpecId string `json:"goodSpecId"` //商品ID goodSpecId 是 String 商品ID(c_goods_id)
|
GoodSpecId string `json:"goodSpecId"` //SKU ID goodSpecId 是 String 商品ID(c_goods_id)
|
||||||
GoodsId string `json:"goodsId"` //商品父 goodsId 是 String 商品父ID(c_father_goods_id)
|
GoodsId string `json:"goodsId"` //商品ID goodsId 是 String 商品父ID(c_father_goods_id)
|
||||||
Num string `json:"num"` // 数量
|
Num string `json:"num"` // 数量
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,3 +45,24 @@ type CreateOrderReq struct {
|
|||||||
OrderNo string `json:"orderNo"` //对接方业务单号 orderNo 是 String
|
OrderNo string `json:"orderNo"` //对接方业务单号 orderNo 是 String
|
||||||
NoticeUrl string `json:"noticeUrl"` //合作方通知地址 noticeUrl 否 String 规定值 如支持,订单更新实时通知。此参数可不用传,统一走异步回调
|
NoticeUrl string `json:"noticeUrl"` //合作方通知地址 noticeUrl 否 String 规定值 如支持,订单更新实时通知。此参数可不用传,统一走异步回调
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RefundDeliveryReq struct {
|
||||||
|
McOrderNo string `json:"mcOrderNo"` // 子订单号 是 int 下单时候返回子订单号 20190704124955600363
|
||||||
|
DeliveryName string `json:"deliveryName"` // 快递公司
|
||||||
|
DeliveryNo string `json:"deliveryNo"` // 快递单号
|
||||||
|
Freight string `json:"freight"` // 运费金额 freight 否 string 单位:元
|
||||||
|
FreightImg string `json:"freightImg"` // 运费支付凭证 freightImg 否 string 图片地址
|
||||||
|
}
|
||||||
|
|
||||||
|
// test ------------------------------------------------
|
||||||
|
|
||||||
|
type DeliverGoodsReq struct {
|
||||||
|
COrderItemNo string `json:"c_order_item_no"` //c_order_item_no 子订单号 是 int 下单时候返回子订单号 20190704124955600363
|
||||||
|
CDeliveryName string `json:"c_delivery_name"` // 快递公司
|
||||||
|
CDeliveryNo string `json:"c_delivery_no"` // 快递单号
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdateServiceReq struct {
|
||||||
|
COrderItemNo string `json:"c_order_item_no"` //c_order_item_no 子订单号 是 int 下单时候返回子订单号 20190704124955600363
|
||||||
|
CType string `json:"c_type"` //c_type 快递名称 是 String [处理类型 1 同意售后 2 拒绝 3 退款完成]
|
||||||
|
}
|
||||||
|
@@ -36,8 +36,9 @@ type SkuData struct {
|
|||||||
GoodSpecId string `json:"goodSpecId"` //商品ID(c_goods_id)
|
GoodSpecId string `json:"goodSpecId"` //商品ID(c_goods_id)
|
||||||
GoodsId string `json:"goodsId"` //商品ID(c_father_goods_id)
|
GoodsId string `json:"goodsId"` //商品ID(c_father_goods_id)
|
||||||
GoodName string `json:"goodName"` //商品名称
|
GoodName string `json:"goodName"` //商品名称
|
||||||
Num string `json:"num"` //数量
|
//Num string `json:"num"` //数量
|
||||||
Price string `json:"price"` //单价
|
Num int `json:"num"` //数量
|
||||||
|
Price string `json:"price"` //单价
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetOrderInfoRes struct {
|
type GetOrderInfoRes struct {
|
||||||
@@ -46,8 +47,9 @@ type GetOrderInfoRes struct {
|
|||||||
Data []Data `json:"data"` // 返回数据 data array
|
Data []Data `json:"data"` // 返回数据 data array
|
||||||
}
|
}
|
||||||
type Data struct {
|
type Data struct {
|
||||||
CThirdUserCode string `json:"c_third_user_code"` // 用户编码
|
CThirdUserCode string `json:"c_third_user_code"` // 用户编码
|
||||||
COrderNoThird string `json:"c_order_no_third"` // 渠道订单号
|
//COrderNoThird string `json:"c_order_no_third"` // 渠道订单号
|
||||||
|
COrderNo string `json:"c_order_no"` // 渠道订单号
|
||||||
COrderNoPayservice string `json:"c_order_no_payservice"` //支付订单号
|
COrderNoPayservice string `json:"c_order_no_payservice"` //支付订单号
|
||||||
CSendStatus string `json:"c_send_status"` // 订单状态 订单所处阶段【’’CHECKED订单被创建’’,’INSTOCK已备货’,’’SENDED已发货’’,’’RECEIVED已收货’’】
|
CSendStatus string `json:"c_send_status"` // 订单状态 订单所处阶段【’’CHECKED订单被创建’’,’INSTOCK已备货’,’’SENDED已发货’’,’’RECEIVED已收货’’】
|
||||||
CIsPay int `json:"c_is_pay"` // 支付状态(0-未支付,1-已支付)
|
CIsPay int `json:"c_is_pay"` // 支付状态(0-未支付,1-已支付)
|
||||||
@@ -67,6 +69,12 @@ type Data struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GetOrderInfoByItemNORes struct {
|
type GetOrderInfoByItemNORes struct {
|
||||||
|
Code int `json:"code"` // 0为成功,其它为失败
|
||||||
|
Msg string `json:"msg"` // 请求接口消息
|
||||||
|
Data OrderInfoByItemNOData `json:"data"` // 返回数据 data array
|
||||||
|
|
||||||
|
}
|
||||||
|
type OrderInfoByItemNOData struct {
|
||||||
OrderItemNo string `json:"order_item_no"` // 子订单号
|
OrderItemNo string `json:"order_item_no"` // 子订单号
|
||||||
SendStatus string `json:"send_status"` //发货状态【’CHECKED订单被创建’,’INSTOCK已备货’,’SENDED已发货’,’RECEIVED已收货’】
|
SendStatus string `json:"send_status"` //发货状态【’CHECKED订单被创建’,’INSTOCK已备货’,’SENDED已发货’,’RECEIVED已收货’】
|
||||||
DeliveryName string `json:"delivery_name"` // 快递公司
|
DeliveryName string `json:"delivery_name"` // 快递公司
|
||||||
@@ -81,6 +89,8 @@ type GetOrderInfoByThirdNORes struct {
|
|||||||
Data []OrderInfoData `json:"data"` // 返回数据 data array
|
Data []OrderInfoData `json:"data"` // 返回数据 data array
|
||||||
}
|
}
|
||||||
type OrderInfoData struct {
|
type OrderInfoData struct {
|
||||||
|
GoodsId string `json:"goodsId"` //商品ID goodsId 是 String 商品父ID(c_father_goods_id)
|
||||||
|
GoodSpecId string `json:"goodSpecId"` //SKU ID goodSpecId 是 String 商品ID(c_goods_id)
|
||||||
OrderItemNo string `json:"order_item_no"` // 子订单号
|
OrderItemNo string `json:"order_item_no"` // 子订单号
|
||||||
SendStatus string `json:"send_status"` //发货状态【’CHECKED订单被创建’,’INSTOCK已备货’,’SENDED已发货’,’RECEIVED已收货’】
|
SendStatus string `json:"send_status"` //发货状态【’CHECKED订单被创建’,’INSTOCK已备货’,’SENDED已发货’,’RECEIVED已收货’】
|
||||||
DeliveryName string `json:"delivery_name"` // 快递公司
|
DeliveryName string `json:"delivery_name"` // 快递公司
|
||||||
@@ -88,8 +98,13 @@ type OrderInfoData struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type IsRefundRes struct {
|
type IsRefundRes struct {
|
||||||
Code int `json:"code"` // 0为成功,其它为失败
|
Code int `json:"code"` // 0为成功,其它为失败
|
||||||
Msg string `json:"msg"` // 请求接口消息
|
Msg string `json:"msg"` // 请求接口消息
|
||||||
|
Data IsRefundData `json:"data"` // 返回数据 data array
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
type IsRefundData struct {
|
||||||
ResultType []Param `json:"resultType"` // 售后类型
|
ResultType []Param `json:"resultType"` // 售后类型
|
||||||
WareReturn []Param `json:"wareReturn"` // 服务类型
|
WareReturn []Param `json:"wareReturn"` // 服务类型
|
||||||
}
|
}
|
||||||
@@ -109,3 +124,15 @@ type OrderCancelRes struct {
|
|||||||
Code int `json:"code"` // 0为成功,其它为失败
|
Code int `json:"code"` // 0为成功,其它为失败
|
||||||
Msg string `json:"msg"` // 请求接口消息
|
Msg string `json:"msg"` // 请求接口消息
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RefundDeliveryRes struct {
|
||||||
|
Code int `json:"code"` // 0为成功,其它为失败
|
||||||
|
Msg string `json:"msg"` // 请求接口消息
|
||||||
|
}
|
||||||
|
|
||||||
|
// test -------------------------------------
|
||||||
|
|
||||||
|
type TestRes struct {
|
||||||
|
Code int `json:"code"` // 0为成功,其它为失败
|
||||||
|
Msg string `json:"msg"` // 请求接口消息
|
||||||
|
}
|
||||||
|
@@ -5,6 +5,7 @@ import (
|
|||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -25,6 +26,8 @@ func NewWeiPinShangClient(host, channelType, key string) *WeiPinShangClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pay
|
||||||
|
|
||||||
func (w *WeiPinShangClient) GetManyPostage(getManyPostageReq *GetManyPostageReq) (res *GetManyPostageRes, err error) {
|
func (w *WeiPinShangClient) GetManyPostage(getManyPostageReq *GetManyPostageReq) (res *GetManyPostageRes, err error) {
|
||||||
fmt.Println("getManyPostageReq", getManyPostageReq)
|
fmt.Println("getManyPostageReq", getManyPostageReq)
|
||||||
paramMap := make(map[string]any)
|
paramMap := make(map[string]any)
|
||||||
@@ -97,6 +100,8 @@ func (w *WeiPinShangClient) CreateOrder(createOrderReq *CreateOrderReq) (res *Cr
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetOrderInfo 1
|
||||||
|
|
||||||
func (w *WeiPinShangClient) GetOrderInfo(orderNo string) (res *GetOrderInfoRes, err error) {
|
func (w *WeiPinShangClient) GetOrderInfo(orderNo string) (res *GetOrderInfoRes, err error) {
|
||||||
fmt.Println("orderNo", orderNo)
|
fmt.Println("orderNo", orderNo)
|
||||||
paramMap := make(map[string]any)
|
paramMap := make(map[string]any)
|
||||||
@@ -115,26 +120,7 @@ func (w *WeiPinShangClient) GetOrderInfo(orderNo string) (res *GetOrderInfoRes,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WeiPinShangClient) GetOrderInfoByItemNO(mcOrderNo string) (res *GetOrderInfoByItemNORes, err error) {
|
// GetOrderInfo n
|
||||||
fmt.Println("mcOrderNo", mcOrderNo)
|
|
||||||
//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
|
|
||||||
}
|
|
||||||
|
|
||||||
err = json.Unmarshal(postRes, &res)
|
|
||||||
if err != nil || res == nil {
|
|
||||||
err = fmt.Errorf("转换GetOrderInfoByItemNORes结构体失败: %s", string(postRes))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *WeiPinShangClient) GetOrderInfoByThirdNO(orderNo string) (res *GetOrderInfoByThirdNORes, err error) {
|
func (w *WeiPinShangClient) GetOrderInfoByThirdNO(orderNo string) (res *GetOrderInfoByThirdNORes, err error) {
|
||||||
fmt.Println("orderNo", orderNo)
|
fmt.Println("orderNo", orderNo)
|
||||||
@@ -154,6 +140,27 @@ func (w *WeiPinShangClient) GetOrderInfoByThirdNO(orderNo string) (res *GetOrder
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// refund
|
||||||
|
|
||||||
|
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/Order/getOrderInfoByItemNO", paramMap)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(postRes, &res)
|
||||||
|
if err != nil || res == nil {
|
||||||
|
err = fmt.Errorf("转换GetOrderInfoByItemNORes结构体失败: %s", string(postRes))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (w *WeiPinShangClient) IsRefund(mcOrderNo string) (res *IsRefundRes, err error) {
|
func (w *WeiPinShangClient) IsRefund(mcOrderNo string) (res *IsRefundRes, err error) {
|
||||||
fmt.Println("mcOrderNo", mcOrderNo)
|
fmt.Println("mcOrderNo", mcOrderNo)
|
||||||
paramMap := make(map[string]any)
|
paramMap := make(map[string]any)
|
||||||
@@ -189,7 +196,7 @@ func (w *WeiPinShangClient) CreateAfsApply(createAfsApplyReq *CreateAfsApplyReq)
|
|||||||
paramMap["pickwareCounty"] = createAfsApplyReq.PickwareCounty
|
paramMap["pickwareCounty"] = createAfsApplyReq.PickwareCounty
|
||||||
paramMap["pickwareAddress"] = createAfsApplyReq.PickwareAddress
|
paramMap["pickwareAddress"] = createAfsApplyReq.PickwareAddress
|
||||||
|
|
||||||
postRes, err := w.WPSPost("mcang/Refunds/IsRefund", paramMap)
|
postRes, err := w.WPSPost("mcang/Refunds/createAfsApply", paramMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -206,7 +213,7 @@ func (w *WeiPinShangClient) OrderCancel(mcOrderNo string) (res *OrderCancelRes,
|
|||||||
fmt.Println("mcOrderNo", mcOrderNo)
|
fmt.Println("mcOrderNo", mcOrderNo)
|
||||||
paramMap := make(map[string]any)
|
paramMap := make(map[string]any)
|
||||||
paramMap["mcOrderNo"] = mcOrderNo
|
paramMap["mcOrderNo"] = mcOrderNo
|
||||||
postRes, err := w.WPSPost("mcang/Refunds/IsRefund", paramMap)
|
postRes, err := w.WPSPost("mcang/Refunds/orderCancel", paramMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -219,6 +226,27 @@ func (w *WeiPinShangClient) OrderCancel(mcOrderNo string) (res *OrderCancelRes,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *WeiPinShangClient) RefundDelivery(refundDeliveryReq RefundDeliveryReq) (res *RefundDeliveryRes, err error) {
|
||||||
|
fmt.Println("refundDeliveryReq", refundDeliveryReq)
|
||||||
|
paramMap := make(map[string]any)
|
||||||
|
paramMap["mcOrderNo"] = refundDeliveryReq.McOrderNo
|
||||||
|
paramMap["deliveryName"] = refundDeliveryReq.DeliveryName
|
||||||
|
paramMap["deliveryNo"] = refundDeliveryReq.DeliveryNo
|
||||||
|
paramMap["freight"] = refundDeliveryReq.Freight
|
||||||
|
paramMap["freightImg"] = refundDeliveryReq.FreightImg
|
||||||
|
postRes, err := w.WPSPost("mcang/Refunds/refundDelivery", paramMap)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(postRes, &res)
|
||||||
|
if err != nil || res == nil {
|
||||||
|
err = fmt.Errorf("转换RefundDeliveryRes结构体失败: %s", string(postRes))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (w *WeiPinShangClient) Sign(paramMap map[string]any) (res string, err error) {
|
func (w *WeiPinShangClient) Sign(paramMap map[string]any) (res string, err error) {
|
||||||
var sumParamString string
|
var sumParamString string
|
||||||
if len(paramMap) != 0 {
|
if len(paramMap) != 0 {
|
||||||
@@ -270,8 +298,47 @@ func (w *WeiPinShangClient) WPSPost(url string, paramMap map[string]any) (res []
|
|||||||
fmt.Printf("res: %s\n", string(res))
|
fmt.Printf("res: %s\n", string(res))
|
||||||
|
|
||||||
if !json.Valid(res) {
|
if !json.Valid(res) {
|
||||||
return nil, fmt.Errorf("响应不是有效的JSON格式: %s", string(res))
|
return nil, errors.New("响应体不是有效的JSON格式")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test ----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
func (w *WeiPinShangClient) DeliverGoods(deliverGoodsReq *DeliverGoodsReq) (res *TestRes, err error) {
|
||||||
|
fmt.Println("deliverGoodsReq", deliverGoodsReq)
|
||||||
|
paramMap := make(map[string]any)
|
||||||
|
paramMap["c_order_item_no"] = deliverGoodsReq.COrderItemNo
|
||||||
|
paramMap["c_delivery_name"] = deliverGoodsReq.CDeliveryName
|
||||||
|
paramMap["c_delivery_no"] = deliverGoodsReq.CDeliveryNo
|
||||||
|
postRes, err := w.WPSPost("mcang/Cycle/deliverGoods", paramMap)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(postRes, &res)
|
||||||
|
if err != nil || res == nil {
|
||||||
|
err = fmt.Errorf("转换TestRes结构体失败: %s", string(postRes))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WeiPinShangClient) UpdateService(updateServiceReq *UpdateServiceReq) (res *TestRes, err error) {
|
||||||
|
fmt.Println("updateServiceReq", updateServiceReq)
|
||||||
|
paramMap := make(map[string]any)
|
||||||
|
paramMap["c_order_item_no"] = updateServiceReq.COrderItemNo
|
||||||
|
paramMap["c_type"] = updateServiceReq.CType
|
||||||
|
postRes, err := w.WPSPost("mcang/Cycle/updateService", paramMap)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(postRes, &res)
|
||||||
|
if err != nil || res == nil {
|
||||||
|
err = fmt.Errorf("转换TestRes结构体失败: %s", string(postRes))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@@ -80,14 +80,14 @@ func TestWeiPinShangClient_PreOrder(t *testing.T) {
|
|||||||
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||||
},
|
},
|
||||||
args: PreOrderReq{
|
args: PreOrderReq{
|
||||||
GoodsInfo: "[{\"goodsId\":\"WPS9_282520\",\"goodSpecId\":\"WPS9_1221183858889276\",\"num\":1}]",
|
GoodsInfo: "[{\"goodsId\":\"WPS9_282520\",\"goodSpecId\":\"WPS9_1221183858889276\",\"num\":2}]",
|
||||||
Province: "广东省",
|
Province: "广东省",
|
||||||
Address: "奥园",
|
Address: "奥园",
|
||||||
City: "广州市",
|
City: "广州市",
|
||||||
Area: "番禺区",
|
Area: "番禺区",
|
||||||
ConsigneePhone: "15375390426",
|
ConsigneePhone: "15375390426",
|
||||||
ConsigneeContacts: "张三",
|
ConsigneeContacts: "张三",
|
||||||
LockCode: "L1234567890",
|
LockCode: "L100000000",
|
||||||
Source: "AILEHUI",
|
Source: "AILEHUI",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -135,8 +135,8 @@ func TestWeiPinShangClient_CreateOrder(t *testing.T) {
|
|||||||
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||||
},
|
},
|
||||||
args: CreateOrderReq{
|
args: CreateOrderReq{
|
||||||
LockCode: "L1234567890",
|
LockCode: "L100000000",
|
||||||
OrderNo: "10000000000",
|
OrderNo: "30000000000",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -159,6 +159,55 @@ func TestWeiPinShangClient_CreateOrder(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWeiPinShangClient_GetOrderInfo(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 *GetOrderInfoRes
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "test1",
|
||||||
|
fields: fields{
|
||||||
|
Host: "https://uat.api.weipinshang.net/",
|
||||||
|
ChannelType: "AILEHUI",
|
||||||
|
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||||
|
},
|
||||||
|
args: args{
|
||||||
|
//orderNo: "20250527172503439229",
|
||||||
|
//orderNo: "10000000000",
|
||||||
|
orderNo: "20000000000",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
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.GetOrderInfo(test.args.orderNo)
|
||||||
|
|
||||||
|
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) {
|
func TestWeiPinShangClient_GetOrderInfoByItemNO(t *testing.T) {
|
||||||
type fields struct {
|
type fields struct {
|
||||||
Host string
|
Host string
|
||||||
@@ -183,7 +232,8 @@ func TestWeiPinShangClient_GetOrderInfoByItemNO(t *testing.T) {
|
|||||||
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||||
},
|
},
|
||||||
args: args{
|
args: args{
|
||||||
mcOrderNo: "mc20250527174640537475",
|
//mcOrderNo: "mc20250527174640537475",
|
||||||
|
mcOrderNo: "mc20250616115732440085",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -230,7 +280,19 @@ func TestWeiPinShangClient_GetOrderInfoByThirdNO(t *testing.T) {
|
|||||||
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||||
},
|
},
|
||||||
args: args{
|
args: args{
|
||||||
orderNo: "10000000000",
|
//orderNo: "10000000000",
|
||||||
|
orderNo: "20000000000",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "test1",
|
||||||
|
fields: fields{
|
||||||
|
Host: "https://uat.api.weipinshang.net/",
|
||||||
|
ChannelType: "AILEHUI",
|
||||||
|
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||||
|
},
|
||||||
|
args: args{
|
||||||
|
orderNo: "570872619444771455",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -252,3 +314,273 @@ func TestWeiPinShangClient_GetOrderInfoByThirdNO(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWeiPinShangClient_IsRefund(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 *IsRefundRes
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "test1",
|
||||||
|
fields: fields{
|
||||||
|
Host: "https://uat.api.weipinshang.net/",
|
||||||
|
ChannelType: "AILEHUI",
|
||||||
|
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||||
|
},
|
||||||
|
args: args{
|
||||||
|
mcOrderNo: "mc20250613182629112823",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
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.IsRefund(test.args.mcOrderNo)
|
||||||
|
|
||||||
|
log.Println(gotRes, err)
|
||||||
|
|
||||||
|
if (err != nil) != test.wantErr {
|
||||||
|
t.Errorf("GetManyPostage() error = %v, wantErr %v", err, test.wantErr)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWeiPinShangClient_OrderCancel(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 *IsRefundRes
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "test1",
|
||||||
|
fields: fields{
|
||||||
|
Host: "https://uat.api.weipinshang.net/",
|
||||||
|
ChannelType: "AILEHUI",
|
||||||
|
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||||
|
},
|
||||||
|
args: args{
|
||||||
|
mcOrderNo: "mc20250529102347485667",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
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.OrderCancel(test.args.mcOrderNo)
|
||||||
|
|
||||||
|
log.Println(gotRes, err)
|
||||||
|
|
||||||
|
if (err != nil) != test.wantErr {
|
||||||
|
t.Errorf("GetManyPostage() error = %v, wantErr %v", err, test.wantErr)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWeiPinShangClient_CreateAfsApply(t *testing.T) {
|
||||||
|
type fields struct {
|
||||||
|
Host string
|
||||||
|
ChannelType string
|
||||||
|
Key string
|
||||||
|
}
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
fields fields
|
||||||
|
args CreateAfsApplyReq
|
||||||
|
wantRes *IsRefundRes
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "test1",
|
||||||
|
fields: fields{
|
||||||
|
Host: "https://uat.api.weipinshang.net/",
|
||||||
|
ChannelType: "AILEHUI",
|
||||||
|
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||||
|
},
|
||||||
|
args: CreateAfsApplyReq{
|
||||||
|
CustomerContactName: "钟",
|
||||||
|
CustomerExpect: 10,
|
||||||
|
CustomerMobilePhone: "15375399426",
|
||||||
|
CustomerTel: "15375399426",
|
||||||
|
McOrderNo: "mc20250613182629112823",
|
||||||
|
PickwareAddress: "奥园",
|
||||||
|
PickwareCity: "广州",
|
||||||
|
PickwareCounty: "番禺",
|
||||||
|
PickwareProvince: "广东",
|
||||||
|
QuestionDesc: "商品问题",
|
||||||
|
QuestionPic: "11",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
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.CreateAfsApply(&test.args)
|
||||||
|
|
||||||
|
log.Println(gotRes, err)
|
||||||
|
|
||||||
|
if (err != nil) != test.wantErr {
|
||||||
|
t.Errorf("GetManyPostage() error = %v, wantErr %v", err, test.wantErr)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// test ---------------------------------------------------
|
||||||
|
|
||||||
|
func TestWeiPinShangClient_DeliverGoods(t *testing.T) {
|
||||||
|
type fields struct {
|
||||||
|
Host string
|
||||||
|
ChannelType string
|
||||||
|
Key string
|
||||||
|
}
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
fields fields
|
||||||
|
args DeliverGoodsReq
|
||||||
|
wantRes *TestRes
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "test1",
|
||||||
|
fields: fields{
|
||||||
|
Host: "https://uat.api.weipinshang.net/",
|
||||||
|
ChannelType: "AILEHUI",
|
||||||
|
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||||
|
},
|
||||||
|
args: DeliverGoodsReq{
|
||||||
|
COrderItemNo: "mc20250613182629112823",
|
||||||
|
CDeliveryName: "顺丰",
|
||||||
|
CDeliveryNo: "1234567890",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: "test1",
|
||||||
|
fields: fields{
|
||||||
|
Host: "https://uat.api.weipinshang.net/",
|
||||||
|
ChannelType: "AILEHUI",
|
||||||
|
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||||
|
},
|
||||||
|
args: DeliverGoodsReq{
|
||||||
|
COrderItemNo: "mc20250616113428587322",
|
||||||
|
CDeliveryName: "顺丰0",
|
||||||
|
CDeliveryNo: "SF9900000099",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
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.DeliverGoods(&test.args)
|
||||||
|
|
||||||
|
log.Println(gotRes, err)
|
||||||
|
|
||||||
|
if (err != nil) != test.wantErr {
|
||||||
|
t.Errorf("GetManyPostage() error = %v, wantErr %v", err, test.wantErr)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func TestWeiPinShangClient_UpdateService(t *testing.T) {
|
||||||
|
type fields struct {
|
||||||
|
Host string
|
||||||
|
ChannelType string
|
||||||
|
Key string
|
||||||
|
}
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
fields fields
|
||||||
|
args UpdateServiceReq
|
||||||
|
wantRes *TestRes
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "test1",
|
||||||
|
fields: fields{
|
||||||
|
Host: "https://uat.api.weipinshang.net/",
|
||||||
|
ChannelType: "AILEHUI",
|
||||||
|
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||||
|
},
|
||||||
|
args: UpdateServiceReq{
|
||||||
|
COrderItemNo: "mc20250612153935670660",
|
||||||
|
CType: "1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: "test1",
|
||||||
|
fields: fields{
|
||||||
|
Host: "https://uat.api.weipinshang.net/",
|
||||||
|
ChannelType: "AILEHUI",
|
||||||
|
Key: "f654ea5bde7635c3f46191191e5c4c8e",
|
||||||
|
},
|
||||||
|
args: UpdateServiceReq{
|
||||||
|
COrderItemNo: "mc20250609180246814560",
|
||||||
|
CType: "3",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
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.UpdateService(&test.args)
|
||||||
|
|
||||||
|
log.Println(gotRes, err)
|
||||||
|
|
||||||
|
if (err != nil) != test.wantErr {
|
||||||
|
t.Errorf("GetManyPostage() error = %v, wantErr %v", err, test.wantErr)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user