/
wxa.business.getliveinfo.go
71 lines (66 loc) · 2.73 KB
/
wxa.business.getliveinfo.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
package wechatminiprogram
import (
"context"
"fmt"
"go.dtapp.net/gojson"
"go.dtapp.net/gorequest"
"net/http"
)
type BusinessGetLiveInfoResponse struct {
Errcode int `json:"errcode"` // // 错误码,0代表成功,1代表未创建直播间
Errmsg string `json:"errmsg"` // 错误信息
Total int `json:"total"`
RoomInfo []struct {
Name string `json:"name"` // 直播间名称
Roomid int `json:"roomid"` // 直播间ID
CoverImg string `json:"cover_img"`
ShareImg string `json:"share_img"`
LiveStatus int `json:"live_status"`
StartTime int `json:"start_time"`
EndTime int `json:"end_time"`
AnchorName string `json:"anchor_name"`
Goods []struct {
CoverImg string `json:"cover_img"`
Url string `json:"url"`
Name string `json:"name"`
Price int `json:"price"`
Price2 int `json:"price2"`
PriceType int `json:"price_type"`
GoodsId int `json:"goods_id"`
ThirdPartyAppid string `json:"third_party_appid"`
} `json:"goods"`
LiveType int `json:"live_type"`
CloseLike int `json:"close_like"`
CloseGoods int `json:"close_goods"`
CloseComment int `json:"close_comment"`
CloseKf int `json:"close_kf"`
CloseReplay int `json:"close_replay"`
IsFeedsPublic int `json:"is_feeds_public"`
CreaterOpenid string `json:"creater_openid"`
FeedsImg string `json:"feeds_img"`
} `json:"room_info"`
}
type BusinessGetLiveInfoResult struct {
Result BusinessGetLiveInfoResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
}
func newBusinessGetLiveInfoResult(result BusinessGetLiveInfoResponse, body []byte, http gorequest.Response) *BusinessGetLiveInfoResult {
return &BusinessGetLiveInfoResult{Result: result, Body: body, Http: http}
}
// BusinessGetLiveInfo 获取直播间列表
// 调用此接口获取直播间列表及直播间信息
// https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/liveplayer/studio-api.html
func (c *Client) BusinessGetLiveInfo(ctx context.Context, notMustParams ...gorequest.Params) (*BusinessGetLiveInfoResult, error) {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/wxa/business/getliveinfo?access_token=%s", c.getAccessToken(ctx)), params, http.MethodPost)
if err != nil {
return newBusinessGetLiveInfoResult(BusinessGetLiveInfoResponse{}, request.ResponseBody, request), err
}
// 定义
var response BusinessGetLiveInfoResponse
err = gojson.Unmarshal(request.ResponseBody, &response)
return newBusinessGetLiveInfoResult(response, request.ResponseBody, request), err
}