自字义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; }
}
推荐阅读
您的鼓励与嘉奖将成为创作者们前进的动力,如果觉得本文还不错,可以给予作者创作打赏哦!
请选择打赏金币数 *