京东商城一堆
This commit is contained in:
@@ -1,9 +1,21 @@
|
||||
package jdshopapi
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/gif"
|
||||
"image/jpeg"
|
||||
"image/png"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
func TestFindShopCategories(t *testing.T) {
|
||||
@@ -29,3 +41,206 @@ func TestFindVendorCategories(t *testing.T) {
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestUploadPicture(t *testing.T) {
|
||||
data, _, err := DownloadFileByURL("https://image.jxc4.com/noGoodsImg.jpg")
|
||||
// img, outMimeType, _ := Binary2Image(data, "")
|
||||
// result2, _ := Image2Binary(img, outMimeType)
|
||||
result, err := api.UploadPicture(data, 0, "noGoodsImg")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func DownloadFileByURL(fileURL string) (bodyData []byte, fileMD5 string, err error) {
|
||||
response, err := http.Get(fileURL)
|
||||
if err == nil {
|
||||
defer response.Body.Close()
|
||||
if response.StatusCode == http.StatusOK {
|
||||
if bodyData, err = ioutil.ReadAll(response.Body); err == nil {
|
||||
fileMD5 = fmt.Sprintf("%X", md5.Sum(bodyData))
|
||||
}
|
||||
} else {
|
||||
err = platformapi.ErrHTTPCodeIsNot200
|
||||
}
|
||||
}
|
||||
return bodyData, fileMD5, err
|
||||
}
|
||||
|
||||
func Binary2Image(binaryData []byte, mimeType string) (img image.Image, outMimeType string, err error) {
|
||||
if mimeType == "" {
|
||||
mimeType = http.DetectContentType(binaryData)
|
||||
}
|
||||
switch mimeType {
|
||||
case model.MimeTypeJpeg:
|
||||
img, err = jpeg.Decode(bytes.NewReader(binaryData))
|
||||
case model.MimeTypePng:
|
||||
img, err = png.Decode(bytes.NewReader(binaryData))
|
||||
case model.MimeTypeGif:
|
||||
img, err = gif.Decode(bytes.NewReader(binaryData))
|
||||
}
|
||||
return img, mimeType, err
|
||||
}
|
||||
|
||||
func Image2Binary(img image.Image, mimeType string) (binaryData []byte, err error) {
|
||||
buf := new(bytes.Buffer)
|
||||
switch mimeType {
|
||||
case model.MimeTypeJpeg:
|
||||
jpeg.Encode(buf, img, nil)
|
||||
case model.MimeTypePng:
|
||||
png.Encode(buf, img)
|
||||
case model.MimeTypeGif:
|
||||
gif.Encode(buf, img, nil)
|
||||
}
|
||||
binaryData = buf.Bytes()
|
||||
return binaryData, err
|
||||
}
|
||||
|
||||
func TestGetFeightMb(t *testing.T) {
|
||||
err := api.GetFeightMb()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestAA(t *testing.T) {
|
||||
ware := &CreateSkuParamWare{
|
||||
Title: "测试商品1",
|
||||
CategoryID: 13577,
|
||||
TransportID: TransportID,
|
||||
MobileDesc: "测试",
|
||||
Introduction: "测试",
|
||||
WareStatus: 8,
|
||||
OuterID: "1",
|
||||
Weight: 2300,
|
||||
Height: 100,
|
||||
Length: 100,
|
||||
Width: 100,
|
||||
JdPrice: 20,
|
||||
MarketPrice: 10,
|
||||
VenderID: 0,
|
||||
BrandID: JxBrandId,
|
||||
}
|
||||
result, _ := json.Marshal(ware)
|
||||
fmt.Println(string(result))
|
||||
}
|
||||
|
||||
func TestCreateSku(t *testing.T) {
|
||||
var images []*CreateSkuParamImages
|
||||
var skus []*CreateSkuParamSkus
|
||||
var attrs []*CreateSkuParamAttrs
|
||||
var attrs2 []*CreateSkuParamAttrs
|
||||
var attrs3 []*CreateSkuParamAttrs
|
||||
ware := &CreateSkuParamWare{
|
||||
Title: "测试商品1",
|
||||
ShopCategorys: []int{11},
|
||||
CategoryID: 13577,
|
||||
TransportID: TransportID,
|
||||
MobileDesc: "测试",
|
||||
Introduction: "测试",
|
||||
WareStatus: 8,
|
||||
OuterID: "1",
|
||||
Weight: 2300,
|
||||
Height: 100,
|
||||
Length: 100,
|
||||
Width: 100,
|
||||
JdPrice: 20,
|
||||
MarketPrice: 10,
|
||||
VenderID: 0,
|
||||
BrandID: JxBrandId,
|
||||
Is7ToReturn: 0,
|
||||
}
|
||||
image := &CreateSkuParamImages{
|
||||
ColorID: "0000000000",
|
||||
ImgIndex: 1,
|
||||
ImgURL: "jfs/t1/124185/34/1067/20460/5eb90d1aE2a81b6e4/ab451433f5e963b0.jpg",
|
||||
}
|
||||
images = append(images, image)
|
||||
ware.Images = images
|
||||
sku := &CreateSkuParamSkus{
|
||||
JdPrice: 10,
|
||||
StockNum: 1,
|
||||
Type: "com.jd.pop.ware.ic.api.domain.sku",
|
||||
Type2: "com.jd.pop.ware.ic.api.domain.Sku",
|
||||
}
|
||||
sku2 := &CreateSkuParamSkus{
|
||||
JdPrice: 10,
|
||||
StockNum: 1,
|
||||
Type: "com.jd.pop.ware.ic.api.domain.sku",
|
||||
Type2: "com.jd.pop.ware.ic.api.domain.Sku",
|
||||
}
|
||||
attr1 := &CreateSkuParamAttrs{
|
||||
AttrID: "109692",
|
||||
AttrValues: []string{"613613"},
|
||||
}
|
||||
// attr2 := &CreateSkuParamAttrs{
|
||||
// AttrID: "109897",
|
||||
// AttrValues: []string{"613771"},
|
||||
// }
|
||||
attr3 := &CreateSkuParamAttrs{
|
||||
AttrID: "160508",
|
||||
AttrValues: []string{"0.5"},
|
||||
}
|
||||
attr4 := &CreateSkuParamAttrs{
|
||||
AttrID: "160781",
|
||||
AttrValues: []string{"5"},
|
||||
}
|
||||
attr5 := &CreateSkuParamAttrs{
|
||||
AttrID: "1001027606",
|
||||
AttrValues: []string{"2440273517"},
|
||||
}
|
||||
attr6 := &CreateSkuParamAttrs{
|
||||
AttrID: "1001027606",
|
||||
AttrValues: []string{"2440272539"},
|
||||
}
|
||||
attrs = append(attrs, attr1)
|
||||
// attrs = append(attrs, attr2)
|
||||
attrs = append(attrs, attr3)
|
||||
attrs = append(attrs, attr4)
|
||||
attrs2 = append(attrs2, attr5)
|
||||
attrs3 = append(attrs3, attr6)
|
||||
ware.MultiCateProps = attrs
|
||||
sku2.SaleAttrs = attrs3
|
||||
sku.SaleAttrs = attrs2
|
||||
skus = append(skus, sku)
|
||||
skus = append(skus, sku2)
|
||||
result, err := api.CreateWare(ware, skus)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestFindAttrs(t *testing.T) {
|
||||
err := api.FindAttrs(13577)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestFindValuesByAttrId(t *testing.T) {
|
||||
err := api.FindValuesByAttrId(109692)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestSaveVenderAttrValue(t *testing.T) {
|
||||
err := api.SaveVenderAttrValue("0.5", 160806, 13571, 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestDeleteWare(t *testing.T) {
|
||||
err := api.DeleteWare(14509148757)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user