forked from baidu/smartapp-openapi-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getCommentList.go
89 lines (78 loc) · 3.3 KB
/
getCommentList.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
package openapi
import (
"fmt"
)
// GetCommentListRequest 请求结构体
type GetCommentListRequest struct {
AccessToken string // 接口调用凭证
HostName string // 宿主名称
Snid string // 文章的 ID
SnidType string // 无 snid_type 的开发者请默认传空串
Start int64 // 评论的开始偏移量,默认0
Num int64 // 获取的评论条数,默认10
}
// 响应结构体
type GetCommentListResponsedatalistItemreplyListItem struct {
Content string `json:"content"` // 回复内容
CreateTime string `json:"create_time"` // 发表时间
IsUped string `json:"is_uped"` // 点赞状态 1:已点赞 0:未点赞
LikeCount string `json:"like_count"` // 点赞数
}
type GetCommentListResponsedatalistItem struct {
Content string `json:"content"` // 评论内容
CreateTime string `json:"create_time"` // 发表时间
IsUped string `json:"is_uped"` // 点赞状态 1:已点赞 0:未点赞
LikeCount string `json:"like_count"` // 点赞数
ReplyList []GetCommentListResponsedatalistItemreplyListItem `json:"reply_list"` // 回复列表
Srid string `json:"srid"` // 评论ID
ThreadID string `json:"thread_id"` // 主题ID
}
type GetCommentListResponsedata struct {
List []GetCommentListResponsedatalistItem `json:"list"` // 评论列表
}
type GetCommentListResponse struct {
Data GetCommentListResponsedata `json:"data"` // 响应对象
Errno int64 `json:"errno"` // 错误码
ErrMsg string `json:"msg"` // 错误信息
RequestID string `json:"request_id"` // 请求 ID,标识一次请求
ErrorCode int64 `json:"error_code"` // openapi 错误码
ErrorMsg string `json:"error_msg"` // openapi 错误信息
}
// GetCommentList
func GetCommentList(params *GetCommentListRequest) (*GetCommentListResponsedata, error) {
var (
err error
defaultRet *GetCommentListResponsedata
)
respData := &GetCommentListResponse{}
client := NewHTTPClient().
SetContentType(ContentTypeForm).
SetConverterType(ConverterTypeJSON).
SetMethod("POST").
SetScheme(SCHEME).
SetHost(OPENAPIHOST).
SetPath("/rest/2.0/smartapp/ma/component/comment/open_list")
client.AddGetParam("access_token", params.AccessToken)
client.AddGetParam("host_name", params.HostName)
client.AddGetParam("sp_sdk_ver", SDKVERSION)
client.AddGetParam("sp_sdk_lang", SDKLANG)
client.AddPostParam("snid", params.Snid)
client.AddPostParam("snid_type", params.SnidType)
client.AddPostParam("start", fmt.Sprintf("%v", params.Start))
client.AddPostParam("num", fmt.Sprintf("%v", params.Num))
err = client.Do()
if err != nil {
return defaultRet, err
}
err = client.Convert(respData)
if err != nil {
return defaultRet, err
}
if respData.ErrorCode != 0 {
return defaultRet, &OpenAPIError{respData.ErrorCode, respData.ErrorMsg, respData}
}
if respData.Errno != 0 {
return defaultRet, &APIError{respData.Errno, respData.ErrMsg, respData}
}
return &respData.Data, nil
}