C#对接金蝶接口(K3)
金蝶查询接口:
/// <summary> /// 调用金蝶的查询接口 /// </summary> /// <param name="context"></param> public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; // 使用webapi引用组件Kingdee.BOS.WebApi.Client.dll K3CloudApiClient client = new K3CloudApiClient("http://8.136.98.54/k3cloud/"); var loginResult = client.ValidateLogin("5fe007ae85d7d5", "Administrator", "888888", 2052); var resultType = JObject.Parse(loginResult)["LoginResultType"].Value<int>(); //登录结果类型等于1,代表登录成功 if (resultType == 1) { //string st = "{\n \"FormId\": \"BD_Customer\",\"FieldKeys\": \"FNumber,FName\", \"FilterString\": \"\"\n}"; var req = context.Request.Form["params"]; var test = client.ExecuteBillQuery(req); context.Response.Write(JsonConvert.SerializeObject(test)); } }
调用金蝶查询接口(传参和取数据的作用):
private dynamic GetWorkOrder(string no) { static string KDApiUrl = "http://vps2.seekersoft.cn:8037/api.ashx"; var client = new RestClient(KDApiUrl); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AlwaysMultipartFormData = true; request.AddParameter("params", "{\"FormId\":\"PRD_MO\",\"FieldKeys\": \"FMaterialId.FNumber,F_ora_Text,FSpecification,FLot.FNumber,FDate,FBillNo\",\"FilterString\": \"FBillNo = '" + no + "'\"}"); IRestResponse response = client.Execute(request); var data = JsonConvert.DeserializeObject<List<List<string>>>(response.Content); List<dynamic> result = new List<dynamic>(data.Count); foreach (var li in data) { return (new { FMaterimalNo = li[0],// 物料编码 FSaleOrderNo = li[1], //销售订单号 FSpecification=li[2],//大昌规格型号 FlotFNumber=li[3],//批号 FDate=li[4],//生产日期 FBillNo=li[5]//生产工单单据号 }); } return null; }
越是无知的人越是觉得自己无所不知(之前的自己)
越是学习的人越是觉得自己会的太少了(现在的自己)
共勉