forked from baidu/smartapp-openapi-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getCommentCount.go
63 lines (54 loc) · 1.98 KB
/
getCommentCount.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
package openapi
// GetCommentCountRequest 请求结构体
type GetCommentCountRequest struct {
AccessToken string // 接口调用凭证
Snid string // 文章的 ID
SnidType string // 无 snid_type 的开发者请默认传空串
}
// 响应结构体
type GetCommentCountResponsedata struct {
CommentCount string `json:"comment_count"` // 评论数
}
type GetCommentCountResponse struct {
Data GetCommentCountResponsedata `json:"data"` // 互动评论数详细结果
Errno int64 `json:"errno"` // 错误码,正常返回情况下,errno 值为 0
ErrMsg string `json:"msg"` // 错误信息
RequestID string `json:"request_id"` // 请求 ID,标识一次请求
ErrorCode int64 `json:"error_code"` // openapi 错误码
ErrorMsg string `json:"error_msg"` // openapi 错误信息
}
// GetCommentCount
func GetCommentCount(params *GetCommentCountRequest) (*GetCommentCountResponsedata, error) {
var (
err error
defaultRet *GetCommentCountResponsedata
)
respData := &GetCommentCountResponse{}
client := NewHTTPClient().
SetContentType(ContentTypeForm).
SetConverterType(ConverterTypeJSON).
SetMethod("POST").
SetScheme(SCHEME).
SetHost(OPENAPIHOST).
SetPath("/rest/2.0/smartapp/ma/component/comment/tcount")
client.AddGetParam("access_token", params.AccessToken)
client.AddGetParam("sp_sdk_ver", SDKVERSION)
client.AddGetParam("sp_sdk_lang", SDKLANG)
client.AddPostParam("snid", params.Snid)
client.AddPostParam("snid_type", params.SnidType)
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
}