From 6e0a97f724d126fee98d147755959a291d9d1536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Wed, 9 Aug 2023 15:42:57 +0800 Subject: [PATCH] 1 --- platformapi/tao_vegetable/store_sku_test.go | 35 ++++++++++++++++----- platformapi/tao_vegetable/upload_img.go | 6 ++-- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/platformapi/tao_vegetable/store_sku_test.go b/platformapi/tao_vegetable/store_sku_test.go index 982609e2..aebcf6fb 100644 --- a/platformapi/tao_vegetable/store_sku_test.go +++ b/platformapi/tao_vegetable/store_sku_test.go @@ -1,6 +1,7 @@ package tao_vegetable import ( + "bytes" "fmt" request1475 "git.rosy.net.cn/baseapi/platformapi/tao_vegetable/sdk/ability1475/request" domain585 "git.rosy.net.cn/baseapi/platformapi/tao_vegetable/sdk/ability585/domain" @@ -9,6 +10,7 @@ import ( request589 "git.rosy.net.cn/baseapi/platformapi/tao_vegetable/sdk/ability589/request" "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/globals" + "image/jpeg" "io/ioutil" "net/http" "strings" @@ -18,7 +20,8 @@ import ( // 上传图片 func TestUploadImg(t *testing.T) { - uploadImg(apiTao, []string{"http://img20.360buyimg.com/vc/jfs/t2473/147/1629369634/4242813/e73adcd0/566a65f3N8aa04ec1.jpg,http://img20.360buyimg.com/vc/jfs/t1/109293/32/7166/234234/5e576c17E8e493056/cd6b8ba6db7f1522.png"}) + uploadImg(apiTao, []string{"http://img20.360buyimg.com/vc/jfs/t2473/147/1629369634/4242813/e73adcd0/566a65f3N8aa04ec1.jpg"}) + //uploadImg(apiTao, []string{"http://image.jxc4.com/image/2c28b6e2a1de59adba0f117b1519b5f7.png"}) } func TestAddStoreSku(t *testing.T) { @@ -113,11 +116,11 @@ func TestUpdateSku(t *testing.T) { param := &request585.AlibabaWdkSkuUpdateRequest{} updateSkuList := make([]domain585.AlibabaWdkSkuUpdateSkuDo, 0, 0) updateSku := domain585.AlibabaWdkSkuUpdateSkuDo{ - OuCode: utils.String2Pointer("JX667321"), - SkuCode: utils.String2Pointer("26024"), - ShortTitle: utils.String2Pointer("小时达"), - SkuPrice: utils.String2Pointer("80"), + OuCode: utils.String2Pointer("JX101870"), + SkuCode: utils.String2Pointer("6045426"), CleanSkuMemberPrice: utils.Int64ToPointer(1), + AllowAppSale: utils.Int64ToPointer(1), + OnlineSaleFlag: utils.Int64ToPointer(1), } updateSkuList = append(updateSkuList, updateSku) param.ParamList = &updateSkuList @@ -407,11 +410,24 @@ func uploadImg(api *API, imgs []string) *string { if strings.Contains(string(body), "Document not found") { continue } + if float64(len(body))/float64(1024)/float64(1024) > float64(3) { + jpgimg, err := jpeg.Decode(strings.NewReader(string(body))) // 文件解码成图像对象 + if err != nil { + return nil + } + var buf bytes.Buffer + err = jpeg.Encode(&buf, jpgimg, &jpeg.Options{Quality: 30}) + if err != nil { + return nil + } + body = buf.Bytes() + } + if newImg, _ := api.UploadImg(&request1475.AlibabaWdkPictureUploadRequest{ PictureCategoryId: utils.Int64ToPointer(0), Img: &body, - ImgInputTitle: utils.String2Pointer(v[inputTitle:]), - Title: utils.String2Pointer(v[inputTitle:title]), + ImgInputTitle: utils.String2Pointer(v[inputTitle+1:]), + Title: utils.String2Pointer(v[inputTitle+1 : title]), }); newImg != "" { result = append(result, newImg) } @@ -438,3 +454,8 @@ func TestUpLoadImg(t *testing.T) { globals.SugarLogger.Debugf("errr3 := %s", utils.Format4Output(err3, false)) globals.SugarLogger.Debugf("data2 := %s", utils.Format4Output(dataa, false)) } + +// 上传文件到七牛云 +func TestQiNiuYn(t *testing.T) { + +} diff --git a/platformapi/tao_vegetable/upload_img.go b/platformapi/tao_vegetable/upload_img.go index ba4a9a49..02f2d296 100644 --- a/platformapi/tao_vegetable/upload_img.go +++ b/platformapi/tao_vegetable/upload_img.go @@ -10,9 +10,11 @@ import ( func (a *API) UploadImg(param *request.AlibabaWdkPictureUploadRequest) (string, error) { client := ability1475.NewAbility1475(&a.client) - data, _ := client.AlibabaWdkPictureUpload(param, a.token) + data, err := client.AlibabaWdkPictureUpload(param, a.token) + if err != nil { + return "", err + } if data.Result.ErrCode != nil { - //globals.SugarLogger.Debugf("requestId[%s],err[%s]", data.RequestId, utils.Format4Output(data.Result, false)) return "", fmt.Errorf(*data.Result.ErrMsg) }