Giter Site home page Giter Site logo

k3client's Introduction

K3Client of Java Version

Maven:

 <dependency>
   <groupId>com.github.joshualley</groupId>
   <artifactId>K3Client</artifactId>
   <version>1.2.0</version>
 </dependency>

Usages:

对金蝶云星空的WebApi的请求进行了一次封装,用法如下:

  1. 登录

     String url = "http://yourdomain.com";
     K3Client client = K3Client.getInstance().setDomain(url);
     LoginParam param = new LoginParam.Builder()
             .setAcctID("数据中心ID")
             .setUsername("用户名")
             .setPassword("密码")
             .build();
     client.loginRequestAsync(param, new K3Response() {
         @Override
         public void onSuccess(JsonObject res) {
             // Do Something.
         }
    
         @Override
         public void onError(Exception e) {
             System.out.println("登录时发生错误:" + e.getMessage());
         }
     });
     // 如果忽略错误可以使用lambda
     client.loginRequestAsync(param, res -> {
        // Do Something.
     });
  2. 其他查询,登录之后才能够使用,以单据查询为例

    K3Client client = K3Client.getInstance();
    QueryParam queryParam = new QueryParam.Builder()
            .setFormId("ora_CRM_Niche")
            .setFieldKeys(new String[]{"FID", "FDocumentStatus"})
            .setFilterString("FDocumentStatus='D'")
            .build();
    client.postRequestAsync(queryParam, new K3Response() {
        @Override
        public void onSuccess(JsonObject res) {
            System.out.println(res.toString());
        }
    
        @Override
        public void onError(Exception e) {
            System.out.println("e = [" + e.getMessage() + "]");
        }
    });

    查询时对Cloud返回的结果做了一下解析,由Json数组转为了Json对象数组,如下:

     {"data":[
        {"FID":"100477","FDocumentStatus":"D"},
        {"FID":"100655","FDocumentStatus":"D"},
        {"FID":"100685","FDocumentStatus":"D"}
     ]}
  3. 保存这类需要提交数据的操作,需要自己构建Json对象,对Json的使用方面,依赖了谷歌的Gson。这里演示一下Save操作的请求。

     K3Client client = K3Client.getInstance();
     JsonObject object = new JsonObject();
     SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
     String d = format.format(new Date());
     object.addProperty("FCreateDate", d);
     JsonObject FDirectorPost = new JsonObject();
     FDirectorPost.addProperty("FNUMBER", "GW000383");
     object.add("FDirectorPost", FDirectorPost);
     JsonArray FEntity = new JsonArray();
     JsonObject row = new JsonObject();
     row.addProperty("FEvaContent", "这个月要干的事");
     row.addProperty("FEvaDetail", "还挺多的");
     row.addProperty("FWeight", 100);
     row.addProperty("FNote", "备个注");
     FEntity.add(row);
     object.add("FEntity", FEntity);
     SaveParam saveParam = new SaveParam.Builder()
             .setFormId("ora_Task_PersonalReport")
             .setModel(object)
             .build();
     client.postRequestAsync(saveParam, new K3Response() {
         @Override
         public void onSuccess(JsonObject res) {
             System.out.println("res : " + res.toString());
         }
    
         @Override
         public void onError(Exception e) {
             System.out.println("e = [" + e + "]");
         }
     });

    这是对一个二开单据工作计划的保存,方法不够优雅,建议使用时创建对应的实体类,利用Gson将实体类转为JsonObject。

  4. Others:

    其他操作的用法类似。

  5. 如果不想使用异步回调,可以这么调用:

     K3Client client = K3Client.getInstance();
     ViewParam viewParam = new ViewParam.Builder()
             .setFormId("ora_CRM_Niche")
             .setNumber("")
             .build();
     try {
         JsonObject res = client.postRequest(viewParam);
         System.out.println(res.toString());
     } catch (Exception e) {
         System.out.println("e = [" + e.getMessage() + "]");
     }
  6. 就这么多了...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.