正在显示
5 个修改的文件
包含
45 行增加
和
52 行删除
| @@ -3,6 +3,9 @@ package k3cloud | @@ -3,6 +3,9 @@ package k3cloud | ||
| 3 | import ( | 3 | import ( |
| 4 | "errors" | 4 | "errors" |
| 5 | "io" | 5 | "io" |
| 6 | + "time" | ||
| 7 | + | ||
| 8 | + "github.com/google/uuid" | ||
| 6 | ) | 9 | ) |
| 7 | 10 | ||
| 8 | //初始化默认的客户端 | 11 | //初始化默认的客户端 |
| @@ -41,7 +44,14 @@ func (c *Client) Login(acctID string, username string, password string, lcid ... | @@ -41,7 +44,14 @@ func (c *Client) Login(acctID string, username string, password string, lcid ... | ||
| 41 | if len(lcid) > 0 { | 44 | if len(lcid) > 0 { |
| 42 | lcidTemp = lcid[0] | 45 | lcidTemp = lcid[0] |
| 43 | } | 46 | } |
| 44 | - param := []interface{}{acctID, username, password, lcidTemp} | 47 | + param := RequestValidateUser{ |
| 48 | + Format: 1, | ||
| 49 | + Useragent: "ApiClient", | ||
| 50 | + Rid: uuid.NewString(), | ||
| 51 | + Timestamp: time.Now().Format("2006-01-02"), | ||
| 52 | + V: "1.0", | ||
| 53 | + Parameters: []interface{}{acctID, username, password, lcidTemp}, | ||
| 54 | + } | ||
| 45 | resp, err := c.PostRequest(api, param) | 55 | resp, err := c.PostRequest(api, param) |
| 46 | if err != nil { | 56 | if err != nil { |
| 47 | return nil, err | 57 | return nil, err |
| @@ -64,8 +74,7 @@ func (c *Client) Login(acctID string, username string, password string, lcid ... | @@ -64,8 +74,7 @@ func (c *Client) Login(acctID string, username string, password string, lcid ... | ||
| 64 | // ExecuteBillQuery 单据查询 | 74 | // ExecuteBillQuery 单据查询 |
| 65 | func (c *Client) ExecuteBillQuery(param RequestExecuteBillQuery) (*BillQueryResult, error) { | 75 | func (c *Client) ExecuteBillQuery(param RequestExecuteBillQuery) (*BillQueryResult, error) { |
| 66 | api := "/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery.common.kdsvc" | 76 | api := "/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery.common.kdsvc" |
| 67 | - paramFomat := []interface{}{param} | ||
| 68 | - resp, err := c.PostRequest(api, paramFomat) | 77 | + resp, err := c.PostRequest(api, param) |
| 69 | if err != nil { | 78 | if err != nil { |
| 70 | return nil, err | 79 | return nil, err |
| 71 | } | 80 | } |
| @@ -75,11 +84,6 @@ func (c *Client) ExecuteBillQuery(param RequestExecuteBillQuery) (*BillQueryResu | @@ -75,11 +84,6 @@ func (c *Client) ExecuteBillQuery(param RequestExecuteBillQuery) (*BillQueryResu | ||
| 75 | if err != nil { | 84 | if err != nil { |
| 76 | return nil, err | 85 | return nil, err |
| 77 | } | 86 | } |
| 78 | - queryResult := newBillQueryResult(dataByte, param.FieldKeys) | 87 | + queryResult := newBillQueryResult(dataByte, param.Data.FieldKeys) |
| 79 | return queryResult, queryResult.Error() | 88 | return queryResult, queryResult.Error() |
| 80 | } | 89 | } |
| 81 | - | ||
| 82 | -//QueryGroupInfo 分组信息查询 | ||
| 83 | -func (c *Client) QueryGroupInfo() { | ||
| 84 | - | ||
| 85 | -} |
| @@ -35,14 +35,18 @@ func TestExecuteBillQuery(t *testing.T) { | @@ -35,14 +35,18 @@ func TestExecuteBillQuery(t *testing.T) { | ||
| 35 | // {"FIsSalseByNet", "是否网销"}, {"FIsAutoAllocate", "自动分配"}, {"FSPUID", "SPU信息"}, {"FPinYin", "拼音"}, {"FDSMatchByLot", "按批号匹配供需"}, | 35 | // {"FIsSalseByNet", "是否网销"}, {"FIsAutoAllocate", "自动分配"}, {"FSPUID", "SPU信息"}, {"FPinYin", "拼音"}, {"FDSMatchByLot", "按批号匹配供需"}, |
| 36 | // {"FForbidReson", "禁用原因"}, {"FRefStatus", "已使用"}} | 36 | // {"FForbidReson", "禁用原因"}, {"FRefStatus", "已使用"}} |
| 37 | result, err := client.ExecuteBillQuery(RequestExecuteBillQuery{ | 37 | result, err := client.ExecuteBillQuery(RequestExecuteBillQuery{ |
| 38 | - FormId: "BD_MATERIAL", //物料 | ||
| 39 | - FieldKeys: "FMATERIALID,FDocumentStatus,FName,FNumber,FModifyDate,FBaseUnitId.FName,FUseOrgId.FName,FMaterialGroup.FName", //查询的字段 | ||
| 40 | - TopRowCount: 5, | 38 | + FormId: "BD_MATERIAL", |
| 39 | + Data: ExecuteBillQueryData{ | ||
| 40 | + FormId: "BD_MATERIAL", | ||
| 41 | + FieldKeys: "FMATERIALID,FDocumentStatus,FName,FNumber,FModifyDate,FBaseUnitId.FName,FUseOrgId.FName,FMaterialGroup.FNumber", //查询的字段 | ||
| 42 | + TopRowCount: 5, | ||
| 43 | + FilterString: `FMaterialGroup.FNumber like '05%' and FModifyDate<'2022-01-08T19:36:06'`, | ||
| 44 | + }, | ||
| 41 | }) | 45 | }) |
| 42 | t.Logf("result buf===> %s \n", string(result.Buf)) | 46 | t.Logf("result buf===> %s \n", string(result.Buf)) |
| 43 | if err != nil { | 47 | if err != nil { |
| 44 | t.Error(err) | 48 | t.Error(err) |
| 45 | return | 49 | return |
| 46 | } | 50 | } |
| 47 | - t.Logf("tomap===>%v \n", result.ToMapString()) | 51 | + // t.Logf("tomap===>%v \n", result.ToMapString()) |
| 48 | } | 52 | } |
| @@ -7,8 +7,6 @@ import ( | @@ -7,8 +7,6 @@ import ( | ||
| 7 | "io" | 7 | "io" |
| 8 | "net/http" | 8 | "net/http" |
| 9 | "time" | 9 | "time" |
| 10 | - | ||
| 11 | - "github.com/google/uuid" | ||
| 12 | ) | 10 | ) |
| 13 | 11 | ||
| 14 | //全局使用的http请求 | 12 | //全局使用的http请求 |
| @@ -17,24 +15,9 @@ type HttpClient struct { | @@ -17,24 +15,9 @@ type HttpClient struct { | ||
| 17 | Cookie []*http.Cookie | 15 | Cookie []*http.Cookie |
| 18 | } | 16 | } |
| 19 | 17 | ||
| 20 | -//WrapPostData 包装发送的数据 | ||
| 21 | -func (hClient *HttpClient) WrapPostData(param interface{}) (*postData, error) { | ||
| 22 | - data := postData{ | ||
| 23 | - Format: 1, | ||
| 24 | - Useragent: "ApiClient", | ||
| 25 | - Rid: uuid.NewString(), | ||
| 26 | - Timestamp: time.Now().Format("2006-01-02"), | ||
| 27 | - V: "1.0", | ||
| 28 | - Parameters: param, | ||
| 29 | - } | ||
| 30 | - return &data, nil | ||
| 31 | -} | ||
| 32 | - | ||
| 33 | func (hClient *HttpClient) PostRequest(api string, param interface{}) (*http.Response, error) { | 18 | func (hClient *HttpClient) PostRequest(api string, param interface{}) (*http.Response, error) { |
| 34 | - data, err := hClient.WrapPostData(param) | ||
| 35 | - if err != nil { | ||
| 36 | - return nil, err | ||
| 37 | - } | 19 | + var err error |
| 20 | + data := param | ||
| 38 | url := fmt.Sprintf("%s%s", hClient.HostUrl, api) | 21 | url := fmt.Sprintf("%s%s", hClient.HostUrl, api) |
| 39 | var buf bytes.Buffer | 22 | var buf bytes.Buffer |
| 40 | encoder := json.NewEncoder(&buf) | 23 | encoder := json.NewEncoder(&buf) |
| @@ -92,8 +92,7 @@ func (result *BillQueryResult) ToMap() []map[string]interface{} { | @@ -92,8 +92,7 @@ func (result *BillQueryResult) ToMap() []map[string]interface{} { | ||
| 92 | 92 | ||
| 93 | func (result *BillQueryResult) Error() error { | 93 | func (result *BillQueryResult) Error() error { |
| 94 | var ( | 94 | var ( |
| 95 | - errMsg QueryError | ||
| 96 | - err error | 95 | + err error |
| 97 | ) | 96 | ) |
| 98 | jResult := gjson.ParseBytes(result.Buf) | 97 | jResult := gjson.ParseBytes(result.Buf) |
| 99 | for _, arr1 := range jResult.Array() { | 98 | for _, arr1 := range jResult.Array() { |
| @@ -101,13 +100,15 @@ func (result *BillQueryResult) Error() error { | @@ -101,13 +100,15 @@ func (result *BillQueryResult) Error() error { | ||
| 101 | if !item.IsObject() { | 100 | if !item.IsObject() { |
| 102 | return nil | 101 | return nil |
| 103 | } | 102 | } |
| 103 | + var errMsg QueryError | ||
| 104 | err = json.Unmarshal([]byte(item.Raw), &errMsg) | 104 | err = json.Unmarshal([]byte(item.Raw), &errMsg) |
| 105 | if err != nil { | 105 | if err != nil { |
| 106 | return err | 106 | return err |
| 107 | } | 107 | } |
| 108 | + err = errMsg | ||
| 108 | } | 109 | } |
| 109 | } | 110 | } |
| 110 | - return errMsg | 111 | + return err |
| 111 | } | 112 | } |
| 112 | 113 | ||
| 113 | //TODO 将结果解析为结构体 | 114 | //TODO 将结果解析为结构体 |
| 1 | package k3cloud | 1 | package k3cloud |
| 2 | 2 | ||
| 3 | -//postData 请求接口发送的数据结构 | ||
| 4 | -type postData struct { | ||
| 5 | - Format int `json:"format"` | ||
| 6 | - Useragent string `json:"useragent"` | ||
| 7 | - Rid string `json:"rid"` | ||
| 8 | - Parameters interface{} `json:"parameters"` | ||
| 9 | - Timestamp string `json:"timestamp"` | ||
| 10 | - V string `json:"v"` | ||
| 11 | -} | ||
| 12 | - | ||
| 13 | //登录验证请求数据结构 /Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser.common.kdsvc | 3 | //登录验证请求数据结构 /Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser.common.kdsvc |
| 14 | type ( | 4 | type ( |
| 15 | - // RequestValidateUser struct { | ||
| 16 | - // AcctID string `json:"acctID"` //账套Id, | ||
| 17 | - // Username string `json:"username"` //密码 | ||
| 18 | - // Password string `json:"password"` //用户登陆名 | ||
| 19 | - // Lcid int `json:"lcid"` //语言id,选择哪种语言访问,参考:中文2052,英文1033,繁体307 | ||
| 20 | - // } | 5 | + // AcctID string `json:"acctID"` //账套Id, |
| 6 | + // Username string `json:"username"` //密码 | ||
| 7 | + // Password string `json:"password"` //用户登陆名 | ||
| 8 | + // Lcid int `json:"lcid"` //语言id,选择哪种语言访问,参考:中文2052,英文1033,繁体307 | ||
| 9 | + RequestValidateUser struct { | ||
| 10 | + Format int `json:"format"` | ||
| 11 | + Useragent string `json:"useragent"` | ||
| 12 | + Rid string `json:"rid"` | ||
| 13 | + Timestamp string `json:"timestamp"` | ||
| 14 | + V string `json:"v"` | ||
| 15 | + Parameters []interface{} `json:"parameters"` | ||
| 16 | + } | ||
| 21 | 17 | ||
| 22 | ReponseValidateUser struct { | 18 | ReponseValidateUser struct { |
| 23 | 19 | ||
| @@ -39,8 +35,9 @@ type ( | @@ -39,8 +35,9 @@ type ( | ||
| 39 | ) | 35 | ) |
| 40 | 36 | ||
| 41 | //表单数据查询 /K3Cloud/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery.common.kdsvc | 37 | //表单数据查询 /K3Cloud/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery.common.kdsvc |
| 38 | +//数据请求结构 | ||
| 42 | type ( | 39 | type ( |
| 43 | - RequestExecuteBillQuery struct { | 40 | + ExecuteBillQueryData struct { |
| 44 | FormId string `json:"FormId"` //必录,查询表单元数据唯一标识 | 41 | FormId string `json:"FormId"` //必录,查询表单元数据唯一标识 |
| 45 | FieldKeys string `json:"FieldKeys"` //必录,待查询表单的字段列表 | 42 | FieldKeys string `json:"FieldKeys"` //必录,待查询表单的字段列表 |
| 46 | Limit int `json:"Limit"` //非必录,分页取数每页允许获取的数据,最大不能超过2000 | 43 | Limit int `json:"Limit"` //非必录,分页取数每页允许获取的数据,最大不能超过2000 |
| @@ -49,4 +46,8 @@ type ( | @@ -49,4 +46,8 @@ type ( | ||
| 49 | OrderString string `json:"OrderString"` //非必录,排序条件 | 46 | OrderString string `json:"OrderString"` //非必录,排序条件 |
| 50 | TopRowCount int `json:"TopRowCount"` //非必录,返回总行数 | 47 | TopRowCount int `json:"TopRowCount"` //非必录,返回总行数 |
| 51 | } | 48 | } |
| 49 | + RequestExecuteBillQuery struct { | ||
| 50 | + FormId string `json:"FormId"` //必录,查询表单元数据唯一标识 | ||
| 51 | + Data ExecuteBillQueryData `json:"data"` | ||
| 52 | + } | ||
| 52 | ) | 53 | ) |
-
请 注册 或 登录 后发表评论