forked from shenghui0779/sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish.go
169 lines (143 loc) · 4.5 KB
/
publish.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
157
158
159
160
161
162
163
164
165
166
167
168
169
package offia
import (
"encoding/json"
"github.com/liniu/gochat/urls"
"github.com/liniu/gochat/wx"
)
type ParamsPublishSubmit struct {
MediaID string `json:"media_id"`
}
type ResultPublishSubmit struct {
PublishID string `json:"publish_id"`
}
// SubmitPublish 发布能力 - 发布图文
// 开发者需要先将图文素材以草稿的形式保存(见“草稿箱/新建草稿”,如需从已保存的草稿中选择,见“草稿箱/获取草稿列表”),选择要发布的草稿 media_id 进行发布
func SubmitPublish(mediaID string, result *ResultPublishSubmit) wx.Action {
params := &ParamsPublishSubmit{
MediaID: mediaID,
}
return wx.NewPostAction(urls.OffiaPublishSubmit,
wx.WithBody(func() ([]byte, error) {
return wx.MarshalNoEscapeHTML(params)
}),
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}
type ParamsPublishGet struct {
PublishID string `json:"publish_id"`
}
type ResultPublishGet struct {
PublishID string `json:"publish_id"`
PublishStatus int `json:"publish_status"`
ArticleID string `json:"article_id"`
ArticleDetail *PublishArticles `json:"article_detail"`
FailIDX []int `json:"fail_idx"`
}
type PublishArticles struct {
Count int `json:"count"`
Item []*PublishItem `json:"item"`
}
type PublishItem struct {
IDX int `json:"idx"`
ArticleURL string `json:"article_url"`
}
// GetPublish 发布能力 - 发布状态轮询
// 开发者可以尝试通过下面的发布状态轮询接口获知发布情况。
func GetPublish(publishID string, result *ResultPublishGet) wx.Action {
params := &ParamsPublishGet{
PublishID: publishID,
}
return wx.NewPostAction(urls.OffiaPublishGet,
wx.WithBody(func() ([]byte, error) {
return wx.MarshalNoEscapeHTML(params)
}),
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}
type ParamsPublishDelete struct {
ArticleID string `json:"article_id"`
Index int `json:"index"`
}
// DeletePublish 发布能力 - 删除发布
func DeletePublish(articleID string, index int) wx.Action {
params := &ParamsPublishDelete{
ArticleID: articleID,
Index: index,
}
return wx.NewPostAction(urls.OffiaPublishDelete,
wx.WithBody(func() ([]byte, error) {
return wx.MarshalNoEscapeHTML(params)
}),
)
}
type ParamsPublishArticle struct {
ArticleID string `json:"article_id"`
}
type ResultPublishArticle struct {
NewsItem []*PublishArticle `json:"news_item"`
}
type PublishArticle struct {
Title string `json:"title"`
Author string `json:"author"`
Digest string `json:"digest"`
Content string `json:"content"`
ContentSourceURL string `json:"content_source_url"`
ThumbMediaID string `json:"thumb_media_id"`
ShowCoverPic int `json:"show_cover_pic"`
NeedOpenComment int `json:"need_open_comment"`
OnlyFansCanComment int `json:"only_fans_can_comment"`
URL string `json:"url"`
IsDelete bool `json:"is_delete"`
}
// GetPublishArticle 发布能力 - 通过 article_id 获取已发布文章
func GetPublishArticle(articleID string, result *ResultPublishArticle) wx.Action {
params := &ParamsPublishArticle{
ArticleID: articleID,
}
return wx.NewPostAction(urls.OffiaPublishGetArticle,
wx.WithBody(func() ([]byte, error) {
return wx.MarshalNoEscapeHTML(params)
}),
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}
type ParamsPublishBatchGet struct {
Offset int `json:"offset"`
Count int `json:"count"`
NoContent int `json:"no_content,omitempty"`
}
type ResultPublishBatchGet struct {
TotalCount int `json:"total_count"`
ItemCount int `json:"item_count"`
Item []*PublishDetail `json:"item"`
}
type PublishDetail struct {
ArticleID string `json:"article_id"`
Content *PublishContent `json:"content"`
UpdateTime int64 `json:"update_time"`
}
type PublishContent struct {
NewsItem []*PublishArticle `json:"news_item"`
}
// BatchGetPublish 发布能力 - 获取成功发布列表
func BatchGetPublish(offset, count, nocontent int, result *ResultPublishBatchGet) wx.Action {
params := &ParamsPublishBatchGet{
Offset: offset,
Count: count,
NoContent: nocontent,
}
return wx.NewPostAction(urls.OffiaPublishBatchGet,
wx.WithBody(func() ([]byte, error) {
return wx.MarshalNoEscapeHTML(params)
}),
wx.WithDecode(func(b []byte) error {
return json.Unmarshal(b, result)
}),
)
}