91a5dce71cd4f39d59be69a1398fae775b1e4662.svn-base 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package com.kingdee.customer.Auth.handler;
  2. import java.io.IOException;
  3. import java.sql.SQLException;
  4. import java.util.HashMap;
  5. import java.util.Map;
  6. import java.util.Set;
  7. import javax.servlet.ServletException;
  8. import javax.servlet.http.HttpServlet;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. import javax.servlet.http.HttpSession;
  12. import java.util.Base64;
  13. import com.aliyun.odps.utils.StringUtils;
  14. import com.kingdee.bos.BOSException;
  15. import com.kingdee.bos.Context;
  16. import com.kingdee.eas.cp.eip.sso.util.CloudParamUtil;
  17. import com.kingdee.eas.util.app.DbUtil;
  18. import com.kingdee.jdbc.rowset.IRowSet;
  19. import org.slf4j.Logger;
  20. import org.slf4j.LoggerFactory;
  21. public class TestServlet extends HttpServlet {
  22. private final Logger logger = LoggerFactory.getLogger(TestServlet.class);
  23. public TestServlet() {
  24. super();
  25. }
  26. /**
  27. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  28. */
  29. @Override
  30. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  31. logger.error("into TestServlet.doGet");
  32. //标准版流程助手
  33. String url = "http://bos.kingdee.com/workflow/main.html?";
  34. String wfversion = request.getParameter("wfversion");
  35. String storeEid = request.getParameter("storeEid");
  36. //移动bos版本流程助手,客户有使用移动bos可使用这个版本
  37. //if("mbos".equals(wfversion)){
  38. /**
  39. * https://mbos.kdeascloud.com/mbos/page/loadPage?
  40. * path=cmpSubmit88sp1&name=submitbill.editui
  41. * &lczstype=list&cometype=havedo&billID=SPKUhmbQSQifgjFU2ESznbEdulw%3D
  42. * &assignId=22910d25-d1b4-425c-9e87-eaa287f438b6WFWKITEM
  43. * &fprocinstid=653327bb-c464-4472-aa8d-c60b35000674WFPCINST
  44. * &operateState=VIEW&lczsapprove=9444be02b9d40929508ff587f216a64e&canChangeLanguage=1
  45. * &eid=ww434cb2a638701cdd&appid=10036
  46. *
  47. * https://mbos.kdeascloud.com/mbos/page/loadPage?storeEid=21231
  48. * &path=lczs2&name=approveui.navui
  49. *
  50. * &eid=ww434cb2a638701cdd&appid=10036
  51. * &token=ZmVuZy5jaGVu
  52. *
  53. *
  54. *
  55. * &cometype=todo&assignId=22910d25-d1b4-425c-9e87-eaa287f438b6WFWKITEM
  56. *
  57. *
  58. */
  59. /**
  60. * https://mbos.kdeascloud.com/mbos/page/loadPage?
  61. * * path=cmpSubmit88sp1&name=submitbill.editui
  62. * * &lczstype=list&cometype=havedo&billID=SPKUhmbQSQifgjFU2ESznbEdulw%3D
  63. * * &assignId=22910d25-d1b4-425c-9e87-eaa287f438b6WFWKITEM
  64. * * &fprocinstid=653327bb-c464-4472-aa8d-c60b35000674WFPCINST
  65. * * &operateState=VIEW&lczsapprove=9444be02b9d40929508ff587f216a64e&canChangeLanguage=1
  66. *
  67. *
  68. */
  69. //url = "https://mbos.kdeascloud.com/mbos/page/loadPage?storeEid=21231&path=lczs2&name=approveui.navui";
  70. //TODO:加入的代码拼接跳转的参数
  71. String assignmentId = "";
  72. HttpSession session = request.getSession();
  73. if (session != null) {
  74. Map<String, String> assignmentMap = (Map) session.getAttribute("assignment");
  75. if (assignmentMap != null && assignmentMap.size() > 0) {
  76. assignmentId = assignmentMap.get("assignmentId");
  77. logger.info("onSuccessfulValidation......assignmentId:" + assignmentId);
  78. }
  79. }
  80. String billId = "";
  81. String fprocinstid = "";
  82. try {
  83. Map<String,String> paramMap = getParamMapByAssignId(assignmentId);
  84. billId = paramMap.get("billId");
  85. fprocinstid = paramMap.get("fprocinstid");
  86. } catch (BOSException e) {
  87. logger.error("TestServlet.doGet" + e.getMessage());
  88. throw new ServletException(e.getMessage());
  89. }
  90. url = "https://mbos.kdeascloud.com/mbos/page/loadPage?path=cmpSubmit88sp1&name=submitbill.editui&lczstype=list&billID="+billId+"&fprocinstid="+fprocinstid+"&operateState=VIEW&lczsapprove=9444be02b9d40929508ff587f216a64e&canChangeLanguage=1";
  91. if (storeEid != null && !"".equals(storeEid) && !"null".equals(storeEid)) {
  92. url = url.replace("storeEid=21231", "storeEid=" + storeEid);
  93. }
  94. //}
  95. Map<String, String> infoMap = encryptUserInfo(request);
  96. Set<String> keySet = infoMap.keySet();
  97. for (String key : keySet) {
  98. url += "&" + key + "=" + infoMap.get(key);
  99. }
  100. url = url.replace("?&", "?");
  101. url += "&cometype=havedo&assignId=" + assignmentId;
  102. logger.info("OtherAppPortalServlet.doget.url:" + url);
  103. response.sendRedirect(url);
  104. }
  105. @Override
  106. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  107. // TODO Auto-generated method stub
  108. doGet(request, response);
  109. }
  110. /**
  111. * accessurl
  112. * 如果第三方app点击链接带token,这方法可以不写,将流程助手主页作为应用url,getLoginInfoByToken中根据第三方app的token解析到用户信息即可
  113. * 如果第三方app点击链接不带token,将此接口作为应用的url,方法内获取第三方app用户对应的eas用户信息,方法返回值resultMap存跳转到流程助手的参数
  114. * http://localhost:8080/otherapp/index?eid=21231&appid=10036&param=zhangsan
  115. */
  116. public Map<String, String> encryptUserInfo(HttpServletRequest request) {
  117. HashMap<String, String> resultMap = new HashMap<String, String>();
  118. String param = request.getParameter("param");
  119. //下面三个参数为跳转流程助手主页参数
  120. String eid = request.getParameter("eid");
  121. String appid = request.getParameter("appid");
  122. String token = "";
  123. //........根据第三方app传来的参数,取到eas用户信息
  124. try {
  125. token = encrypt_Base64(param);
  126. } catch (Exception e) {
  127. logger.error("encryptUserInfo encrypt_Base64 Exception" + e.getMessage());
  128. e.printStackTrace();
  129. }
  130. logger.info("encryptUserInfo.token:"+token);
  131. resultMap.put("eid", eid);
  132. resultMap.put("appid", appid == null ? "10036" : appid);
  133. resultMap.put("token", token);
  134. return resultMap;
  135. }
  136. /***
  137. * Base64加密
  138. * @param str 需要加密的参数
  139. * @return
  140. * @throws Exception
  141. */
  142. private static String encrypt_Base64(String str) throws Exception {
  143. if(StringUtils.isEmpty(str)){
  144. return "";
  145. }
  146. String result = Base64.getEncoder().encodeToString(str.getBytes("UTF-8"));
  147. return result;
  148. }
  149. /**
  150. * 通过assignId 查询出billId 和fprocinstId
  151. * @param assignId
  152. * @return
  153. */
  154. private Map<String,String> getParamMapByAssignId(String assignId) throws BOSException {
  155. Map<String,String> paramMap = new HashMap<String,String>();
  156. String dataCenter=ConfigAddressServletUtil.getProperty("dataCenter");
  157. String locale=ConfigAddressServletUtil.getProperty("locale");
  158. Context ctx = CloudParamUtil.getContext(dataCenter, locale, "administrator");
  159. String sql = "select fbizobjid as billId,fprocinstid from t_wfr_assign where fassignid = '"+assignId+"'";
  160. String billId = "";
  161. String fprocinstid = "";
  162. try {
  163. IRowSet result = DbUtil.executeQuery(ctx, sql);
  164. while (result.next()) {
  165. billId = result.getString("billId");
  166. fprocinstid = result.getString("fprocinstid");
  167. paramMap.put("billId",billId);
  168. paramMap.put("fprocinstid",fprocinstid);
  169. }
  170. } catch (SQLException e) {
  171. throw new BOSException(e);
  172. }
  173. return paramMap;
  174. }
  175. }