-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp_test.go
156 lines (137 loc) · 3.29 KB
/
app_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package ydapp
import (
"io/ioutil"
"net/http"
"path/filepath"
"testing"
)
const (
_Buin = 666666
_AppId = `yd37D192E9F20E448192827A001A84D443`
_EncAesKey = `AY2O92Lpyr4M2IOXT05NQG3eaXd72FlS/QZ1l4vGKsQ=`
_User = "sa08"
)
func TestAllApi(t *testing.T) {
Server_Addr = "http://localhost:7080"
demo, _ := NewMsgApp(_Buin, _AppId, _EncAesKey)
go http.ListenAndServe(":8899", demo)
//获取token
_, _, err := demo.GetToken()
if err != nil {
t.Error(err)
return
}
t.Log("Get accesstoken success:", demo.accToken)
//传入路径,上传文件
fileId, err := demo.UploadFile("hello.txt", filepath.Join("file", "hello.txt"))
if err != nil {
t.Error(err)
return
}
t.Log("File mediaId:", fileId)
//传入路径,上传图片
imgId, err := demo.UploadImage("lake.jpg", filepath.Join("file", "lake.jpg"))
if err != nil {
t.Error(err)
return
}
t.Log("Image mediaId:", imgId)
//下载图片并保存到指定路径
err = demo.DownloadFileSave(fileId, "file/file.txt")
if err != nil {
t.Error(err)
return
}
t.Log("Download and save file success.")
//下载文件,返回文件数据
data, err := demo.DownloadFile(fileId)
if err != nil {
t.Error(err)
return
}
ioutil.WriteFile("file/file1.txt", data, 0666)
t.Log("Download file success.")
//下载文件并保存到指定路径
err = demo.DownloadImageSave(imgId, "file/image.jpg")
if err != nil {
t.Error(err)
return
}
t.Log("Download and save image success.")
//下载图片,返回图片数据
data, err = demo.DownloadImage(imgId)
if err != nil {
t.Error(err)
}
ioutil.WriteFile("file/image1.jpg", data, 0666)
t.Log("Download file success.")
//发送文本消息
err = demo.SendTxtMsg(_User, "第三方接口测试123abc!@#$%^^&*()/::|/::)-+=-")
if err != nil {
t.Error(err)
return
}
t.Log("Send text msg success.")
//传入mediaId,发送图片信息
err = demo.SendImgMsg(_User, imgId)
if err != nil {
t.Error(err)
return
}
t.Log("Send image msg success.")
//传入mediaId,发送文件信息
err = demo.SendFileMsg(_User, fileId)
if err != nil {
t.Error(err)
return
}
t.Log("Send file msg success.")
//传入路径,上传并发送图片信息
err = demo.SendImg(_User, "file/lake.jpg")
if err != nil {
t.Error(err)
return
}
t.Log("Send image success.")
//传入路径,上传并发送文件信息
err = demo.SendFile(_User, "hello.txt", "file/hello.txt")
if err != nil {
t.Error(err)
return
}
t.Log("Send file success.")
m := &Mpnews{
Title: "测试标题1",
Path: "file/lake.jpg",
//MediaId: imgId,
Digest: "一些摘要",
Url: `http://www.zhbuswx.com/busline/BusQuery.html?v=1.97#/`,
Content: "我本将心向明月,奈何明月照沟渠",
ShowFront: 1,
}
//发送图文信息
err = demo.SendMpnewsMsg(_User, []*Mpnews{m})
if err != nil {
t.Error(err)
return
}
t.Log("Send msg success.")
link := &Exlink{
Title: "这是一个标题",
Url: "http://www.zhbuswx.com/busline/BusQuery.html?v=1.97#/",
Digest: "外链摘要",
Path: "file/lake.jpg",
//MediaId: imgId,
}
err = demo.SendExlinkMsg(_User, []*Exlink{link})
if err != nil {
t.Error(err)
return
}
t.Log("Send exlink msg success.")
_, _, err = demo.SearchFile(fileId)
if err != nil {
t.Error("File not exist")
}
t.Log("Search file success.")
}