forked from shenghui0779/sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
draft.go
156 lines (132 loc) · 3.77 KB
/
draft.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 offia
import (
"encoding/json"
"github.com/liniu/gochat/urls"
"github.com/liniu/gochat/wx"
)
type DraftArticle struct {
Title string `json:"title"`
Author string `json:"author,omitempty"`
Digest string `json:"digest,omitempty"`
Content string `json:"content"`
ContentSourceURL string `json:"content_source_url,omitempty"`
ThumbMediaID string `json:"thumb_media_id"`
ShowCoverPic int `json:"show_cover_pic,omitempty"`
NeedOpenComment int `json:"need_open_comment,omitempty"`
OnlyFansCanComment int `json:"only_fans_can_comment,omitempty"`
URL string `json:"url,omitempty"`
}
type ParamsDraftAdd struct {
Articles []*DraftArticle `json:"articles"`
}
type ResultDraftAdd struct {
MediaID string `json:"media_id"`
}
// AddDraft 草稿箱 - 新建草稿
func AddDraft(params *ParamsDraftAdd, result *ResultDraftAdd) wx.Action {
return wx.NewPostAction(urls.OffiaDraftAdd,
wx.WithBody(func() ([]byte, error) {
return wx.MarshalNoEscapeHTML(params)
}),
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}
type ParamsDraftUpdate struct {
MediaID string `json:"media_id"`
Index int `json:"index"`
Articles *DraftArticle `json:"articles"`
}
// UpdateDraft 草稿箱 - 修改草稿
func UpdateDraft(mediaID string, index int, article *DraftArticle) wx.Action {
params := &ParamsDraftUpdate{
MediaID: mediaID,
Index: index,
Articles: article,
}
return wx.NewPostAction(urls.OffiaDraftUpdate,
wx.WithBody(func() ([]byte, error) {
return wx.MarshalNoEscapeHTML(params)
}),
)
}
type ParamsDraftGet struct {
MediaID string `json:"media_id"`
}
type ResultDraftGet struct {
NewsItem []*DraftArticle `json:"news_item"`
}
// GetDraft 草稿箱 - 获取草稿
func GetDraft(mediaID string, result *ResultDraftGet) wx.Action {
params := &ParamsDraftGet{
MediaID: mediaID,
}
return wx.NewPostAction(urls.OffiaDraftGet,
wx.WithBody(func() ([]byte, error) {
return wx.MarshalNoEscapeHTML(params)
}),
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}
type ParamsDraftDelete struct {
MediaID string `json:"media_id"`
}
// DeleteDraft 草稿箱 - 删除草稿
func DeleteDraft(mediaID string) wx.Action {
params := &ParamsDraftDelete{
MediaID: mediaID,
}
return wx.NewPostAction(urls.OffiaDraftDelete,
wx.WithBody(func() ([]byte, error) {
return wx.MarshalNoEscapeHTML(params)
}),
)
}
type ResultDraftCount struct {
TotalCount int `json:"total_count"`
}
// GetDraftCount 草稿箱 - 获取草稿总数
func GetDraftCount(result *ResultDraftCount) wx.Action {
return wx.NewGetAction(urls.OffiaDraftCount,
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}
type ParamsDraftBatchGet struct {
Offset int `json:"offset"`
Count int `json:"count"`
NoContent int `json:"no_content,omitempty"`
}
type ResultDraftBatchGet struct {
TotalCount int `json:"total_count"`
ItemCount int `json:"item_count"`
Item []*DraftDetail `json:"item"`
}
type DraftDetail struct {
ArticleID string `json:"article_id"`
Content *DraftContent `json:"content"`
UpdateTime int64 `json:"update_time"`
}
type DraftContent struct {
NewsItem []*DraftArticle `json:"news_item"`
}
// BatchGetDraft 草稿箱 - 获取草稿列表
func BatchGetDraft(offset, count, nocontent int, result *ResultDraftBatchGet) wx.Action {
params := &ParamsDraftBatchGet{
Offset: offset,
Count: count,
NoContent: nocontent,
}
return wx.NewPostAction(urls.OffiaDraftBatchGet,
wx.WithBody(func() ([]byte, error) {
return wx.MarshalNoEscapeHTML(params)
}),
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}