oauth.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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 src="js/base_simple_anonymous.js"></script>
  16. <script>
  17. layout.addReady(function(){
  18. (function(layout){
  19. var uri = new URI(window.location.href);
  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. var _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. _load();
  137. })(layout);
  138. });
  139. // o2.addReady(function () {
  140. // layout = window.layout || {};
  141. // layout.desktop = layout;
  142. // o2.xDesktop = o2.xDesktop || {};
  143. //
  144. // var locate = window.location;
  145. // var protocol = locate.protocol;
  146. // var href = locate.href;
  147. //
  148. // var uri = new URI(href);
  149. // var oauth = uri.getData("oauth");
  150. // var redirect = uri.getData("redirect");
  151. // var code = uri.getData("code");
  152. // var method = uri.getData("method");
  153. //
  154. // layout.load = function () {
  155. // if (code) {
  156. // layout.loginOauth();
  157. // } else if (oauth) {
  158. // layout.loadOauth();
  159. // }
  160. //
  161. // };
  162. // layout.loginOauth = function () {
  163. // var r = protocol + "//" + location.host + location.pathname;
  164. // r = r + "?oauth=" + oauth;
  165. // if (redirect) r = r + "&redirect=" + redirect;
  166. //
  167. // var action = MWF.Actions.get("x_organization_assemble_authentication");
  168. // //企业微信单点登录
  169. // if (layout.isQywx()) {
  170. // action["loginOauthQywxServer"](code, function () {
  171. // if (redirect) {
  172. // window.location = redirect;
  173. // } else {
  174. // window.location = "/";
  175. // }
  176. // }.bind(this));
  177. // } else if (layout.isDingding()) {
  178. // action["loginOauthDingdingServer"](code, function () {
  179. // if (redirect) {
  180. // window.location = redirect;
  181. // } else {
  182. // window.location = "/";
  183. // }
  184. // }.bind(this));
  185. // } else {
  186. //
  187. // var logMethod = method || "loginOauthServer";
  188. // action[logMethod](oauth, code, encodeURIComponent(r), function () {
  189. // if (method === "oauthBind") {
  190. // alert("用户绑定已成功!");
  191. // window.close();
  192. // } else {
  193. // if (redirect) {
  194. // window.location = redirect;
  195. // } else {
  196. // window.location = "/";
  197. // }
  198. // }
  199. //
  200. // }.bind(this));
  201. // }
  202. //
  203. // };
  204. // layout.loadOauth = function () {
  205. // var action = MWF.Actions.get("x_organization_assemble_authentication");
  206. // //企业微信单点登录
  207. // if (layout.isQywx()) {
  208. // action.qywxOauthServer(function (json) {
  209. // var qywxConfig = json.data || {};
  210. // var url = "https://open.work.weixin.qq.com/wwopen/sso/qrConnect?state=STATE";
  211. // var corpId = qywxConfig.corpId;
  212. // if (corpId) {
  213. // url += "&appid=" + corpId;
  214. // }
  215. // var agentId = qywxConfig.agentId;
  216. // if (agentId) {
  217. // url += "&agentid=" + agentId;
  218. // }
  219. // var r = protocol + "//" + location.host + location.pathname;
  220. // r = r + "?oauth=" + oauth + "&qywx=true";
  221. // url += "&redirect_uri=" + encodeURIComponent(r);
  222. //
  223. // window.location = url;
  224. // }.bind(this));
  225. // } else if (layout.isDingding()) { //钉钉单点登录
  226. // action.dingdingOauthServer(function (json) {
  227. // var dingdingConfig = json.data || {};
  228. // var url = "https://oapi.dingtalk.com/connect/qrconnect?response_type=code&scope=snsapi_login&state=STATE";
  229. // var appId = dingdingConfig.scanLoginAppId;
  230. // if (appId) {
  231. // url += "&appid=" + appId;
  232. // }
  233. // var r = protocol + "//" + location.host + location.pathname;
  234. // r = r + "?oauth=" + oauth + "&dingding=true";
  235. // url += "&redirect_uri=" + encodeURIComponent(r);
  236. // window.location = url;
  237. // }.bind(this));
  238. // } else {
  239. // action.getOauthServer(oauth, function (json) {
  240. // var url = json.data.authAddress;
  241. // var p = json.data.authParameter;
  242. // var r = protocol + "//" + location.host + location.pathname;
  243. // r = r + "?oauth=" + oauth;
  244. // if (method) r = r + "&method=" + method;
  245. // if (redirect) r = r + "&redirect=" + redirect;
  246. // p = (p) ? p + "&redirect_uri=" + encodeURIComponent(r) : "&redirect_uri=" + encodeURIComponent(r);
  247. // url = (url.indexOf("?" === -1)) ? url + "?" + p : url + "&" + p;
  248. // window.location = url;
  249. // }.bind(this));
  250. // }
  251. // };
  252. // layout.isQywx = function () {
  253. // var qywx = uri.getData("qywx");
  254. // if (qywx) {
  255. // return true;
  256. // } else {
  257. // return false;
  258. // }
  259. // };
  260. // layout.isDingding = function () {
  261. // var dingding = uri.getData("dingding");
  262. // if (dingding) {
  263. // return true;
  264. // } else {
  265. // return false;
  266. // }
  267. // };
  268. //
  269. // MWF.loadLP("zh-cn");
  270. // MWF.require("MWF.xDesktop.Common", null, false);
  271. // MWF.require("MWF.xAction.RestActions", null, false);
  272. //
  273. // o2.load(["../o2_lib/mootools/plugin/mBox.Notice.js", "../o2_lib/mootools/plugin/mBox.Tooltip.js"], { "sequence": true }, function () {
  274. // o2.JSON.get("res/config/config.json", function (config) {
  275. // layout.config = config;
  276. // MWF.xDesktop.getServiceAddress(config, function (service, center) {
  277. // layout.serviceAddressList = service;
  278. // layout.centerServer = center;
  279. // layout.load();
  280. // }.bind(this));
  281. // }.bind(this));
  282. // });
  283. // //});
  284. // });
  285. </script>
  286. <script src="../o2_lib/mootools/mootools-1.6.0.min.js"></script>
  287. </head>
  288. <body>
  289. <!--<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);">-->
  290. <!--<div id="layout" style="overflow: auto; height:100%"></div>-->
  291. </body>
  292. </html>