فهرست منبع

对接OA用户认证、部门获取、人员获取

5 سال پیش
والد
کامیت
01a9420090

+ 29 - 0
pcbms/pom.xml

@@ -52,6 +52,35 @@
                 </exclusion>
             </exclusions>
         </dependency>
+        <!--以下三个依赖是一组-->
+        <!-- https://mvnrepository.com/artifact/org.apache.axis/axis -->
+        <dependency>
+            <groupId>org.apache.axis</groupId>
+            <artifactId>axis</artifactId>
+            <version>1.4</version>
+        </dependency>
+
+        <!-- https://mvnrepository.com/artifact/axis/axis-jaxrpc -->
+        <dependency>
+            <groupId>axis</groupId>
+            <artifactId>axis-jaxrpc</artifactId>
+            <version>1.4</version>
+        </dependency>
+
+        <!-- https://mvnrepository.com/artifact/wsdl4j/wsdl4j -->
+        <dependency>
+            <groupId>wsdl4j</groupId>
+            <artifactId>wsdl4j</artifactId>
+            <version>1.6.1</version>
+        </dependency>
+
+        <!-- https://mvnrepository.com/artifact/dom4j/dom4j -->
+        <dependency>
+            <groupId>dom4j</groupId>
+            <artifactId>dom4j</artifactId>
+            <version>1.6.1</version>
+        </dependency>
+
 
         <!-- mybatis-plus依赖 -->
         <dependency>

+ 1 - 0
pcbms/src/main/java/com/hssx/pcbms/constant/Constant.java

@@ -8,5 +8,6 @@ package com.hssx.pcbms.constant;
  */
 public class Constant {
     public static final String HANDLE_CONTENT = "将状态 oldState 改为 newState ";//处理资产类容前缀
+    public static final String APP_ID = "";//appid
 
 }

+ 173 - 2
pcbms/src/main/java/com/hssx/pcbms/controller/UserController.java

@@ -1,11 +1,19 @@
 package com.hssx.pcbms.controller;
 
 
+import com.hssx.pcbms.constant.Constant;
 import com.hssx.pcbms.entity.User;
 import com.hssx.pcbms.entity.vo.UserVO;
 import com.hssx.pcbms.service.UserService;
 import com.hssx.pcbms.util.HttpRespMsg;
 import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.axis.client.Call;
+import org.apache.axis.client.Service;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -15,6 +23,11 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.xml.rpc.ServiceException;
+import java.rmi.RemoteException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
 
 /**
  * <p>
@@ -26,6 +39,7 @@ import javax.servlet.http.HttpServletResponse;
  */
 @Controller
 @RequestMapping("/user")
