Files
baseapi/platformapi/weixinapi/cgibin_test.go
邹宗楠 709da734ab 1
2022-05-19 17:00:19 +08:00

139 lines
3.5 KiB
Go

package weixinapi
import (
"crypto/md5"
"fmt"
"git.rosy.net.cn/baseapi/platformapi"
"io/ioutil"
"net/http"
"testing"
"git.rosy.net.cn/baseapi/utils"
)
func TestCBRetrieveToken(t *testing.T) {
result, err := api.CBRetrieveToken()
if err != nil || result.ExpiresIn != 7200 {
t.Fatal(err.Error())
}
sugarLogger.Debug(result)
}
func TestCBMessageTemplateSend(t *testing.T) {
// "oYN_usk0AeGc_C6VEZfmFQP5VHMQ": 1, // 周小扬
// "oYN_ust9hXKEvEv0X6Mq6nlAWs_E": 1, // me
// "oYN_usvnObzrPweIgHTad9-uMf78": 1, // 老赵
err := api.CBMessageTemplateSend("oYN_ust9hXKEvEv0X6Mq6nlAWs_E", "_DtNGwmOeR6TkkTVUblxLIlkV2MAPOX57TkvfdqG6nY", "", map[string]interface{}{
"appid": "wx4b5930c13f8b1170",
"pagepath": "pages/order-manager/main",
}, map[string]interface{}{
"first": "first",
"Day": "Day",
"orderId": "orderId",
"orderType": "orderType",
"customerName": "customerName",
"customerPhone": "customerPhone",
})
if err != nil {
t.Fatal(err.Error())
}
}
func TestCBUpdateRemark(t *testing.T) {
remark := "一二三四五六七八九十"
t.Log(len(remark))
err := api.CBUpdateRemark("oYN_ust9hXKEvEv0X6Mq6nlAWs_E", remark)
if err != nil {
t.Log(err)
}
}
func TestCBGetUserInfo(t *testing.T) {
userInfo, err := api.CBGetUserInfo("ox1y15LCS3ytipsTjEQ4_nXrRtkw")
if err != nil {
t.Fatal(err)
}
t.Log(utils.Format4Output(userInfo, false))
}
func TestCBGetTicketInfo(t *testing.T) {
userInfo, err := api.CBGetTicketInfo()
if err != nil {
t.Fatal(err)
}
t.Log(utils.Format4Output(userInfo, false))
}
func TestCBBatchgetMaterial(t *testing.T) {
userInfo, err := api.CBBatchgetMaterial(MaterialTypeThumb, 0, 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 TestCBCBUploadThumb(t *testing.T) {
data, _, _ := DownloadFileByURL("https://image.jxc4.com/noGoodsImg.jpg")
result, _, err := api.CBUploadThumb(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
}
func TestCBAddNews(t *testing.T) {
result, err := api.CBAddNews(&CBAddNewsParam{
Title: "测试素材",
ThumbMediaID: "cILZtVn68ncUY79JUE3tWFOGvL3GytjbKLOKiGbLK1I",
Author: "西西",
Digest: "测试摘要",
ShowCoverPic: 1,
Content: "测试内容:<p><b>测试段落</b></p>",
ContentSourceUrl: "",
NeedOpenComment: 0,
OnlyFansCanComment: 0,
})
if err != nil {
t.Fatal(err)
}
//cILZtVn68ncUY79JUE3tWL4YE2er7eHJJPV_BGRieHE
t.Log(utils.Format4Output(result, false))
}
func TestCBMassSend(t *testing.T) {
err := api.CBMassSend([]string{"oYN_usv1RPvrSxCvo1WsbwI8lZa0", "oYN_ushJ8Ma2kppYRlCJKSZxtzMk"}, "cILZtVn68ncUY79JUE3tWL4YE2er7eHJJPV_BGRieHE")
if err != nil {
t.Fatal(err)
}
//t.Log(utils.Format4Output(result, false))
}
func TestTode(t *testing.T) {
ccc := 3 &^ 1
fmt.Println(ccc)
}