即时库存查询WebApi接口(使用自定义接口封装)调用示例(Python 版本,含源码附件)
一、需求背景以及接口定义
接口说明以及参数信息参考链接:
即时库存查询WebApi接口(使用自定义接口封装)调用示例(.Net 版本,含源码附件)
二、python调用示例
import urllib.parse
import urllib.request
import re
import json
import time
import datetime
import threading
import http.cookiejar
#登录地址
LOGIN_URL="http://127.0.0.1/K3Cloud/Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser.common.kdsvc"
#查询地址
QUERYSTOCK_URL="http://127.0.0.1/K3Cloud/Kingdee.K3.SCM.WebApi.ServicesStub.InventoryQueryService.GetInventoryData.common.kdsvc"
#获取cookie
def GetCookie():
logindata={"acctid":"5f31fb5dca7566","username":"test","password":"123456","lcid":2052}
post_data=bytes(urllib.parse.urlencode(logindata),encoding='utf8')
cookie=http.cookiejar.CookieJar()
handler=urllib.request.HTTPCookieProcessor(cookie)
loginres=urllib.request.build_opener(handler).open(LOGIN_URL,data=post_data)
if (loginres.code==200):
resJson=json.loads(loginres.read().decode('utf-8'))
if resJson["LoginResultType"]==1:
return cookie
else:
return False
else:
return False
#接口查询
def QueryStockData():
params=[{
"fstockorgnumbers":"",
"fmaterialnumbers":"",
"fstocknumbers":"CK001,CK002,CK003",
"flotnumbers":"",
"isshowstockloc":"true",
"isshowauxprop":"true",
"pageindex":1,
"pagerows":1000
}]
post_data={
"format":1,
"useragent":"ApiClient",
"rid":"575757585755",
"parameters":json.dumps(params),
"timestamp":"2020-09-28 19:58:00",
"v":"1.0"
}
curcookie=GetCookie()
if curcookie:
post_data2=bytes(urllib.parse.urlencode(post_data),encoding='utf8')
handler=urllib.request.HTTPCookieProcessor(curcookie)
resdata=urllib.request.build_opener(handler).open(QUERYSTOCK_URL,data=post_data2)
if resdata.code==200:
print(resdata.read().decode('utf-8'))
if __name__ == '__main__':
QueryStockData()
即时库存查询WebApi接口(使用自定义接口封装)调用示例(Python 版本,含源码附件)
本文2024-09-23 02:56:46发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-155711.html