11
This commit is contained in:
@@ -0,0 +1,166 @@
|
||||
using Kingdee.CDP.WebApi.SDK;
|
||||
using MyCode.Project.Domain.Message.Request.KingDee;
|
||||
using MyCode.Project.Domain.Message.Response.KingDee;
|
||||
using MyCode.Project.Infrastructure.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
|
||||
namespace MyCode.Project.OutSideService.Implementation
|
||||
{
|
||||
public class KingDeeService //: IKingDeeService
|
||||
{
|
||||
public KingDeeService()
|
||||
{
|
||||
}
|
||||
public static K3CloudApi staClient = null;
|
||||
public static DateTime timeOut = DateTime.Now;
|
||||
|
||||
|
||||
#region
|
||||
/// <summary>
|
||||
/// 获取一个K3客户端
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public K3CloudApi GetK3CloudClient(string yuYan = "")
|
||||
{
|
||||
|
||||
/***
|
||||
* "Kingdee": {
|
||||
"Default": {
|
||||
//第三方系统登录授权的账套ID
|
||||
"AcctID": "65edc24ab975db",
|
||||
//第三方系统登录授权的应用ID
|
||||
"AppID": "302967_20fp7YsL2kpWR9VG5Y3LSbUHzv3/SDmv",
|
||||
//第三方系统登录授权的应用密钥
|
||||
"AppSec": "5e38f16711514126ae1511ca4ead3232",
|
||||
//第三方系统登录授权的用户
|
||||
"UserName": "ERP1",
|
||||
//账套语系,默认2052
|
||||
"LCID": 2052,
|
||||
//服务Url地址 (只有私有云用户需要配置Serverurl,公有云用户走网关不需要配置)
|
||||
"ServerUrl": "http://8.138.110.197/K3Cloud",
|
||||
// 时间
|
||||
"Timestamp": 30
|
||||
}
|
||||
}
|
||||
语言ID,中文2052(默认),英文1033,繁体3076;
|
||||
*
|
||||
*
|
||||
* */
|
||||
|
||||
if (staClient == null || DateTime.Now > timeOut || 1 == 1)
|
||||
{
|
||||
|
||||
string AppID = ConfigurationManager.AppSettings.Get("X-KDApi-AppID");
|
||||
string UserName = ConfigurationManager.AppSettings.Get("X-KDApi-UserName");
|
||||
string AcctID = ConfigurationManager.AppSettings.Get("X-KDApi-AcctID");
|
||||
string AppSec = ConfigurationManager.AppSettings.Get("X-KDApi-AppSec");
|
||||
string LCID = ConfigurationManager.AppSettings.Get("X-KDApi-LCID");
|
||||
if (yuYan != "")
|
||||
LCID = yuYan;
|
||||
string ServerUrl = ConfigurationManager.AppSettings.Get("X-KDApi-ServerUrl");
|
||||
//staClient = new K3CloudApi(ServerUrl);
|
||||
timeOut = DateTime.Now.AddMinutes(5);
|
||||
staClient = new K3CloudApi();
|
||||
staClient.InitClient(AcctID, AppID, AppSec, UserName, int.Parse(LCID), "100", ServerUrl);
|
||||
//staClient.InitClient("65edc24ab975db", "302967_20fp7YsL2kpWR9VG5Y3LSbUHzv3/SDmv", "5e38f16711514126ae1511ca4ead3232", "ERP1", 2052, "100", "http://8.138.110.197/k3cloud/");
|
||||
}
|
||||
return staClient;
|
||||
|
||||
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#region 保存一个订单对象
|
||||
/// <summary>
|
||||
/// 保存一个订单对象
|
||||
/// </summary>
|
||||
/// <param name="formId"></param>
|
||||
/// <param name="billSave"></param>
|
||||
/// <returns></returns>
|
||||
public string Save(string formId, BillSave billSave)
|
||||
{
|
||||
staClient = GetK3CloudClient();
|
||||
var datastr = JsonHelper.ToJson(billSave);
|
||||
//LogHelper.Info(datastr);
|
||||
var resultString = staClient.Save(formId, datastr);
|
||||
if (resultString.Contains("ErrorCode"))
|
||||
{
|
||||
LogHelper.Error("金蝶云接口调用失败,请检查");
|
||||
LogHelper.Error(resultString);
|
||||
//throw new Exception("单据在云星空已锁定,请联系采购员");
|
||||
string Message = "";
|
||||
try
|
||||
{
|
||||
ErrorResponse errorResponse = JsonHelper.ToObject<ErrorResponse>(resultString);
|
||||
Message = string.Join(",", errorResponse.Result.ResponseStatus.Errors.Select(t => t.Message).ToList());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string ds = ex.Message;
|
||||
throw new Exception("2云星空接口调用失败,请联系管理员,错误信息:" + resultString);
|
||||
|
||||
}
|
||||
throw new Exception("1云星空接口调用失败,请联系管理员,错误信息:" + Message);
|
||||
}
|
||||
var result = JsonHelper.ToObject<Dictionary<string, Dictionary<string, dynamic>>>(resultString);
|
||||
var data = result["Result"]["ResponseStatus"];
|
||||
return resultString;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
#region Delete(删除某个订单)
|
||||
/// <summary>
|
||||
/// 删除某个订单
|
||||
/// </summary>
|
||||
/// <param name="formId"></param>
|
||||
/// <param name="billdelete"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
|
||||
public dynamic Delete(string formId, BillDelete billdelete)
|
||||
{
|
||||
staClient = GetK3CloudClient();
|
||||
var datastr = JsonHelper.ToJson(billdelete);
|
||||
LogHelper.Info(datastr);
|
||||
var resultString = staClient.Delete(formId, datastr);
|
||||
if (resultString.Contains("ErrorCode"))
|
||||
{
|
||||
LogHelper.Error("金蝶云接口调用失败,请检查");
|
||||
LogHelper.Error(resultString);
|
||||
string Message = "";
|
||||
try
|
||||
{
|
||||
ErrorResponse errorResponse = JsonHelper.ToObject<ErrorResponse>(resultString);
|
||||
Message = string.Join(",", errorResponse.Result.ResponseStatus.Errors.Select(t => t.Message).ToList());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string ds = ex.Message;
|
||||
throw new Exception("2云星空接口调用失败,请联系管理员,错误信息:" + resultString);
|
||||
|
||||
}
|
||||
throw new Exception("1云星空接口调用失败,请联系管理员,错误信息:" + Message);
|
||||
}
|
||||
var result = JsonHelper.ToObject<dynamic>(resultString);
|
||||
var data = result["Result"]["ResponseStatus"]["SuccessEntitys"];
|
||||
return JsonHelper.ToJson(data);
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,9 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Kingdee.CDP.WebApi.SDK">
|
||||
<HintPath>..\kingdeeDll\Kingdee.CDP.WebApi.SDK.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Practices.Unity, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Lib\Microsoft.Practices.Unity.dll</HintPath>
|
||||
@@ -108,6 +111,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="IBfyService.cs" />
|
||||
<Compile Include="Implementation\BfyService.cs" />
|
||||
<Compile Include="Implementation\KingDeeService.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user