银豹商品上传图片
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
package yinbaoapi
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
@@ -84,3 +89,27 @@ func TestTryGetCookie(t *testing.T) {
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestUploadProductImage(t *testing.T) {
|
||||
url := "http://image.jxc4.com/image/243ec2100060c15a1eb009fd2ee99450.jpg"
|
||||
data, _, _ := DownloadFileByURL(url)
|
||||
err := api.UploadProductImage(MainStoreVendorOrgCode, "8788044", data, "243ec2100060c15a1eb009fd2ee99450.jpg")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user