云之家智能审批推送EAS(SHR)之完全解读(一)原创
金蝶云社区-BobbyLIU
BobbyLIU
9人赞赏了该文章 1,678次浏览 未经作者许可,禁止转载编辑于2022年06月27日 10:59:53

最近接了一个项目,用户需要把云之家智能审批数据推送到shr系统。由于之前未做过类似的项目,因此对此做了一个详细的研究。并最终解决。

前提分析:

1、云之家智能审批推送只支持http推送方式,也就是我们常说的open api的方式。这种方式的一个特点就是传送过来的数据是(HttpServletRequest request, HttpServletResponse response)形式。

2、EAS(shr)这边的话只支持webservice的方式,osf方式我们我们下一条再讨论。webservice的方式接收数据的话他只有一个json字符串的形式,对于openapi传过来的数据无法解析。

3、shr也支持一种形式的open api接口,这就是osf,但是有个点,就是参数是固定的,然后如果数据进来的话需要登录等一些参数的设置,这样的话就不能匹配云之家的openapi方式。

解决方法:

在经历张上述方式的测试研究。最终我们只能采取一种最保险,也绝对可行的方式,就是搭建一个外部接口,通过外部接口去转化并对接云之家。

当然这个接口的搭建也不是很简单。

首先我们要创建一个tomcat服务,通过tomcat服务,我们建立起api的接口,用来接收云之家那边传过来的数据,并且在这个接口中,我们可以自己随意实现对eas这边接口的数据登录,数据传送等操作。这样我们就可以轻松的解决。

话不多说,上一段关键代码。后续如有疑问可以私信我。

public void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

System.out.println("******shr云之家接口接口开始调用******");

try (InputStream is = request.getInputStream()) {

            byte[] buf = new byte[2048];

            int length = -1;


            // 读取请求参数

            ByteArrayOutputStream baos = new ByteArrayOutputStream();

            while ((length = is.read(buf)) > 0) {

                baos.write(buf, 0, length);

            }

            String data = baos.toString("utf-8");

            

            Configuration configuration = new Configuration();

            configuration.setCloudflowKey(CloudflowKey);

            configuration.setCloudflowAppId(CloudflowAppId);

            configuration.setCloudflowSecret(CloudflowSecret);         

            configuration.setEid(Eid);

            configuration.setHost(Host);

            com.eas.kingdee.AESEncryptor encryptor = new com.eas.kingdee.AESEncryptor(configuration.getCloudflowKey());

            String plainText = encryptor.decrypt(data);

            System.out.println("解密数据==>" + plainText);

            

            String rtn = "fail";

JSONObject jsonOther=JSONObject.fromObject(plainText);

if(jsonOther != null) {

EASLoginProxy proxy = null;

try {

WSContext ctx = login();

System.out.println("用户已经登录==>"+jsonOther.toString());

if(ctx!=null) {

WSCloudHouseFacadeSrvProxyServiceLocator locator = new WSCloudHouseFacadeSrvProxyServiceLocator();

//正式环境安全模式

URL portUrl = new URL("http://223.168.105.26:6992/ormrpc/services/WSCloudHouseFacade");

WSCloudHouseFacadeSrvProxy voucherProxy = locator.getWSCloudHouseFacade(portUrl);

((Stub) voucherProxy).setHeader("http://login.webservice.bos.kingdee.com","SessionId", ctx.getSessionId());

System.out.println("进入调用webserveice方法:");

String jsonResult = voucherProxy.importRequest(plainText, data);

System.out.println("调用返回值为:"+jsonResult);

rtn =jsonResult;

}

} catch (Exception e) {

System.out.println("WebService调用出错!");

e.printStackTrace();

}

finally {

if(proxy != null) {

try {

proxy.logout(USERNAME, SLNNAME, DCNAME, LANGUAGE);

}

catch (RemoteException e) {

e.printStackTrace();

}

}

}

System.out.println("中转服务调用shr云之家接口shr返回的json为"+rtn);

}

System.out.println(new Date()+"shr接口中转的返回结果为:"+plainText);

            response.getWriter().write("success");

            response.flushBuffer();

        } catch (IOException e) {

        System.out.println("WebService调用出错!");

e.printStackTrace();

        } catch (Exception e) {

// TODO Auto-generated catch block

        System.out.println("数据解码出错!");

e.printStackTrace();

}

}

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

this.doGet(request, response);

}


赞 9