oauth.html 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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" type="text/css" href="css/v10/root.css" charset="UTF-8" />
  9. <link rel="stylesheet" type="text/css" href="css/v10/style.css" id="oo-css-skin" charset="UTF-8" />
  10. <link rel="stylesheet" href="css/mBoxNotice.css" charset="UTF-8" />
  11. <link rel="stylesheet" href="css/mBoxTooltip.css" charset="UTF-8" />
  12. <!-- <script src="res/framework/mootools/mootools-core-1.4.5-full-nocompat.js"></script>-->
  13. <!-- <script src="res/framework/mootools/mootools-more-1.4.0.1-all_2.js"></script>-->
  14. <script src="../o2_core/o2.min.js"></script>
  15. <script src="../o2_lib/Decimal.js"></script>
  16. <script src="js/base_simple_anonymous.js"></script>
  17. <script>
  18. layout.addReady(function(){
  19. (function(layout){
  20. var uri = new URI(window.location.href);
  21. var locate = window.location;
  22. var protocol = locate.protocol;
  23. var href = locate.href;
  24. //var uri = new URI(href);
  25. var oauth = uri.getData("oauth");
  26. var redirect = uri.getData("redirect");
  27. var code = uri.getData("code");
  28. var method = uri.getData("method");
  29. var _load = function(){
  30. if (code) {
  31. layout.loginOauth();
  32. } else if (oauth) {
  33. layout.loadOauth();
  34. }
  35. };
  36. layout.loginOauth = function () {
  37. var r = protocol + "//" + location.host + location.pathname;
  38. r = r + "?oauth=" + oauth;
  39. if (redirect) r = r + "&redirect=" + redirect;
  40. r = o2.filterUrl(r);
  41. var action = MWF.Actions.get("x_organization_assemble_authentication");
  42. //企业微信单点登录
  43. if (layout.isQywx()) {
  44. action["loginOauthQywxServer"](code, function () {
  45. if (redirect) {
  46. window.location = redirect;
  47. } else {
  48. window.location = "../";
  49. }
  50. }.bind(this));
  51. } else if (layout.isDingding()) {
  52. action["loginOauthDingdingServer"](code, function () {
  53. if (redirect) {
  54. window.location = redirect;
  55. } else {
  56. window.location = "../";
  57. }
  58. }.bind(this));
  59. } else {
  60. var logMethod = method || "loginOauthServer";
  61. action[logMethod](oauth, code, encodeURIComponent(r), function () {
  62. if (method === "oauthBind") {
  63. alert("用户绑定已成功!");
  64. window.close();
  65. } else {
  66. if (redirect) {
  67. window.location = redirect;
  68. } else {
  69. window.location = "../";
  70. }
  71. }
  72. }.bind(this), function(){
  73. document.write("<div style='text-align: center; font-size: 24px; margin: 40px auto;'>无法获取用户凭证, 您可能未绑定“"+oauth+"”账号。</div>");
  74. 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>")
  75. });
  76. }
  77. };
  78. layout.loadOauth = function () {
  79. var action = MWF.Actions.get("x_organization_assemble_authentication");
  80. //企业微信单点登录
  81. if (layout.isQywx()) {
  82. action.qywxOauthServer(function (json) {
  83. var qywxConfig = json.data || {};
  84. var qrConnectAddress = qywxConfig.qrConnectAddress || "https://open.work.weixin.qq.com";
  85. var url = qrConnectAddress + "/wwopen/sso/qrConnect?state=STATE";
  86. var corpId = qywxConfig.corpId;
  87. if (corpId) {
  88. url += "&appid=" + corpId;
  89. }
  90. var agentId = qywxConfig.agentId;
  91. if (agentId) {
  92. url += "&agentid=" + agentId;
  93. }
  94. var r = protocol + "//" + location.host + location.pathname;
  95. r = r + "?oauth=" + oauth + "&qywx=true";
  96. url += "&redirect_uri=" + encodeURIComponent(r);
  97. window.location = url;
  98. }.bind(this));
  99. } else if (layout.isDingding()) { //钉钉单点登录
  100. action.dingdingOauthServer(function (json) {
  101. var dingdingConfig = json.data || {};
  102. var oapiAddress = dingdingConfig.oapiAddress || "https://oapi.dingtalk.com";
  103. var url = oapiAddress + "/connect/qrconnect?response_type=code&scope=snsapi_login&state=STATE";
  104. var appId = dingdingConfig.scanLoginAppId;
  105. if (appId) {
  106. url += "&appid=" + appId;
  107. }
  108. var r = protocol + "//" + location.host + location.pathname;
  109. r = r + "?oauth=" + oauth + "&dingding=true";
  110. r = o2.filterUrl(r);
  111. url += "&redirect_uri=" + encodeURIComponent(r);
  112. window.location = url;
  113. }.bind(this));
  114. } else {
  115. action.getOauthServer(oauth, function (json) {
  116. var url = json.data.authAddress;
  117. var p = json.data.authParameter;
  118. var r = protocol + "//" + location.host + location.pathname;
  119. r = r + "?oauth=" + oauth;
  120. if (method) r = r + "&method=" + method;
  121. if (redirect) r = r + "&redirect=" + redirect;
  122. r = o2.filterUrl(r);
  123. if (p.indexOf("{$redirect_uri}")!==-1){
  124. p = p.replace("{$redirect_uri}", encodeURIComponent(r));
  125. }else{
  126. p = (p) ? p + "&redirect_uri=" + encodeURIComponent(r) : "&redirect_uri=" + encodeURIComponent(r);
  127. }
  128. url = (url.indexOf("?" === -1)) ? url + "?" + p : url + "&" + p;
  129. window.location = url;
  130. }.bind(this));
  131. }
  132. };
  133. layout.isQywx = function () {
  134. var qywx = uri.getData("qywx");
  135. if (qywx) {
  136. return true;
  137. } else {
  138. return false;
  139. }
  140. };
  141. layout.isDingding = function () {
  142. var dingding = uri.getData("dingding");
  143. if (dingding) {
  144. return true;
  145. } else {
  146. return false;
  147. }
  148. };
  149. _load();
  150. })(layout);
  151. });
  152. </script>
  153. <script src="../o2_lib/mootools/mootools-1.6.0.min.js"></script>
  154. </head>
  155. <body>
  156. <!--<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);">-->
  157. <!--<div id="layout" style="overflow: auto; height:100%"></div>-->
  158. </body>
  159. </html>