本文介绍了K/3Cloud BOS之前仅提供.net版本的webapi client sdk,而java版本的sdk缺乏完整性和示例代码,导致集成时存在乱码等问题。为解决这些问题,现推出适用于Java 1.7的K/3 Cloud webapi client sdk for java,并提供了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)。demo代码可以参考如下,示例代码中演示了K3CloudApiClient和ApiClient的使用方法。在实际应用中,建议大家使用K3CloudApiClient就可以了,而ApiClient可以用来自由发挥。
<P>
import java.util.List;</P>
<P>import kingdee.bos.webapi.client.ApiClient;
import kingdee.bos.webapi.client.K3CloudApiClient;</P>
<P>public class DemoTest {
static String K3CloudURL = "<A href="http://localhost:1600/">http://localhost:1600/</A>";
static String dbId = "5805e44292bf19";
static String uid = "administrator";
static String pwd = "888888";
static int;</P>
<P> 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<List<Object>> 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);</P>
<P> }
}
public static void saveCurrency() throws Exception{
String K3CloudURL = "<A href="http://localhost:1600/">http://localhost:1600/</A>";
String dbId = "5805e44292bf19";
String uid = "administrator";
int;
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);</P>
<P> }
}
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);</P>
<P> }
}
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<List<Object>> sResult = client.executeBillQuery(sContent);//("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Save", new Object[]{sFormId,sContent},String.class);
System.out.println("CurrencyTest success:"+sResult);</P>
<P> }
}
}
</P>
推荐阅读