oauth.html 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <!DOCTYPE html>
  2. <html xml:lang="zh-CN" style="height: 100%;">
  3. <head lang="en">
  4. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  5. <meta charset="UTF-8">
  6. <title></title>
  7. <link rel="stylesheet" type="text/css" href="css/style.css" charset="UTF-8" />
  8. <link rel="stylesheet" href="css/mBoxNotice.css" charset="UTF-8" />
  9. <link rel="stylesheet" href="css/mBoxTooltip.css" charset="UTF-8" />
  10. <!-- <script src="res/framework/mootools/mootools-core-1.4.5-full-nocompat.js"></script>-->
  11. <!-- <script src="res/framework/mootools/mootools-more-1.4.0.1-all_2.js"></script>-->
  12. <script src="../o2_core/o2.min.js"></script>
  13. <script src="../o2_core/compatible.min.js"></script>
  14. <script src="../o2_lib/Decimal.js"></script>
  15. <script>
  16. o2.addReady(function () {
  17. layout = window.layout || {};
  18. layout.desktop = layout;
  19. o2.xDesktop = o2.xDesktop || {};
  20. var locate = window.location;
  21. var protocol = locate.protocol;
  22. var href = locate.href;
  23. var uri = new URI(href);
  24. var oauth = uri.getData("oauth");
  25. var redirect = uri.getData("redirect");
  26. var code = uri.getData("code");
  27. var method = uri.getData("method");
  28. layout.load = function () {
  29. if (code) {
  30. layout.loginOauth();
  31. } else if (oauth) {
  32. layout.loadOauth();
  33. }
  34. };
  35. layout.loginOauth = function () {
  36. var r = protocol + "//" + location.host + location.pathname;
  37. r = r + "?oauth=" + oauth;
  38. if (redirect) r = r + "&redirect=" + redirect;
  39. var action = MWF.Actions.get("x_organization_assemble_authentication");
  40. //企业微信单点登录
  41. if (layout.isQywx()) {
  42. action["loginOauthQywxServer"](code, function () {
  43. if (redirect) {
  44. window.location = redirect;
  45. } else {
  46. window.location = "/";
  47. }
  48. }.bind(this));
  49. } else if (layout.isDingding()) {
  50. action["loginOauthDingdingServer"](code, function () {
  51. if (redirect) {
  52. window.location = redirect;
  53. } else {
  54. window.location = "/";
  55. }
  56. }.bind(this));
  57. } else {
  58. var logMethod = method || "loginOauthServer";
  59. action[logMethod](oauth, code, encodeURIComponent(r), function () {
  60. if (method === "oauthBind") {
  61. alert("用户绑定已成功!");
  62. window.close();
  63. } else {
  64. if (redirect) {
  65. window.location = redirect;
  66. } else {
  67. window.location = "/";
  68. }
  69. }
  70. }.bind(this));
  71. }
  72. };
  73. layout.loadOauth = function () {
  74. var action = MWF.Actions.get("x_organization_assemble_authentication");
  75. //企业微信单点登录
  76. if (layout.isQywx()) {
  77. action.qywxOauthServer(function (json) {
  78. var qywxConfig = json.data || {};
  79. var url = "https://open.work.weixin.qq.com/wwopen/sso/qrConnect?state=STATE";
  80. var corpId = qywxConfig.corpId;
  81. if (corpId) {
  82. url += "&appid=" + corpId;
  83. }
  84. var agentId = qywxConfig.agentId;
  85. if (agentId) {
  86. url += "&agentid=" + agentId;
  87. }
  88. var r = protocol + "//" + location.host + location.pathname;
  89. r = r + "?oauth=" + oauth + "&qywx=true";
  90. url += "&redirect_uri=" + encodeURIComponent(r);
  91. window.location = url;
  92. }.bind(this));
  93. } else if (layout.isDingding()) { //钉钉单点登录
  94. action.dingdingOauthServer(function (json) {
  95. var dingdingConfig = json.data || {};
  96. var url = "https://oapi.dingtalk.com/connect/qrconnect?response_type=code&scope=snsapi_login&state=STATE";
  97. var appId = dingdingConfig.scanLoginAppId;
  98. if (appId) {
  99. url += "&appid=" + appId;
  100. }
  101. var r = protocol + "//" + location.host + location.pathname;
  102. r = r + "?oauth=" + oauth + "&dingding=true";
  103. url += "&redirect_uri=" + encodeURIComponent(r);
  104. window.location = url;
  105. }.bind(this));
  106. } else {
  107. action.getOauthServer(oauth, function (json) {
  108. var url = json.data.authAddress;
  109. var p = json.data.authParameter;
  110. var r = protocol + "//" + location.host + location.pathname;
  111. r = r + "?oauth=" + oauth;
  112. if (method) r = r + "&method=" + method;
  113. if (redirect) r = r + "&redirect=" + redirect;
  114. p = (p) ? p + "&redirect_uri=" + encodeURIComponent(r) : "&redirect_uri=" + encodeURIComponent(r);
  115. url = (url.indexOf("?" === -1)) ? url + "?" + p : url + "&" + p;
  116. window.location = url;
  117. }.bind(this));
  118. }
  119. };
  120. layout.isQywx = function () {
  121. var qywx = uri.getData("qywx");
  122. if (qywx) {
  123. return true;
  124. } else {
  125. return false;
  126. }
  127. };
  128. layout.isDingding = function () {
  129. var dingding = uri.getData("dingding");
  130. if (dingding) {
  131. return true;
  132. } else {
  133. return false;
  134. }
  135. };
  136. MWF.loadLP("zh-cn");
  137. MWF.require("MWF.xDesktop.Common", null, false);
  138. MWF.require("MWF.xAction.RestActions", null, false);
  139. o2.load(["../o2_lib/mootools/plugin/mBox.Notice.js", "../o2_lib/mootools/plugin/mBox.Tooltip.js"], { "sequence": true }, function () {
  140. o2.JSON.get("res/config/config.json", function (config) {
  141. layout.config = config;
  142. MWF.xDesktop.getServiceAddress(config, function (service, center) {
  143. layout.serviceAddressList = service;
  144. layout.centerServer = center;
  145. layout.load();
  146. }.bind(this));
  147. }.bind(this));
  148. });
  149. //});
  150. });
  151. </script>
  152. <script src="../o2_lib/mootools/mootools-1.6.0.min.js"></script>
  153. </head>
  154. <body>
  155. <!--<body bgcolor="#faebd7" bgcolor="#ffc0cb" style="height: 100%; overflow: auto; margin:0px; background-size: cover; background-image: url(res/mwf4/package/xDesktop/$Layout/default/desktop.jpg);">-->
  156. <!--<div id="layout" style="overflow: auto; height:100%"></div>-->
  157. </body>
  158. </html>