作者 tangxuhui

更新请求参数处理

... ... @@ -3,6 +3,9 @@ package k3cloud
import (
"errors"
"io"
"time"
"github.com/google/uuid"
)
//初始化默认的客户端
... ... @@ -41,7 +44,14 @@ func (c *Client) Login(acctID string, username string, password string, lcid ...
if len(lcid) > 0 {
lcidTemp = lcid[0]
}
param := []interface{}{acctID, username, password, lcidTemp}
param := RequestValidateUser{
Format: 1,
Useragent: "ApiClient",
Rid: uuid.NewString(),
Timestamp: time.Now().Format("2006-01-02"),
V: "1.0",
Parameters: []interface{}{acctID, username, password, lcidTemp},
}
resp, err := c.PostRequest(api, param)
if err != nil {
return nil, err
... ... @@ -64,8 +74,7 @@ func (c *Client) Login(acctID string, username string, password string, lcid ...
// 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)
resp, err := c.PostRequest(api, param)
if err != nil {
return nil, err
}
... ... @@ -75,11 +84,6 @@ func (c *Client) ExecuteBillQuery(param RequestExecuteBillQuery) (*BillQueryResu
if err != nil {
return nil, err
}
queryResult := newBillQueryResult(dataByte, param.FieldKeys)
queryResult := newBillQueryResult(dataByte, param.Data.FieldKeys)
return queryResult, queryResult.Error()
}
//QueryGroupInfo 分组信息查询
func (c *Client) QueryGroupInfo() {
}
... ...
... ... @@ -35,14 +35,18 @@ func TestExecuteBillQuery(t *testing.T) {
// {"FIsSalseByNet", "是否网销"}, {"FIsAutoAllocate", "自动分配"}, {"FSPUID", "SPU信息"}, {"FPinYin", "拼音"}, {"FDSMatchByLot", "按批号匹配供需"},
// {"FForbidReson", "禁用原因"}, {"FRefStatus", "已使用"}}
result, err := client.ExecuteBillQuery(RequestExecuteBillQuery{
FormId: "BD_MATERIAL", //物料
FieldKeys: "FMATERIALID,FDocumentStatus,FName,FNumber,FModifyDate,FBaseUnitId.FName,FUseOrgId.FName,FMaterialGroup.FName", //查询的字段
TopRowCount: 5,
FormId: "BD_MATERIAL",
Data: ExecuteBillQueryData{
FormId: "BD_MATERIAL",
FieldKeys: "FMATERIALID,FDocumentStatus,FName,FNumber,FModifyDate,FBaseUnitId.FName,FUseOrgId.FName,FMaterialGroup.FNumber", //查询的字段
TopRowCount: 5,
FilterString: `FMaterialGroup.FNumber like '05%' and FModifyDate<'2022-01-08T19:36:06'`,
},
})
t.Logf("result buf===> %s \n", string(result.Buf))
if err != nil {
t.Error(err)
return
}
t.Logf("tomap===>%v \n", result.ToMapString())
// t.Logf("tomap===>%v \n", result.ToMapString())
}
... ...
... ... @@ -7,8 +7,6 @@ import (
"io"
"net/http"
"time"
"github.com/google/uuid"
)
//全局使用的http请求
... ... @@ -17,24 +15,9 @@ type HttpClient struct {
Cookie []*http.Cookie
}
//WrapPostData 包装发送的数据
func (hClient *HttpClient) WrapPostData(param interface{}) (*postData, error) {
data := postData{
Format: 1,
Useragent: "ApiClient",
Rid: uuid.NewString(),
Timestamp: time.Now().Format("2006-01-02"),
V: "1.0",
Parameters: param,
}
return &data, nil
}
func (hClient *HttpClient) PostRequest(api string, param interface{}) (*http.Response, error) {
data, err := hClient.WrapPostData(param)
if err != nil {
return nil, err
}
var err error
data := param
url := fmt.Sprintf("%s%s", hClient.HostUrl, api)
var buf bytes.Buffer
encoder := json.NewEncoder(&buf)
... ...
... ... @@ -92,8 +92,7 @@ func (result *BillQueryResult) ToMap() []map[string]interface{} {
func (result *BillQueryResult) Error() error {
var (
errMsg QueryError
err error
err error
)
jResult := gjson.ParseBytes(result.Buf)
for _, arr1 := range jResult.Array() {
... ... @@ -101,13 +100,15 @@ func (result *BillQueryResult) Error() error {
if !item.IsObject() {
return nil
}
var errMsg QueryError
err = json.Unmarshal([]byte(item.Raw), &errMsg)
if err != nil {
return err
}
err = errMsg
}
}
return errMsg
return err
}
//TODO 将结果解析为结构体
... ...
package k3cloud
//postData 请求接口发送的数据结构
type postData struct {
Format int `json:"format"`
Useragent string `json:"useragent"`
Rid string `json:"rid"`
Parameters interface{} `json:"parameters"`
Timestamp string `json:"timestamp"`
V string `json:"v"`
}
//登录验证请求数据结构 /Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser.common.kdsvc
type (
// RequestValidateUser struct {
// AcctID string `json:"acctID"` //账套Id,
// Username string `json:"username"` //密码
// Password string `json:"password"` //用户登陆名
// Lcid int `json:"lcid"` //语言id,选择哪种语言访问,参考:中文2052,英文1033,繁体307
// }
// AcctID string `json:"acctID"` //账套Id,
// Username string `json:"username"` //密码
// Password string `json:"password"` //用户登陆名
// Lcid int `json:"lcid"` //语言id,选择哪种语言访问,参考:中文2052,英文1033,繁体307
RequestValidateUser struct {
Format int `json:"format"`
Useragent string `json:"useragent"`
Rid string `json:"rid"`
Timestamp string `json:"timestamp"`
V string `json:"v"`
Parameters []interface{} `json:"parameters"`
}
ReponseValidateUser struct {
... ... @@ -39,8 +35,9 @@ type (
)
//表单数据查询 /K3Cloud/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery.common.kdsvc
//数据请求结构
type (
RequestExecuteBillQuery struct {
ExecuteBillQueryData struct {
FormId string `json:"FormId"` //必录,查询表单元数据唯一标识
FieldKeys string `json:"FieldKeys"` //必录,待查询表单的字段列表
Limit int `json:"Limit"` //非必录,分页取数每页允许获取的数据,最大不能超过2000
... ... @@ -49,4 +46,8 @@ type (
OrderString string `json:"OrderString"` //非必录,排序条件
TopRowCount int `json:"TopRowCount"` //非必录,返回总行数
}
RequestExecuteBillQuery struct {
FormId string `json:"FormId"` //必录,查询表单元数据唯一标识
Data ExecuteBillQueryData `json:"data"`
}
)
... ...