金蝶查询转数组,对接金蝶绝对用到的

分享  收藏
2 / 49

根据金蝶论坛扒到的代码自己组装了一下
本人不会 Python,属于看得懂不会写的
上代码希望指正与优化

import json
login_url="http://yourserverip/k3cloud/Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser.common.kdsvc"
query_url="http://yourserverip/K3Cloud/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery.common.kdsvc"
login_data={ "acctid":"yourdatacenter","username":"yourdengluming","password":"yourmima","lcid":2052}
def login():
#定义登录函数 
  login_response=requests.post(url=login_url,data=login_data)
#返回cookies,方便下次访问时携带
  return login_response.cookies   

#查询字段(后面可以自己封装成json)
sFieldKeys = "FBILLNO,FDate,FBillTypeID.FName,FDocumentStatus,FCustId.FName,FReceiveId.FName,FReceiveAddress,FLinkMan,FLinkPhone,FSalerId.FName,FMaterialName,FMaterialModel,FQty,FUnitID,FBaseUnitId"
#请求内容
post_data = {"data":json.dumps({"FormId":"SAL_SaleOrder","FieldKeys":sFieldKeys,"FilterString":"FDate='2022-5-1'","Limit":20})}

#结果
response = requests.post(url=query_url,data=post_data,cookies=login())

#字段数组
sFieldKeysArr = sFieldKeys.split(',')

#返回的单据
sResponseArr = json.loads(response.text)

# 构建新的输出数组
newArray = []
newJsonArray = json.loads(json.dumps(newArray, ensure_ascii=False),strict=False)
# 构建嵌套数据(下标看需求)
for i1 in sResponseArr:
    print (len(i1))
    for i2,v2 in enumerate(i1):
        for i3,v3 in enumerate(sFieldKeysArr):
            addItems = {sFieldKeysArr[0]:i1[0],sFieldKeysArr[1]:i1[1],sFieldKeysArr[2]:i1[2],sFieldKeysArr[3]:i1[3],sFieldKeysArr[4]:i1[4],sFieldKeysArr[5]:i1[5],sFieldKeysArr [6]:i1[6],sFieldKeysArr[7]:i1[7],sFieldKeysArr[8]:i1[8],sFieldKeysArr [9]:i1[9],sFieldKeysArr[10]:i1[10],sFieldKeysArr[11]:i1[11],sFieldKeysArr [12]:i1[12],sFieldKeysArr[13]:i1[13],sFieldKeysArr[14]:i1[14]}
            
    newJsonArray.append(addItems )
    
# 打印结果
output = {'组成的数据':newJsonArray}

数组嵌套组装我希望得到优化,或者各位有更好的方法请分享出来 😄 😄 😄