自定义WEBAPI 调用 (无DLL引用 大坑解决)原创
金蝶云社区-jerryhu
jerryhu
1人赞赏了该文章 781次浏览 未经作者许可,禁止转载编辑于2022年04月18日 09:18:51

自字义WEBAPI接口

JObject 对像接收是注意点,然后Newtonsoft用的是4.0也要注意


public class InvoiceDoService : AbstractWebApiBusinessService

    {

        public InvoiceDoService(KDServiceContext context) : base(context) { }


        public string Update(JObject parameter)

        {

            //获取参数

            JSONObject jsonResult = new JSONObject();

            try

            {

                string billNo = "";

                string sql = string.Format("update DQIN_LincInvoice set FBILLSTATUS='C' );

                int res = Kingdee.BOS.App.Data.DBUtils.Execute(this.KDContext.Session.AppContext, sql);

                if (res > 0)

                {

                    jsonResult.Add("IsSuccess", true);

                    jsonResult.Add("Msg", "");

                }

                else

                {

                    jsonResult.Add("IsSuccess", false);

                    jsonResult.Add("Msg", "Update Error!");

                }

            }

            catch (Exception ex)

            {

                jsonResult.Add("IsSuccess", false);

                jsonResult.Add("Msg", ex.Message);

            }

            return KDObjectConverter.SerializeObject(jsonResult);

        }

    }


给第三方用平台调用,不引用金蝶提供的CLIENT的DLL,使用通用方式


string uri = serverUrl + "UQKA.K3.LQZB.InvoicDo.WebApi.ServicesStub.InvoiceDoService.Update,UQKA.K3.LQZB.InvoicDo.WebApi.ServicesStub.common.kdsvc";

                List<object> objList = new List<object>();

                objList.Add("20000");

        //InvoiceInfo封装了要传递的参数,硬抄就是了,我也是搜来的

                InvoiceInfo info = new InvoiceInfo();

                info.format = 1;

                info.useragent = "ApiClient";

                info.rid = Guid.NewGuid().ToString().GetHashCode().ToString();

                info.parameters = "[{\"billno\":\""+ invoiceID + "\"}]";

                info.timestamp = GetTimeStamp();

                info.v = "1.0";

                string senddata = JsonConvert.SerializeObject(info);

                HttpContent content = new StringContent(senddata, Encoding.UTF8);

                content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

                HttpResponseMessage response = httpClient.PostAsync(uri, content).Result;

                if (response.IsSuccessStatusCode)

                {

                    string responseJson = response.Content.ReadAsStringAsync().Result;

                    if (!responseJson.Equals(""))

                    {

                        

                        return "";

                    }

                }


private class InvoiceInfo

        {

            public string parameters { get; set; }


            public int format { get; set; }


            public string rid { get; set; }


            public long timestamp { get; set; }


            public string v { get; set; }

            

            public string useragent { get; set; }


        }


图标赞 1
1人点赞
还没有人点赞,快来当第一个点赞的人吧!
图标打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!

您的鼓励与嘉奖将成为创作者们前进的动力,如果觉得本文还不错,可以给予作者创作打赏哦!

请选择打赏金币数 *

10金币20金币30金币40金币50金币60金币
可用金币: 0