andfxsso.html 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  5. <meta charset="UTF-8">
  6. <title></title>
  7. <script src="../o2_core/o2.min.js"></script>
  8. <script src="js/sso.min.js"></script>
  9. <script>
  10. o2.addReady(function(){
  11. var requestJson = function ( root, path, successCallback, failureCallback, errorCallback, method ) {
  12. var locate = window.location;
  13. var protocol = locate.protocol;
  14. var addressObj, address;
  15. var defaultPort = layout.config.app_protocol==='https' ? "443" : "80";
  16. if( root === "x_program_center" ){
  17. addressObj = layout.centerServer;
  18. var appPort = addressObj.port || window.location.port;
  19. address = protocol+"//"+(addressObj.host || window.location.hostname)+((!appPort || appPort.toString()===defaultPort) ? "" : ":"+appPort)+ "/x_program_center";
  20. }else{
  21. addressObj = layout.serviceAddressList[root];
  22. var appPort = addressObj.port || window.location.port;
  23. address = protocol+"//"+(addressObj.host || window.location.hostname)+((!appPort || appPort.toString()===defaultPort) ? "" : ":"+appPort)+addressObj.context;
  24. }
  25. var res = new Request.JSON({
  26. url: o2.filterUrl(address+ path),
  27. secure: false,
  28. method: method || "GET",
  29. noCache: true,
  30. withCredentials: true,
  31. onSuccess: function(responseJSON, responseText){
  32. if( successCallback )successCallback( responseJSON, responseText );
  33. }.bind(this),
  34. onFailure: function(xhr){
  35. if( failureCallback )failureCallback(xhr)
  36. }.bind(this),
  37. onError: function(text, error){
  38. if( errorCallback )errorCallback(text, error)
  39. }.bind(this)
  40. });
  41. res.send();
  42. }
  43. var who = function( unloginCallback, loginCallback, failureCallback){
  44. requestJson(
  45. "x_organization_assemble_authentication",
  46. "/jaxrs/authentication",
  47. function(responseJSON, responseText){
  48. if( responseJSON.data.tokenType === "anonymous" ){
  49. unloginCallback()
  50. }else{
  51. loginCallback()
  52. }
  53. }.bind(this),
  54. function(xhr){
  55. failureCallback()
  56. }.bind(this),
  57. function(text, error){
  58. failureCallback()
  59. }.bind(this)
  60. );
  61. };
  62. var login = function(){
  63. var uri = new URI(window.location.toString());
  64. var token = uri.getData("token");
  65. var enterId = uri.getData("enterId");
  66. // var redirect = uri.getData("redirect");
  67. var loginCallback = function (token, enterId) {
  68. requestJson(
  69. "x_organization_assemble_authentication",
  70. "/jaxrs/andfx/moa/sso/token/"+token+"/enter/"+enterId+"&date="+(new Date()).getTime(),
  71. function(responseJSON, responseText){
  72. var result = responseJSON.data.id;
  73. if(result){
  74. redirectTo();
  75. }else{
  76. $("ssoerror").set("html","单点失败!"+responseJSON.message + "<br/>地址:" + window.location).show();
  77. }
  78. }.bind(this),
  79. function(xhr){
  80. var json = JSON.parse(xhr.responseText);
  81. $("ssoerror").set("html", "单点登录失败: " + json.message + "<br/>" + (json.prompt || "") + "<br/>地址:" + window.location ).show();
  82. }.bind(this),
  83. function(text, error){
  84. $("ssoerror").set("html", text + "<br/>地址:" + window.location).show();
  85. }.bind(this)
  86. );
  87. };
  88. //调用
  89. function feixinGetTokenFun() {
  90. var param = {
  91. backid: 'deliveryToken',
  92. backFunc: 'deliveryToken' //回调方法
  93. };
  94. if (window.WebContainer && window.WebContainer.feixinGetToken){ //Android
  95. window.WebContainer.feixinGetToken(JSON.stringify(param))
  96. } else if ( window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.feixinGetToken) {
  97. window.webkit.messageHandlers.feixinGetToken.postMessage(param)
  98. } else if (navigator && navigator.WebContainer && navigator.WebContainer.feixinGetToken) {
  99. navigator.WebContainer.feixinGetToken(JSON.stringify(param))
  100. } else {
  101. $("ssoerror").set("html","单点失败,无token api!" + "<br/>地址:" + window.location).show();
  102. }
  103. }
  104. //if ( enterId ){
  105. if( enterId && token ){
  106. loginCallback( token, enterId )
  107. }else{
  108. //回调方法
  109. window.deliveryToken = function(info){
  110. if( info ){
  111. loginCallback(info, enterId);
  112. }else{
  113. $("ssoerror").set("html","单点失败,通过API未获取到token!" + "<br/>地址:" + window.location).show();
  114. }
  115. }
  116. feixinGetTokenFun();
  117. }
  118. // }else{
  119. // $("ssoerror").set("html","单点失败,enterId为空!" + "<br/>地址:" + window.location).show();
  120. // }
  121. };
  122. function isMobile() {
  123. debugger;
  124. return o2.session.isMobile;
  125. // let userAgentInfo = navigator.userAgent;
  126. // let Agents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod'];
  127. // let getArr = Agents.filter(function(i){
  128. // return userAgentInfo.indexOf(i) > -1;
  129. // });
  130. // return getArr.length ? true : false;
  131. }
  132. var gotoPage = function (uri) {
  133. history.replaceState(null, "gotoPage", uri);
  134. document.location.href = uri;
  135. };
  136. var redirectTo = function(){
  137. var uri = new URI(window.location.toString());
  138. var redirect = uri.getData("redirect");
  139. if (redirect){
  140. gotoPage( redirect );
  141. }else{
  142. if( isMobile() ){
  143. requestJson(
  144. "x_program_center",
  145. "/jaxrs/appstyle/index/portal",
  146. function(responseJSON, responseText){
  147. var data = responseJSON.data;
  148. if( data && data.value ){
  149. // var url = "../x_desktop/portalmobile.html?id="+data.value;
  150. // if( data.indexPage ){
  151. // url = url + "&page=" + loginPage.page;
  152. // }
  153. gotoPage( "../x_desktop/portalmobile.html?id="+data.value );
  154. }else{
  155. gotoPage( "../x_desktop/appMobile.html?app=process.TaskCenter" );
  156. }
  157. }.bind(this),
  158. function(xhr){
  159. gotoPage( "../x_desktop/appMobile.html?app=process.TaskCenter");
  160. }.bind(this),
  161. function(text, error){
  162. gotoPage( "../x_desktop/appMobile.html?app=process.TaskCenter" );
  163. }.bind(this)
  164. );
  165. }else{
  166. gotoPage( "../x_desktop/index.html" );
  167. }
  168. }
  169. };
  170. o2.JSON.get("res/config/config.json", function(config){
  171. if (config.proxyCenterEnable){
  172. if (o2.typeOf(config.center)==="array"){
  173. config.center.forEach(function(c){
  174. c.port = window.location.port || 80;
  175. })
  176. }else{
  177. config.port = window.location.port || 80;
  178. }
  179. }
  180. layout.config = config;
  181. getServiceAddress(config, function(){
  182. //debugger;
  183. //console.log(window.location);
  184. who( login, redirectTo, login)
  185. });
  186. });
  187. });
  188. function buttonLogin() {
  189. who( login, redirectTo, login)
  190. }
  191. </script>
  192. </head>
  193. <body style="background: rgb(239, 239, 244);">
  194. <div id="ssoerror" style="text-align:center;line-height: 30px;word-break: break-all;display:none;">单点失败,请联系管理员!</div>
  195. <button onclick="buttonLogin()"></button>
  196. </body>
  197. </html>