client.go
2.0 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
package k3cloud
import (
"errors"
"io"
)
//初始化默认的客户端
type Client struct {
HttpClient
}
/*NewClient 新建客户端,
默认执行登录操作,填充cookie
*/
func NewClient(apihost string, acctID string, username string, password string, lcid ...int) (*Client, error) {
client := &Client{
HttpClient{
HostUrl: apihost,
},
}
_, err := client.Login(acctID, username, password, lcid...)
if err != nil {
return nil, err
}
return client, nil
}
/*
Login 登陆验证接口
acctID 账套Id,
username 密码
password 用户登陆名
lcid 语言id,选择哪种语言访问,参考:中文2052,英文1033,繁体307
*/
func (c *Client) Login(acctID string, username string, password string, lcid ...int) (*ReponseValidateUser, error) {
api := "/Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser.common.kdsvc"
lcidTemp := 2052
if len(lcid) > 0 {
lcidTemp = lcid[0]
}
param := []interface{}{acctID, username, password, lcidTemp}
resp, err := c.PostRequest(api, param)
if err != nil {
return nil, err
}
defer resp.Body.Close()
cookies := resp.Cookies()
//填充调用接口时需要的cookie
c.HttpClient.Cookie = cookies
var loginReturn ReponseValidateUser
err = c.DecodeJSON(resp.Body, &loginReturn)
if err != nil {
return nil, err
}
if loginReturn.LoginResultType != 1 {
return &loginReturn, errors.New(loginReturn.Message)
}
return &loginReturn, nil
}
// ExecuteBillQuery 单据查询
func (c *Client) ExecuteBillQuery(param RequestExecuteBillQuery) (*BillQueryResult, error) {
api := "/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery.common.kdsvc"
paramFomat := []interface{}{param}
resp, err := c.PostRequest(api, paramFomat)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var dataByte []byte
dataByte, err = io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
queryResult := newBillQueryResult(dataByte, param.FieldKeys)
return queryResult, queryResult.Error()
}
//QueryGroupInfo 分组信息查询
func (c *Client) QueryGroupInfo() {
}