oauth.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. var action = MWF.Actions.get("x_organization_assemble_authentication");
  39. //企业微信单点登录
  40. if (layout.isQywx()) {
  41. action["loginOauthQywxServer"](code, function () {
  42. if (redirect) {
  43. window.location = redirect;
  44. } else {
  45. window.location = "/";
  46. }
  47. }.bind(this));
  48. } else if (layout.isDingding()) {
  49. action["loginOauthDingdingServer"](code, function () {
  50. if (redirect) {
  51. window.location = redirect;
  52. } else {
  53. window.location = "/";
  54. }
  55. }.bind(this));
  56. } else {
  57. var logMethod = method || "loginOauthServer";
  58. action[logMethod](oauth, code, encodeURIComponent(r), function () {
  59. if (method === "oauthBind") {
  60. alert("用户绑定已成功!");
  61. window.close();
  62. } else {
  63. if (redirect) {
  64. window.location = redirect;
  65. } else {
  66. window.location = "/";
  67. }
  68. }
  69. }.bind(this));
  70. }
  71. };
  72. layout.loadOauth = function () {
  73. var action = MWF.Actions.get("x_organization_assemble_authentication");
  74. //企业微信单点登录
  75. if (layout.isQywx()) {
  76. action.qywxOauthServer(function (json) {
  77. var qywxConfig = json.data || {};
  78. var url = "https://open.work.weixin.qq.com/wwopen/sso/qrConnect?state=STATE";
  79. var corpId = qywxConfig.corpId;
  80. if (corpId) {
  81. url += "&appid=" + corpId;
  82. }
  83. var agentId = qywxConfig.agentId;
  84. if (agentId) {
  85. url += "&agentid=" + agentId;
  86. }
  87. var r = protocol + "//" + location.host + location.pathname;
  88. r = r + "?oauth=" + oauth + "&qywx=true";
  89. url += "&redirect_uri=" + encodeURIComponent(r);
  90. window.location = url;
  91. }.bind(this));
  92. } else if (layout.isDingding()) { //钉钉单点登录
  93. action.dingdingOauthServer(function (json) {
  94. var dingdingConfig = json.data || {};
  95. var url = "https://oapi.dingtalk.com/connect/qrconnect?response_type=code&scope=snsapi_login&state=STATE";
  96. var appId = dingdingConfig.scanLoginAppId;
  97. if (appId) {
  98. url += "&appid=" + appId;
  99. }
  100. var r = protocol + "//" + location.host + location.pathname;
  101. r = r + "?oauth=" + oauth + "&dingding=true";
  102. url += "&redirect_uri=" + encodeURIComponent(r);
  103. window.location = url;
  104. }.bind(this));
  105. } else {
  106. action.getOauthServer(oauth, function (json) {
  107. var url = json.data.authAddress;
  108. var p = json.data.authParameter;
  109. var r = protocol + "//" + location.host + location.pathname;
  110. r = r + "?oauth=" + oauth;
  111. if (method) r = r + "&method=" + method;
  112. if (redirect) r = r + "&redirect=" + redirect;
  113. p = (p) ? p + "&redirect_uri=" + encodeURIComponent(r) : "&redirect_uri=" + encodeURIComponent(r);
  114. url = (url.indexOf("?" === -1)) ? url + "?" + p : url + "&" + p;
  115. window.location = url;
  116. }.bind(this));
  117. }
  118. };
  119. layout.isQywx = function () {
  120. var qywx = uri.getData("qywx");
  121. if (qywx) {
  122. return true;
  123. } else {
  124. return false;
  125. }
  126. };
  127. layout.isDingding = function () {
  128. var dingding = uri.getData("dingding");
  129. if (dingding) {
  130. return true;
  131. } else {
  132. return false;
  133. }
  134. };
  135. _load();
  136. })(layout);
  137. });
  138. // o2.addReady(function () {
  139. // layout = window.layout || {};
  140. // layout.desktop = layout;
  141. // o2.xDesktop = o2.xDesktop || {};
  142. //
  143. // var locate = window.location;
  144. // var protocol = locate.protocol;
  145. // var href = locate.href;
  146. //
  147. // var uri = new URI(href);
  148. // var oauth = uri.getData("oauth");
  149. // var redirect = uri.getData("redirect");
  150. // var code = uri.getData("code");
  151. // var method = uri.getData("method");
  152. //
  153. // layout.load = function () {
  154. // if (code) {
  155. // layout.loginOauth();
  156. // } else if (oauth) {
  157. // layout.loadOauth();
  158. // }
  159. //
  160. // };
  161. // layout.loginOauth = function () {
  162. // var r = protocol + "//" + location.host + location.pathname;
  163. // r = r + "?oauth=" + oauth;
  164. // if (redirect) r = r + "&redirect=" + redirect;
  165. //
  166. // var action = MWF.Actions.get("x_organization_assemble_authentication");
  167. // //企业微信单点登录
  168. // if (layout.isQywx()) {
  169. // action["loginOauthQywxServer"](code, function () {
  170. // if (redirect) {
  171. // window.location = redirect;
  172. // } else {
  173. // window.location = "/";
  174. // }
  175. // }.bind(this));
  176. // } else if (layout.isDingding()) {
  177. // action["loginOauthDingdingServer"](code, function () {
  178. // if (redirect) {
  179. // window.location = redirect;
  180. // } else {
  181. // window.location = "/";
  182. // }
  183. // }.bind(this));
  184. // } else {
  185. //
  186. // var logMethod = method || "loginOauthServer";
  187. // action[logMethod](oauth, code, encodeURIComponent(r), function () {
  188. // if (method === "oauthBind") {
  189. // alert("用户绑定已成功!");
  190. // window.close();
  191. // } else {
  192. // if (redirect) {
  193. // window.location = redirect;
  194. // } else {
  195. // window.location = "/";
  196. // }
  197. // }
  198. //
  199. // }.bind(this));
  200. // }
  201. //
  202. // };
  203. // layout.loadOauth = function () {
  204. // var action = MWF.Actions.get("x_organization_assemble_authentication");
  205. // //企业微信单点登录
  206. // if (layout.isQywx()) {
  207. // action.qywxOauthServer(function (json) {
  208. // var qywxConfig = json.data || {};
  209. // var url = "https://open.work.weixin.qq.com/wwopen/sso/qrConnect?state=STATE";
  210. // var corpId = qywxConfig.corpId;
  211. // if (corpId) {
  212. // url += "&appid=" + corpId;
  213. // }
  214. // var agentId = qywxConfig.agentId;
  215. // if (agentId) {
  216. // url += "&agentid=" + agentId;
  217. // }
  218. // var r = protocol + "//" + location.host + location.pathname;
  219. // r = r + "?oauth=" + oauth + "&qywx=true";
  220. // url += "&redirect_uri=" + encodeURIComponent(r);
  221. //
  222. // window.location = url;
  223. // }.bind(this));
  224. // } else if (layout.isDingding()) { //钉钉单点登录
  225. // action.dingdingOauthServer(function (json) {
  226. // var dingdingConfig = json.data || {};
  227. // var url = "https://oapi.dingtalk.com/connect/qrconnect?response_type=code&scope=snsapi_login&state=STATE";
  228. // var appId = dingdingConfig.scanLoginAppId;
  229. // if (appId) {
  230. // url += "&appid=" + appId;
  231. // }
  232. // var r = protocol + "//" + location.host + location.pathname;
  233. // r = r + "?oauth=" + oauth + "&dingding=true";
  234. // url += "&redirect_uri=" + encodeURIComponent(r);
  235. // window.location = url;
  236. // }.bind(this));
  237. // } else {
  238. // action.getOauthServer(oauth, function (json) {
  239. // var url = json.data.authAddress;
  240. // var p = json.data.authParameter;
  241. // var r = protocol + "//" + location.host + location.pathname;
  242. // r = r + "?oauth=" + oauth;
  243. // if (method) r = r + "&method=" + method;
  244. // if (redirect) r = r + "&redirect=" + redirect;
  245. // p = (p) ? p + "&redirect_uri=" + encodeURIComponent(r) : "&redirect_uri=" + encodeURIComponent(r);
  246. // url = (url.indexOf("?" === -1)) ? url + "?" + p : url + "&" + p;
  247. // window.location = url;
  248. // }.bind(this));
  249. // }
  250. // };
  251. // layout.isQywx = function () {
  252. // var qywx = uri.getData("qywx");
  253. // if (qywx) {
  254. // return true;
  255. // } else {
  256. // return false;
  257. // }
  258. // };
  259. // layout.isDingding = function () {
  260. // var dingding = uri.getData("dingding");
  261. // if (dingding) {
  262. // return true;
  263. // } else {
  264. // return false;
  265. // }
  266. // };
  267. //
  268. // MWF.loadLP("zh-cn");
  269. // MWF.require("MWF.xDesktop.Common", null, false);
  270. // MWF.require("MWF.xAction.RestActions", null, false);
  271. //
  272. // o2.load(["../o2_lib/mootools/plugin/mBox.Notice.js", "../o2_lib/mootools/plugin/mBox.Tooltip.js"], { "sequence": true }, function () {
  273. // o2.JSON.get("res/config/config.json", function (config) {
  274. // layout.config = config;
  275. // MWF.xDesktop.getServiceAddress(config, function (service, center) {
  276. // layout.serviceAddressList = service;
  277. // layout.centerServer = center;
  278. // layout.load();
  279. // }.bind(this));
  280. // }.bind(this));
  281. // });
  282. // //});
  283. // });
  284. </script>
  285. <script src="../o2_lib/mootools/mootools-1.6.0.min.js"></script>
  286. </head>
  287. <body>
  288. <!--<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);">-->
  289. <!--<div id="layout" style="overflow: auto; height:100%"></div>-->
  290. </body>
  291. </html>