溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Api接口開發(fā)實例

發(fā)布時間:2020-07-08 07:55:13 來源:網(wǎng)絡(luò) 閱讀:7537 作者:51GT 欄目:編程語言

目的:第三方系統(tǒng)可以調(diào)用k3cloud系統(tǒng)中的庫存數(shù)據(jù)與表單數(shù)據(jù)、報表數(shù)據(jù)進行數(shù)據(jù)分析;
實驗研究:本來打算使用金蝶協(xié)同開發(fā)平臺進行測試開發(fā)api接口,測試沒有成功,然后就開始使用早期開發(fā)使用 的方法進行測試,然后成功了!時間寶貴,潦草寫了以下的代碼步驟,大家可以作為參考!
步驟:1 vs中新建類 ,引用需要的命名空間;
2 vs中新建控制臺,為了測試第三方平臺調(diào)用測試成功與否;
代碼如下:
新建類
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.SqlBuilder;
using Kingdee.BOS.JSON;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Orm.Metadata.DataEntity;
using Kingdee.BOS.ServiceHelper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kingdee.BOS.App.Data;
using System.ComponentModel;
using Kingdee.BOS.WebApi.ServicesStub;

namespace api
{
[Description("接口測試")]
public class Class1 : Kingdee.BOS.WebApi.ServicesStub.AbstractWebApiBusinessService
{
public Class1(Kingdee.BOS.ServiceFacade.KDServiceFx.KDServiceContext context)
: base(context)
{ }

private DynamicObjectCollection GetInven()
{
StringBuilder str = new StringBuilder();
str.Append(@" /dialect/ SELECT t6.FNUMBER,t7.fname,m.FNUMBER, ml.fname,w.fname,isnull(t14.fname,'無') ,TSL.fname,tsl1.FNUMBER ,
sum(TI.FBASEQTY) FBASEQTY,st01.FNAME
FROM (select FBASEQTY,FSTOCKID,FMATERIALID,FSTOCKSTATUSID,FSTOCKORGID from T_STK_INVENTORY where FMATERIALID>1 and FSTOCKSTATUSID=10000 and FOBJECTTYPEID= 'STK_Inventory' and FKEEPERTYPEID='BD_KeeperOrg'and FOWNERTYPEID='BD_OwnerOrg' and FISEFFECTIVED=1 and FBASEQTY<>0) TI
inner join (select FSTOCKSTATUSID,FNAME From T_BD_STOCKSTATUS_L where FSTOCKSTATUSID>1 and FLOCALEID=2052) st01 on st01.FSTOCKSTATUSID=TI.FSTOCKSTATUSID
inner JOIN (select fnumber,FMASTERID,FMATERIALID,FMATERIALGROUP from T_BD_MATERIAL where FMATERIALID>1 and FDOCUMENTSTATUS='C' and FFORBIDSTATUS='A' ) M ON M.FMATERIALID = TI.FMATERIALID
LEFT JOIN (select FMATERIALID,FLOCALEID,fname from T_BD_MATERIAL_L where FMATERIALID>1 and FLOCALEID=2052) ML ON (M.FMASTERID = ML.FMATERIALID)
LEFT JOIN (select FSTOCKID,fname,FLOCALEID From T_BD_STOCK_L where FSTOCKID>1 and FLOCALEID=2052) TSL ON (TSL.FSTOCKID = TI.FSTOCKID)
LEFT JOIN (select fstockid,FGROUP,fnumber from T_BD_STOCK where fstockid>1 and FDOCUMENTSTATUS='C' and FFORBIDSTATUS='A') tsl1 on TSL.FSTOCKID=tsl1.fstockid
LEFT join (select FID,fname from T_BD_STOCKGROUP_L where FID>1 and FLOCALEID=2052) t14 on tsl1.FGROUP=t14.fid
inner join (select FMATERIALID,FCATEGORYID From T_BD_MATERIALBASE where FCATEGORYID>1) u0 on m.FMATERIALID=u0.FMATERIALID
left join (select FCATEGORYID,fname From T_BD_MATERIALCATEGORY_L where FCATEGORYID>1 and FLOCALEID=2052) w on u0.FCATEGORYID=w.FCATEGORYID
left join (select fid,FPARENTID From T_BD_MATERIALGROUP where fid>1) t4 on m.FMATERIALGROUP=t4.fid
left join (select fid,FNUMBER From T_BD_MATERIALGROUP where fid>1 ) t6 on t4.FPARENTID=t6.fid
left join (select fid,fname From T_BD_MATERIALGROUP_L where fid>1 and FLOCALEID=2052) t7 on t4.FPARENTID=t7.fid
inner join (select FORGID,fname From T_ORG_ORGANIZATIONS_L where FORGID>1 and FLOCALEID=2052) cc on TI.FSTOCKORGID=cc.FORGID
group by t6.FNUMBER,t7.fname,ml.fname,m.FNUMBER,tsl.fname,w.fname,isnull(t14.fname,'無'),TSL.fname,tsl1.FNUMBER,st01.FNAME");
return DBUtils.ExecuteDynamicObject(this.KDContext.Session.AppContext, str.ToString());
}
public JSONArray ExecuteService()
{

        DynamicObjectCollection list = GetInven() as DynamicObjectCollection;
        JSONArray jsonArray = new JSONArray();
        foreach (DynamicObject dynamicObject in list)
        {
            jsonArray.Add(ConvertDynamicObject2Json(dynamicObject));
        }
        returnjsonArray;
    }

    private JSONObject ConvertDynamicObject2Json(DynamicObject dynamicObject)
    {
        DynamicPropertyCollection dynamicPropertyCollection = dynamicObject.DynamicObjectType.Properties;
        JSONObject obj = new JSONObject();
        foreach (DynamicProperty property in dynamicPropertyCollection)
        {
            obj.Put(property.Name, dynamicObject[property.Name]);
        }
        return obj;
    }
}

}

新建控制臺:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kingdee.BOS.WebApi.Client;
using Kingdee.BOS.JSON;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{

        ApiClient client1 = new Kingdee.BOS.WebApi.Client.ApiClient("http://localhost/k3cloud/");
        bool result1 = client1.Login("數(shù)據(jù)中心id", "用戶名", "密碼", 2052);
        if (result1)
        {

         object   responseOut1 = client1.Execute<JSONArray>("api.Class1.ExecuteService,api",null);
        }
        Console.Write(responseOut1);
        Console.ReadLine();

    }
}

}

生成解決方案后,打斷點進行測試結(jié)果如下:
Api接口開發(fā)實例

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI