oauth.html 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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_lib/Decimal.js"></script>
  14. <script src="js/base_simple_anonymous.js"></script>
  15. <script>
  16. layout.addReady(function(){
  17. (function(layout){
  18. var uri = new URI(window.location.href);
  19. var locate = window.location;
  20. var protocol = locate.protocol;
  21. var href = locate.href;
  22. //var uri = new URI(href);
  23. var oauth = uri.getData("oauth");
  24. var redirect = uri.getData("redirect");
  25. var code = uri.getData("code");
  26. var method = uri.getData("method");
  27. var _load = function(){
  28. if (code) {
  29. layout.loginOauth();
  30. } else if (oauth) {
  31. layout.loadOauth();
  32. }
  33. };
  34. layout.loginOauth = function () {
  35. var r = protocol + "//" + location.host + location.pathname;
  36. r = r + "?oauth=" + oauth;
  37. if (redirect) r = r + "&redirect=" + redirect;
  38. r = o2.filterUrl(r);
  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), function(){
  71. document.write("<div style='text-align: center; font-size: 24px; margin: 40px auto;'>无法获取用户凭证, 您可能未绑定“"+oauth+"”账号。</div>");
  72. document.write("<div style='text-align: center; font-size: 18px; margin: 40px auto;'>请<a href='../x_desktop/redirect.html?url="+encodeURIComponent("../x_desktop/oauth.html?oauth="+oauth+"&redirect=/&method=oauthBind")+"'>点击此处登陆</a>后,重新扫码绑定账号。</div>")
  73. });
  74. }
  75. };
  76. layout.loadOauth = function () {
  77. var action = MWF.Actions.get("x_organization_assemble_authentication");
  78. //企业微信单点登录
  79. if (layout.isQywx()) {
  80. action.qywxOauthServer(function (json) {
  81. var qywxConfig = json.data || {};
  82. var qrConnectAddress = qywxConfig.qrConnectAddress || "https://open.work.weixin.qq.com";
  83. var url = qrConnectAddress + "/wwopen/sso/qrConnect?state=STATE";
  84. var corpId = qywxConfig.corpId;
  85. if (corpId) {
  86. url += "&appid=" + corpId;
  87. }
  88. var agentId = qywxConfig.agentId;
  89. if (agentId) {
  90. url += "&agentid=" + agentId;
  91. }
  92. var r = protocol + "//" + location.host + location.pathname;
  93. r = r + "?oauth=" + oauth + "&qywx=true";
  94. url += "&redirect_uri=" + encodeURIComponent(r);
  95. window.location = url;
  96. }.bind(this));
  97. } else if (layout.isDingding()) { //钉钉单点登录
  98. action.dingdingOauthServer(function (json) {
  99. var dingdingConfig = json.data || {};
  100. var oapiAddress = dingdingConfig.oapiAddress || "https://oapi.dingtalk.com";
  101. var url = oapiAddress + "/connect/qrconnect?response_type=code&scope=snsapi_login&state=STATE";
  102. var appId = dingdingConfig.scanLoginAppId;
  103. if (appId) {
  104. url += "&appid=" + appId;
  105. }
  106. var r = protocol + "//" + location.host + location.pathname;
  107. r = r + "?oauth=" + oauth + "&dingding=true";
  108. r = o2.filterUrl(r);
  109. url += "&redirect_uri=" + encodeURIComponent(r);
  110. window.location = url;
  111. }.bind(this));
  112. } else {
  113. action.getOauthServer(oauth, function (json) {
  114. var url = json.data.authAddress;
  115. var p = json.data.authParameter;
  116. var r = protocol + "//" + location.host + location.pathname;
  117. r = r + "?oauth=" + oauth;
  118. if (method) r = r + "&method=" + method;
  119. if (redirect) r = r + "&redirect=" + redirect;
  120. r = o2.filterUrl(r);
  121. if (p.indexOf("{$redirect_uri}")!==-1){
  122. p = p.replace("{$redirect_uri}", encodeURIComponent(r));
  123. }else{
  124. p = (p) ? p + "&redirect_uri=" + encodeURIComponent(r) : "&redirect_uri=" + encodeURIComponent(r);
  125. }
  126. url = (url.indexOf("?" === -1)) ? url + "?" + p : url + "&" + p;
  127. window.location = url;
  128. }.bind(this));
  129. }
  130. };
  131. layout.isQywx = function () {
  132. var qywx = uri.getData("qywx");
  133. if (qywx) {
  134. return true;
  135. } else {
  136. return false;
  137. }
  138. };
  139. layout.isDingding = function () {
  140. var dingding = uri.getData("dingding");
  141. if (dingding) {
  142. return true;
  143. } else {
  144. return false;
  145. }
  146. };
  147. _load();
  148. })(layout);
  149. });
  150. </script>
  151. <script src="../o2_lib/mootools/mootools-1.6.0.min.js"></script>
  152. </head>
  153. <body>
  154. <!--<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);">-->
  155. <!--<div id="layout" style="overflow: auto; height:100%"></div>-->
  156. </body>
  157. </html>