即时库存查询WebApi接口(使用自定义接口封装)调用示例(.Net 版本,含源码附件)
一、前言
基于目前使用Api接口情况的反馈,在使用系统自带的【即时库存】WebApi接口时,只有基本单位数量以及辅单位数量是能直接使用,其他单位数量以及可用量情况都需要调用其他接口经过换算、计算才能得到,为便于大家使用,也是对现有即时库存Api接口的一个补充,我们封装了新的【即时库存查询】Api接口。以下即对新接口做个说明。
二、支持版本
补丁号:PT-146848 (即2020年8月13号之后的补丁)
三、接口信息
1、接口地址
2、接口参数
2.1 公共参数(与系统自带接口一致)
{ "format":1, "useragent":"ApiClient", "rid":"唯一码", "parameters":"业务参数(填写下边的业务参数)", "timestamp":"时间戳", "v":"1.0" }
2.2 业务参数
[{ "fstockorgnumbers":"", /*组织编码,多个用,分隔*/ "fmaterialnumbers":"", /*物料编码,多个用,分隔*/ "fstocknumbers":"",/*仓库编码,多个用,分隔*/ "flotnumbers":"",/*批号编码,多个用,分隔*/ "isshowstockloc":true,/*是否查询仓位,查询仓位对性能有影响*/ "isshowauxprop":true,/*是否查询辅助属性,查询辅助属性对性能有影响*/ "pageindex":1,/*当前页*/ "pagerows":1000, /*每页显示行数*/ --------------2020/12/24后---------------------------- "fminbaseqty":0,/*最小库存,不需要时不用传此参数*/ "fmaxbaseqty":0,/*最大库存,不需要时不用传此参数*/ "isshowzeroinv":true,/*是否显示零库存,不需要时不用传此参数*/ "lastupdatetime":""/*最近更新时间,格式:yyyy-MM-dd HH:mm:ss,不需要时不用传此参数*/ }]
2.3 版本更新
1)2020年12月24号
添加业务参数:
[{ "fminbaseqty":0,/*最小库存,不需要时不用传此参数*/ "fmaxbaseqty":0,/*最大库存,不需要时不用传此参数*/ "isshowzeroinv":true,/*是否显示零库存,不需要时不用传此参数*/ "lastupdatetime":""/*最近更新时间,格式:yyyy-MM-dd HH:mm:ss,不需要时不用传此参数*/ }]
增加返回字段
FMASTERID 物料主码 FUPDATETIME 最近库存更新时间
3、返回数据字段说明
{ "rowcount": 1000,/*总行数*/ "success": true,/*调用结果/ "message": "success", "data": [ { "FID": "",/*即时库存內码*/ "FSTOCKORGID": 0,/*库存组织ID*/ "FSTOCKORGNUMBER": "", /*库存组织编码*/ "FSTOCKORGNAME": "",/*库存组织名称*/ "FKEEPERTYPEID": "BD_KeeperOrg", /*保管者类型*/ "FKEEPERTYPENAME": "", "FKEEPERID": 0, /*保管者*/ "FKEEPERNUMBER": "",/*保管者编码*/ "FKEEPERNAME": "",/*保管者名称*/ "FOWNERTYPEID": "",/*货主类型*/ "FOWNERTYPENAME": null, "FOWNERID": 0,/*货主ID*/ "FOWNERNUMBER": "",/*货主编码*/ "FOWNERNAME": "",/*货主名称*/ "FSTOCKID": ,/*仓库ID*/ "FSTOCKNUMBER": "",/*仓库编码*/ "FSTOCKNAME": "",/*仓库名称*/ "FSTOCKLOCID": 0,/*仓位ID*/ "FSTOCKLOC": null, /*仓位编码及名称*/ "FAUXPROPID": 0,/*辅助属性ID*/ "FAUXPROP": null, /*辅助属性*/ "FSTOCKSTATUSID": 0, /*库存状态ID*/ "FSTOCKSTATUSNUMBER": "", "FSTOCKSTATUSNAME": "", "FLOT": 0, /*批号ID*/ "FLOTNUMBER": "", "FBOMID": 0, "FBOMNUMBER": "", "FMTONO": "", "FPROJECTNO": "", "FPRODUCEDATE": "", "FEXPIRYDATE": "", "FBASEUNITID": 0,/*基本单位ID*/ "FBASEUNITNUMBER": "", "FBASEUNITNAME": "", "FBASEQTY": 0,/*基本单位数量*/ "FBASELOCKQTY": 0,/*锁库数量(基本单位)*/ "FSECQTY": 0,/*辅单位数量*/ "FSECLOCKQTY": 0, "FSTOCKUNITID": 0, /*库存单位*/ "FSTOCKUNITNUMBER": "", "FSTOCKUNITNAME": "", "FMATERIALID": , /*物料內码*/ "FMATERIALNUMBER": "", "FMATERIALNAME": "", "FQTY": 1,/*库存数量*/ "FLOCKQTY": 0,/*锁库数量*/ "FSECUNITID": 0, /*辅单位*/ "FSECUNITNUMBER":"", "FSECUNITNAME": "", "FOBJECTTYPEID": "STK_Inventory", "FBASEAVBQTY": 1,/*可用量(基本单位)*/ "FAVBQTY": 1, "FSECAVBQTY": 0 } ]}
四、调用示例代码
class Program
{
static void Main(string[] args)
{
string baseUrl = "http://192.168.1.1/k3cloud";//服务器地址
HttpClientEx httpClient = new HttpClientEx();
httpClient.Url = string.Format("{0}/Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser.common.kdsvc", baseUrl);
List<object> Parameters = new List<object>();
Parameters.Add("11111111");//帐套Id
Parameters.Add("demo");//用户名
Parameters.Add("123456");//密码
Parameters.Add(2052);//多语言:中文
httpClient.Content = JsonConvert.SerializeObject(Parameters);
var iResult = JObject.Parse(httpClient.AsyncRequest())["LoginResultType"].Value<int>();
if (iResult == 1)
{
while (true)
{
Console.WriteLine("请输入任意字符回车继续,输入【exit】退出!");
string key = Console.ReadLine();
if (key == "exit") break;
httpClient.Url = string.Format("{0}/Kingdee.K3.SCM.WebApi.ServicesStub.InventoryQueryService.GetInventoryData.common.kdsvc", baseUrl);
Parameters = new List<object>();
InventoryParamModel model = new InventoryParamModel();
model.fstocknumbers = "CK001,CK002,CK003";
model.isshowauxprop = true;
model.isshowstockloc = true;
model.pageindex = 1;
model.pagerows = 2;
Parameters.Add(model);
httpClient.Content = JsonConvert.SerializeObject(Parameters);
string response = httpClient.AsyncRequest();
Console.WriteLine(string.Format("结果={0}", response));
}
}
}
}
class InventoryParamModel
{
/// <summary>
/// 库存组织编码,多个使用英文逗号【,】分隔
/// </summary>
public string fstockorgnumbers { get; set; }
/// <summary>
/// 物料编码,多个使用英文逗号【,】分隔
/// </summary>
public string fmaterialnumbers { get; set; }
/// <summary>
/// 仓库编码,多个使用英文逗号【,】分隔
/// </summary>
public string fstocknumbers { get; set; }
/// <summary>
/// 批号编码,多个使用英文逗号【,】分隔
/// </summary>
public string flotnumbers { get; set; }
/// <summary>
/// 是否查询仓位
/// </summary>
public bool isshowstockloc { get; set; }
/// <summary>
/// 是否查询辅助属性
/// </summary>
public bool isshowauxprop { get; set; }
/// <summary>
/// 当前页码
/// </summary>
public int pageindex { get; set; }
/// <summary>
/// 每页显示行数
/// </summary>
public int pagerows { get; set; }
}
class HttpClientEx
{
/// <summary>
/// Seivice URL
/// </summary>
public string Url { get; set; }
/// <summary>
/// 内容
/// </summary>
public string Content { get; set; }
/// <summary>
/// Cookie,保证登录后,所有访问持有一个Cookie;
/// </summary>
static CookieContainer Cookie = new CookieContainer();
/// <summary>
/// HTTP访问
/// </summary>
public string AsyncRequest()
{
HttpWebRequest httpRequest = HttpWebRequest.Create(Url) as HttpWebRequest;
httpRequest.Method = "POST";
httpRequest.ContentType = "application/json";
httpRequest.CookieContainer = Cookie;
httpRequest.Timeout = 1000 * 60 * 10;//10min
using (Stream reqStream = httpRequest.GetRequestStream())
{
JObject jObj = new JObject();
jObj.Add("format", 1);
jObj.Add("useragent", "ApiClient");
jObj.Add("rid", Guid.NewGuid().ToString().GetHashCode().ToString());
jObj.Add("parameters", Content);
jObj.Add("timestamp", DateTime.Now);
jObj.Add("v", "1.0");
string sContent = jObj.ToString();
var bytes = UnicodeEncoding.UTF8.GetBytes(sContent);
reqStream.Write(bytes, 0, bytes.Length);
reqStream.Flush();
}
using (var repStream = httpRequest.GetResponse().GetResponseStream())
{
using (var reader = new StreamReader(repStream))
{
return ValidateResult(reader.ReadToEnd());
}
}
}
private static string ValidateResult(string responseText)
{
if (responseText.StartsWith("response_error:"))
{
return responseText.TrimStart("response_error:".ToCharArray());
}
return responseText;
}
}
即时库存查询WebApi接口(使用自定义接口封装)调用示例(.Net 版本,含源码附件)
本文2024-09-23 02:52:44发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-155286.html