-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccount.api.go
More file actions
125 lines (107 loc) · 3.08 KB
/
account.api.go
File metadata and controls
125 lines (107 loc) · 3.08 KB
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
// Code generated by protoc-gen-go_api(github.com/dev-openapi/protoc-gen-go_api version=v1.0.2). DO NOT EDIT.
// source: douyin-webapp/account.proto
package douyin_webapp
import (
context "context"
fmt "fmt"
io "io"
json "encoding/json"
bytes "bytes"
http "net/http"
strings "strings"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = context.Background
var _ = http.NewRequest
var _ = io.Copy
var _ = bytes.Compare
var _ = json.Marshal
var _ = strings.Compare
var _ = fmt.Errorf
// Client API for Account service
type AccountService interface {
// GetUserInfo 获取用户公开信息 https://developer.open-douyin.com/docs/resource/zh-CN/dop/develop/openapi/account-management/get-account-open-info
GetUserInfo(ctx context.Context, in *GetUserInfoReq, opts ...Option) (*GetUserInfoRes, error)
// FansCheck 粉丝判断 https://developer.open-douyin.com/docs/resource/zh-CN/dop/develop/openapi/account-management/fans-judge
FansCheck(ctx context.Context, in *FansCheckReq, opts ...Option) (*FansCheckRes, error)
}
type accountService struct {
// opts
opts *Options
}
func NewAccountService(opts ...Option) AccountService {
opt := newOptions(opts...)
if len(opt.addr) <= 0 {
opt.addr = "https://open.douyin.com"
}
return &accountService {
opts: opt,
}
}
func (c *accountService) GetUserInfo(ctx context.Context, in *GetUserInfoReq, opts ...Option) (*GetUserInfoRes, error) {
var res GetUserInfoRes
// options
opt := buildOptions(c.opts, opts...)
headers := make(map[string]string)
// route
rawURL := fmt.Sprintf("%s/oauth/userinfo", opt.addr)
// body
var body io.Reader
bodyForms := make(map[string]string)
if in.GetAccessToken() != "" {
bodyForms["access_token"] = fmt.Sprintf("%v", in.GetAccessToken())
}
if in.GetOpenId() != "" {
bodyForms["open_id"] = fmt.Sprintf("%v", in.GetOpenId())
}
var bs []string
for k, v := range bodyForms {
bs = append(bs, fmt.Sprintf("%s=%s", k, v))
}
body = strings.NewReader(strings.Join(bs, "&"))
headers["Content-Type"] = "application/x-www-form-urlencoded"
req, err := http.NewRequest("POST", rawURL, body)
if err != nil {
return nil, err
}
// header
for k, v := range headers {
req.Header.Set(k, v)
}
resp, err := opt.DoRequest(ctx, opt.client, req)
if err != nil {
return nil, err
}
err = opt.DoResponse(ctx, resp, &res)
return &res, err
}
func (c *accountService) FansCheck(ctx context.Context, in *FansCheckReq, opts ...Option) (*FansCheckRes, error) {
var res FansCheckRes
// options
opt := buildOptions(c.opts, opts...)
headers := make(map[string]string)
// route
rawURL := fmt.Sprintf("%s/fans/check", opt.addr)
// body
var body io.Reader
bs, err := json.Marshal(in)
if err != nil {
return nil, err
}
body = bytes.NewReader(bs)
headers["Content-Type"] = "application/json"
req, err := http.NewRequest("POST", rawURL, body)
if err != nil {
return nil, err
}
// header
for k, v := range headers {
req.Header.Set(k, v)
}
resp, err := opt.DoRequest(ctx, opt.client, req)
if err != nil {
return nil, err
}
err = opt.DoResponse(ctx, resp, &res)
return &res, err
}