-
Notifications
You must be signed in to change notification settings - Fork 5
/
openapi_v2_files.go
78 lines (68 loc) · 2.12 KB
/
openapi_v2_files.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
package nano
import (
"strconv"
"strings"
"github.com/sirupsen/logrus"
)
// FileType 媒体类型
type FileType int
const (
FileTypeImage = iota + 1 // png/jpg
FileTypeVideo // mp4
FileTypeAudio // silk
FileTypeFile // 暂不开放
)
func (ft FileType) String() string {
switch ft {
case FileTypeImage:
return "图片"
case FileTypeVideo:
return "视频"
case FileTypeAudio:
return "语音"
case FileTypeFile:
return "文件"
default:
return "未知类型" + strconv.Itoa(int(ft))
}
}
// FilePost QQ 富媒体消息发送请求参数
//
// https://bot.q.qq.com/wiki/develop/api-231017/server-inter/message/send-receive/rich-text-media.html
type FilePost struct {
Type FileType `json:"file_type"`
URL string `json:"url"`
IsPositive bool `json:"srv_send_msg"` // IsPositive
// file_data 否 【暂未支持】
}
func (fp *FilePost) String() string {
sb := strings.Builder{}
sb.WriteString("[v2.")
sb.WriteString(fp.Type.String())
sb.WriteString("]")
if fp.URL == "" {
sb.WriteString("无链接")
} else {
sb.WriteString("链接: ")
sb.WriteString(fp.URL)
}
return sb.String()
}
// PostFileToQQUser 发送文件到 QQ 用户的 openid
//
// https://bot.q.qq.com/wiki/develop/api-231017/server-inter/message/send-receive/rich-text-media.html#%E5%8F%91%E9%80%81%E5%88%B0%E5%8D%95%E8%81%8A
func (bot *Bot) PostFileToQQUser(id string, content *FilePost) (*Message, error) {
logrus.Infoln(getLogHeader(), "<= [Q]单:", id+",", content)
return bot.postOpenAPIofMessage("/v2/users/"+id+"/files", "", WriteBodyFromJSON(content))
}
// PostFileToQQGroup 发送文件到 QQ 群的 openid
//
// https://bot.q.qq.com/wiki/develop/api-231017/server-inter/message/send-receive/rich-text-media.html#%E5%8F%91%E9%80%81%E5%88%B0%E7%BE%A4%E8%81%8A
func (bot *Bot) PostFileToQQGroup(id string, content *FilePost) (*Message, error) {
logrus.Infoln(getLogHeader(), "<= [Q]群:", id+",", content)
return bot.postOpenAPIofMessage("/v2/groups/"+id+"/files", "", WriteBodyFromJSON(content))
}
// MessageMedia used in MessagePost
type MessageMedia struct {
FileInfo string `json:"file_info"`
}