K/3Cloud BOS之前主要提供.net版本的webapi client sdk,而java版本的sdk示例较少。随着java用户对集成的需求增加,使用java调用K/3Cloud API时遇到乱码等问题。为解决这些问题并规范使用,现推出K/3 Cloud webapi client sdk for java(版本1.7)。该帖提供jar包及demo代码,演示了如何使用K3CloudApiClient和ApiClient进行登录、查询、新增及批量新增等操作,并建议在实际应用中使用K3CloudApiClient。
K/3Cloud BOS之前对外仅提供了.net版本的webapi client sdk,方便二次开发集成调用。而java版本的sdk仅在论坛提供了部分简单的示例代码。随着大家对K/3CLoud的集成的需求日益加大,面对广大爱好java的粉丝,没有现成的sdk可以使用,无疑是一个痛点。而且大家对接口的调用的写法也是千姿百态,问题多多,最近收到不少关于java调用api出现乱码的反馈,有的问题是数据进入到cloud系统后中文乱码,有的是返回数据到第三方系统显示乱码。究其根本原因还是大家的代码书写的问题。为了一劳永逸解决此类问题,并规范大家使用java调用K/3Cloud webapi的代码,现在向大家推介K/3 Cloud webapi client sdk for java(java的版本是1.7)。有需要的同学请下载本帖中的jar包,引入到项目中。demo代码可以参考如下,示例代码中演示了K3CloudApiClient和ApiClient的使用方法。在实际应用中,建议大家使用K3CloudApiClient就可以了,而ApiClient可以用来自由发挥。
[code]
import java.util.List;
import kingdee.bos.webapi.client.ApiClient;
import kingdee.bos.webapi.client.K3CloudApiClient;
public class DemoTest {
static String K3CloudURL = "http://localhost:1600/";
static String dbId = "5805e44292bf19";
static String uid = "administrator";
static String pwd = "888888";
static int lang = 2052;
public static void main(String[] args) throws Exception {
//saveCurrency();
//query;
//batchsaveCurrency();
testall();
}
public static void testall() throws Exception{
K3CloudApiClient client = new K3CloudApiClient(K3CloudURL);
Boolean result = client.login(dbId, uid, pwd, lang);
if(result){
String sContent = "{\"FormId\":\"PUR_PurchaseOrder\","+// 采购订单formid
"\"TopRowCount\":2,"+// 最多允许查询的数量,0或者不要此属性表示不限制
"\"Limit\":3,"+// 分页取数每页允许获取的数据,最大不能超过2000
"\"StartRow\":0,"+// 分页取数开始行索引,从0开始,例如每页10行数据,第2页开始是10,第3页开始是20
//"\"FilterString\":\"FMaterialId.FNumber like 'HG_TEST%'\","+// 过滤条件
//"\"FilterString\":\"FBillNo='CGDD000008'\","+// 过滤条件
"\"OrderString\":\"FID ASC\","+// 排序条件
"\"FieldKeys\":\"FID,FSupplierId,FMaterialId.FNumber,FMaterialName\"}";// 获取采购订单数据参数,内码,供应商id,物料id,物料编码,物料名称
List> sResult = client.executeBillQuery(sContent);//("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Save", new Object[]{sFormId,sContent},String.class);
System.out.println("CurrencyTest success:"+sResult);
String sFormId = "BD_Currency";
String content = "{\"Numbers\":[\"PRENB00016\"]}";
String result1 = client.delete(sFormId, content);
System.out.println("CurrencyTest success:"+result1);
}
}
public static void saveCurrency() throws Exception{
String K3CloudURL = "http://localhost:1600/";
String dbId = "5805e44292bf19";
String uid = "administrator";
int lang = 2052;
ApiClient client = new ApiClient(K3CloudURL);
Boolean result = client.login(dbId, uid, pwd, lang);
if(result){
String sFormId = "BD_Currency";
String sContent = "{\"Creator\":\"\",\"NeedUpDateFields\":[\"\"],\"Model\":{\"FNumber\":\"PRENB00016\",\"FName\":\"你是噢吗6 ?\",\"FCODE\":\"CNYY\",\"FPRICEDIGITS\":6,\"FAMOUNTDIGITS\":2,\"FPRIORITY\":0,\"FCURRENCYSYMBOLID\":{\"FNumber\":\"CS002\"},\"FIsShowCSymbol\":true}}";
String sResult = client.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Save", new Object[]{sFormId,sContent},String.class);
System.out.println("CurrencyTest success:"+sResult);
}
}
public static void batchsaveCurrency() throws Exception{
K3CloudApiClient client = new K3CloudApiClient(K3CloudURL);
Boolean result = client.login(dbId, uid, pwd, lang);
if(result){
String sFormId = "BD_Currency";
String sContent = "{\"Creator\":\"\",\"NeedUpDateFields\":[\"\"],\"Model\":[{\"FNumber\":\"PRENB000216\",\"FName\":\"你是噢吗26 ?\",\"FCODE\":\"CNYY\",\"FPRICEDIGITS\":6,\"FAMOUNTDIGITS\":2,\"FPRIORITY\":0,\"FCURRENCYSYMBOLID\":{\"FNumber\":\"CS002\"},\"FIsShowCSymbol\":true},"+
"{\"FNumber\":\"PRENB00036\",\"FName\":\"你是噢吗16 ?\",\"FCODE\":\"CNYY\",\"FPRICEDIGITS\":6,\"FAMOUNTDIGITS\":2,\"FPRIORITY\":0,\"FCURRENCYSYMBOLID\":{\"FNumber\":\"CS002\"},\"FIsShowCSymbol\":true}]}";
String sResult = client.batchSave(sFormId, sContent);
System.out.println("CurrencyTest success:"+sResult);
}
}
public static void query() throws Exception{
K3CloudApiClient client = new K3CloudApiClient(K3CloudURL);
Boolean result = client.login(dbId, uid, pwd, lang);
if(result){
String sContent = "{\"FormId\":\"PUR_PurchaseOrder\","+// 采购订单formid
"\"TopRowCount\":2,"+// 最多允许查询的数量,0或者不要此属性表示不限制
"\"Limit\":3,"+// 分页取数每页允许获取的数据,最大不能超过2000
"\"StartRow\":0,"+// 分页取数开始行索引,从0开始,例如每页10行数据,第2页开始是10,第3页开始是20
//"\"FilterString\":\"FMaterialId.FNumber like 'HG_TEST%'\","+// 过滤条件
//"\"FilterString\":\"FBillNo='CGDD000008'\","+// 过滤条件
"\"OrderString\":\"FID ASC\","+// 排序条件
"\"FieldKeys\":\"FID,FSupplierId,FMaterialId.FNumber,FMaterialName\"}";// 获取采购订单数据参数,内码,供应商id,物料id,物料编码,物料名称
List> sResult = client.executeBillQuery(sContent);//("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Save", new Object[]{sFormId,sContent},String.class);
System.out.println("CurrencyTest success:"+sResult);
}
}
}
推荐阅读