+@Slf4j
 public class UserController {
 
     @Autowired
@@ -86,7 +100,7 @@ public class UserController {
     @RequestMapping("/update")
     @ResponseBody
     public HttpRespMsg update(User user, @RequestParam(required = false) MultipartFile file) {
-        HttpRespMsg msg = userService.updateUser(user,file);
+        HttpRespMsg msg = userService.updateUser(user, file);
         return msg;
     }
 
@@ -108,6 +122,7 @@ public class UserController {
     /**
      * 用户分配权限
      * id:用户id permissionIds:权限对应的ids集合字符串("1,2,3")
+     *
      * @return
      */
     @ApiOperation(value = "用户分配权限", notes = "角色分配权限方法")
@@ -115,8 +130,164 @@ public class UserController {
     @ResponseBody
     public HttpRespMsg handOutpermissions(User user, String permissionIds) {
         HttpRespMsg msg = new HttpRespMsg();
-        msg = userService.handOutpermissions(user,permissionIds);
+        msg = userService.handOutpermissions(user, permissionIds);
+        return msg;
+    }
+
+    /**
+     * 用户认证
+     * loginUser 用户名,token 身份凭证
+     *
+     * @return
+     */
+    @ApiOperation(value = "用户认证", notes = "用户认证方法")
+    @RequestMapping("/authentication")
+    @ResponseBody
+    public HttpRespMsg authentication(String loginUser, String token, HttpServletRequest request) throws ServiceException {
+        HttpRespMsg msg = new HttpRespMsg();
+        try {
+//            String params ="";
+            String appSessionId = request.getSession().getId();
+            String wsdlUrl = "http://127.0.0.1/plat/services/SyncBaseService";
+            String methodName = " getTicket";
+            String sResult = "";
+            if (wsdlUrl.indexOf("?wsdl") != -1) {
+                wsdlUrl = wsdlUrl.replaceAll("\\?wsdl", "");
+            }
+            Service service = new Service();
+            Call call = (Call) service.createCall();
+            call.setTargetEndpointAddress(new java.net.URL(wsdlUrl));
+            call.setOperationName(methodName);
+            log.debug("获取的系统同步数据");
+            log.debug("token==>" + token + "appSessionId==>" + appSessionId + "");
+            sResult = (String) call.invoke(new Object[]{token, Constant.APP_ID, appSessionId});
+            log.debug("通过webService同步返回的参数为:" + sResult);
+            Map<String, String> xmlAttribute = getXmlAttribute(sResult);
+            if(!loginUser.equals(xmlAttribute.get("loginName"))){
+                msg.setError("登录失败");
+                return msg;
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
         return msg;
     }
+    /**
+     * 调用同步部门接口
+     *  token //应用标识
+     * @return
+     */
+    @ApiOperation(value = "调用同步部门接口", notes = "调用同步部门接口方法")
+    @RequestMapping("/getSyncDeptJson")
+    @ResponseBody
+    public HttpRespMsg getSyncDeptJson(String loginUser, String token, HttpServletRequest request) throws ServiceException {
+        HttpRespMsg msg = new HttpRespMsg();
+        try {
+//            String params ="";
+            String ivKey = "";//随机秘钥
+            String timeStamp = "";//同步时间戳,如果为空则同步全部部门数据
+            String appSessionId = request.getSession().getId();
+            String wsdlUrl
+                    = "http://127.0.0.1/plat/services/SyncBaseService";
+            String methodName = " getSyncDeptJson";
+            String sResult = "";
+            if (wsdlUrl.indexOf("?wsdl") != -1) {
+                wsdlUrl = wsdlUrl.replaceAll("\\?wsdl", "");
+            }
+            Service service = new Service();
+            Call call = (Call) service.createCall();
+            call.setTargetEndpointAddress(new java.net.URL(wsdlUrl));
+            call.setOperationName(methodName);
+            log.debug("获取的系统同步数据");
+            log.debug("ivKey==>" + ivKey + "timeStamp==>" + timeStamp + "");
+            sResult = (String) call.invoke(new Object[]{Constant.APP_ID, ivKey,timeStamp});
+            log.debug("通过webService同步返回的参数为:" + sResult);
+            Map<String, String> xmlAttribute = getXmlAttribute(sResult);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return msg;
+    }
+    /**
+     * 调用同步用户接口
+     *  token //应用标识
+     * @return
+     */
+    @ApiOperation(value = "调用同步用户接口", notes = "调用同步用户接口方法")
+    @RequestMapping("/getSyncDeptJson")
+    @ResponseBody
+    public HttpRespMsg getSyncUserJson(String loginUser, String token, HttpServletRequest request) throws ServiceException {
+        HttpRespMsg msg = new HttpRespMsg();
+        try {
+//            String params ="";
+            String ivKey = "";//随机秘钥
+            String timeStamp = "";//同步时间戳,如果为空则同步全部部门数据
+            String appSessionId = request.getSession().getId();
+            String wsdlUrl
+                    = "http://127.0.0.1/plat/services/SyncBaseService";
+            String methodName = " getSyncUserJson";
+            String sResult = "";
+            if (wsdlUrl.indexOf("?wsdl") != -1) {
+                wsdlUrl = wsdlUrl.replaceAll("\\?wsdl", "");
+            }
+            Service service = new Service();
+            Call call = (Call) service.createCall();
+            call.setTargetEndpointAddress(new java.net.URL(wsdlUrl));
+            call.setOperationName(methodName);
+            log.debug("获取的系统同步数据");
+            log.debug("ivKey==>" + ivKey + "timeStamp==>" + timeStamp + "");
+            sResult = (String) call.invoke(new Object[]{Constant.APP_ID, ivKey,timeStamp});
+            log.debug("通过webService同步返回的参数为:" + sResult);
+            Map<String, String> xmlAttribute = getXmlAttribute(sResult);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return msg;
+    }
+
+    /**
+     * dom4j解析Xml
+     *
+     * @param xml
+     */
+    public static Map<String, String> getXmlAttribute(String xml) {
+        Map<String, String> map = new HashMap<>();
+        Document doc = null;
+        // 将字符串转为XML
+        try {
+            doc = DocumentHelper.parseText(xml);
+        } catch (DocumentException e) {
+            e.printStackTrace();
+        }
+        // 获取根节点
+        Element recordEle = doc.getRootElement();
+        System.out.println("根节点:" + recordEle.getName());
+        //拿取根节点下的子节点的内容
+        String ticketStr = recordEle.elementTextTrim("ticketId");
+        map.put("ticketId", ticketStr);
+        String loginName = recordEle.elementTextTrim("loginName");
+        map.put("loginName", loginName);
+        String guid = recordEle.elementTextTrim("guid");
+        map.put("guid", guid);
+        String pwd = recordEle.elementTextTrim("pwd");
+        map.put("pwd", pwd);
+        return map;
+    }
+
+    public static void main(String[] args) {
+        String xml = "<?xml version=\"1.0\" encoding=\"GBK\"?>" +
+                "<SsoTicket>" +
+                "<ticketId>" + "a8a950:14715319393:-8000" + "</ticketId>" +
+                "<loginName>test</loginName>" +
+                "<guid>9001</guid>" +
+                "<pwd>96E79218965EB72C92A549DD5A330112</pwd>" +
+                "</SsoTicket>";
+        Map<String, String> xmlAttribute = getXmlAttribute(xml);
+        for (Map.Entry<String, String> entry : xmlAttribute.entrySet()) {
+            String mapKey = entry.getKey();
+            String mapValue = entry.getValue();
+            System.out.println(mapKey + ":" + mapValue);
+        }
+    }
 }