appMobileConnectCheck.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <!DOCTYPE html>
  2. <html>
  3. <head lang="en">
  4. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  5. <link rel="stylesheet" type="text/css" href="../x_desktop/css/style.css" charset="UTF-8" />
  6. <link rel="stylesheet" href="../x_desktop/css/mBoxNotice.css" charset="UTF-8" />
  7. <link rel="stylesheet" href="../x_desktop/css/mBoxTooltip.css" charset="UTF-8" />
  8. <script src="../o2_core/o2.min.js"></script>
  9. <script src="js/base_simple_anonymous.js"></script>
  10. <title>移动App访问检查</title>
  11. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  12. <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
  13. <meta content="yes" name="apple-mobile-web-app-capable" />
  14. <meta content="black" name="apple-mobile-web-app-status-bar-style" />
  15. <meta content="telephone=no" name="format-detection" />
  16. </head>
  17. <body style="height: 100%;overflow: auto; margin:0px;display: block;">
  18. <div id="errorArea" style="margin: 30px 20px; word-break: break-all;display: none;">
  19. </div>
  20. <div id="centerArea" style="margin: 30px 20px; word-break: break-all;">
  21. </div>
  22. <div id="appArea" style="margin: 30px 20px; word-break: break-all;">
  23. </div>
  24. <div id="contentArea" style="margin: 30px 20px; word-break: break-all;">
  25. </div>
  26. <script>
  27. layout.addReady(function(){
  28. (function(layout){
  29. //var uri = new URI(window.location.href);
  30. var hostname = window.location.hostname;
  31. console.log(hostname)
  32. var _showJson = function(json) {
  33. if (json) {
  34. var jsonstr=JSON.stringify(json, null, 2);
  35. var divNode = new Element("div", {
  36. styles:{
  37. "margin": "10px",
  38. "color": "#666666"
  39. },
  40. html: "返回数据:"
  41. }).inject( $("contentArea") );
  42. new Element("pre", {html: jsonstr}).inject(divNode);
  43. }
  44. };
  45. var _showError = function(error, json) {
  46. var errorNode = new Element("div", {
  47. styles:{
  48. "margin": "10px",
  49. "color": "#ff0000"
  50. }
  51. }).inject( $("errorArea") );
  52. $("errorArea").setStyle("display", "block");
  53. new Element("p", {"html": "错误,"+error}).inject(errorNode);
  54. };
  55. var _showSuccess = function(info,area) {
  56. new Element("div", {
  57. styles:{
  58. "margin": "10px",
  59. "color": "#5fbf78"
  60. },
  61. text: info
  62. }).inject( $(area) );
  63. };
  64. // 测试连接认证服务器
  65. var _loadAuthApp = function(authApp, webServer) {
  66. if (authApp && authApp.host && authApp.port) {
  67. var protocal = "http://";
  68. if (webServer && webServer.sslEnable == true) {
  69. protocal = "https://";
  70. }
  71. var url =protocal+authApp.host+":"+authApp.port+"/x_organization_assemble_authentication/jaxrs/echo";
  72. o2.xhr_get(url, function(json) {
  73. console.log(json);
  74. if (json && json.response) {
  75. var res = JSON.parse(json.response);
  76. if (res && res.type == "success") {
  77. _showSuccess("连接应用服务器成功!", "appArea");
  78. return;
  79. }
  80. }
  81. _showError("获取应用服务器地址信息失败!");
  82. }, function(err){
  83. _showError("获取应用服务器地址信息失败!");
  84. });
  85. } else {
  86. _showError("获取应用服务器失败!");
  87. }
  88. };
  89. // 测试连接中心服务器
  90. var _loadCenter = function() {
  91. o2.Actions.load("x_program_center").DistributeAction.assembleWithWebServer(hostname, function(json){
  92. // 中心服务器连接成功
  93. _showSuccess("中心服务器连接成功", "centerArea");
  94. if (json && json.type === "success") {
  95. if (json.data && json.data.assembles) {
  96. _loadAuthApp(json.data.assembles.x_organization_assemble_authentication, json.data.webServer);
  97. _showJson(json);
  98. } else {
  99. // 应用服务器获取不到
  100. _showError("获取应用服务器失败!");
  101. _showJson(json);
  102. }
  103. } else {
  104. // 获取地址信息失败
  105. _showError("获取中心服务器地址信息失败!");
  106. _showJson(json);
  107. }
  108. }.bind(this), function(err){
  109. _showError("获取中心服务器地址信息失败!");
  110. _showJson(err);
  111. }.bind(this));
  112. };
  113. _loadCenter();
  114. })(layout);
  115. });
  116. </script>
  117. </body>
  118. </html>