aa
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
package weixinapi
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/platformapi"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
@@ -58,3 +63,35 @@ func TestCBGetTicketInfo(t *testing.T) {
|
||||
}
|
||||
t.Log(utils.Format4Output(userInfo, false))
|
||||
}
|
||||
|
||||
func TestCBBatchgetMaterial(t *testing.T) {
|
||||
userInfo, err := api.CBBatchgetMaterial(MaterialTypeNews, 19, 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(userInfo, false))
|
||||
}
|
||||
|
||||
func TestCBUploadImg(t *testing.T) {
|
||||
data, _, _ := DownloadFileByURL("https://image.jxc4.com/noGoodsImg.jpg")
|
||||
result, err := api.CBUploadImg(data, "noGoodsImg.jpg", "image/jpeg")
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user