weixinsso.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. layout = window.layout || {};
  2. var locate = window.location;
  3. layout.protocol = locate.protocol;
  4. var href = locate.href;
  5. if (href.indexOf("debugger") != -1) layout.debugger = true;
  6. layout.desktop = layout;
  7. layout.session = layout.session || {};
  8. o2.addReady(function () {
  9. // o2.load(["../o2_lib/mootools/plugin/mBox.Notice.js", "../o2_lib/mootools/plugin/mBox.Tooltip.js"], { "sequence": true }, function () {
  10. MWF.loadLP("zh-cn");
  11. MWF.require("MWF.xDesktop.Layout", function () {
  12. MWF.require("MWF.xDesktop.Authentication", null, false);
  13. MWF.require("MWF.xDesktop.Common", null, false);
  14. (function () {
  15. layout.load = function () {
  16. var uri = href.toURI();
  17. var mode = uri.getData("mode");
  18. var code = uri.getData("code");
  19. var redirect = uri.getData("redirect");
  20. MWF.require("MWF.xDesktop.Actions.RestActions", function () {
  21. var action = new MWF.xDesktop.Actions.RestActions("", "x_organization_assemble_authentication", "");
  22. action.getActions = function (actionCallback) {
  23. this.actions = { "sso": { "uri": "/jaxrs/qiyeweixin/code/{code}", "method": "GET" },
  24. "userdetail" : {"uri": "/jaxrs/qiyeweixin/update/person/detail/{code}", "method": "GET" } };
  25. if (actionCallback) actionCallback();
  26. };
  27. if (mode && mode === "snsapi_privateinfo") { // 获取用户详细信息,更新到Person
  28. action.invoke({
  29. "name": "userdetail", "async": true, "parameter": { "code": code}, "success": function(json) {
  30. // 完成认证 关闭页面
  31. if (redirect) {
  32. history.replaceState(null, "page", redirect);
  33. redirect.toURI().go();
  34. } else {
  35. console.error("没有引入企业微信js!!!");
  36. document.id("layout").set("html", "<div>更新成功,可以关闭页面了!</div>");
  37. }
  38. }.bind(this), "failure": function (xhr, text, error) {
  39. document.id("layout").set("html", "<div>企业微信单点异常!</div>")
  40. }.bind(this)
  41. });
  42. } else { // 默认的单点登录
  43. action.invoke({
  44. "name": "sso", "async": true, "parameter": { "code": code}, "success": function (json) {
  45. if (redirect) {
  46. history.replaceState(null, "page", redirect);
  47. redirect.toURI().go();
  48. } else {
  49. history.replaceState(null, "page", "../x_desktop/appMobile.html?app=process.TaskCenter");
  50. "appMobile.html?app=process.TaskCenter".toURI().go();
  51. }
  52. //"appMobile.html?app=process.TaskCenter".toURI().go();
  53. //window.loaction = "app.html?app=process.TaskCenter";
  54. }.bind(this), "failure": function (xhr, text, error) {
  55. document.id("layout").set("html", "<div>企业微信单点异常!</div>")
  56. //"appMobile.html?app=process.TaskCenter".toURI().go();
  57. //window.loaction = "app.html?app=process.TaskCenter";
  58. }.bind(this)
  59. });
  60. }
  61. });
  62. };
  63. // layout.notice = function (content, type, target, where, offset) {
  64. // if (!where) where = { "x": "right", "y": "top" };
  65. // if (!target) target = this.content;
  66. // if (!type) type = "ok";
  67. // var noticeTarget = target || $(document.body);
  68. // var off = offset;
  69. // if (!off) {
  70. // off = {
  71. // x: 10,
  72. // y: where.y.toString().toLowerCase() == "bottom" ? 10 : 10
  73. // };
  74. // }
  75. // new mBox.Notice({
  76. // type: type,
  77. // position: where,
  78. // move: false,
  79. // target: noticeTarget,
  80. // delayClose: (type == "error") ? 10000 : 5000,
  81. // offset: off,
  82. // content: content
  83. // });
  84. // };
  85. MWF.getJSON("res/config/config.json", function (config) {
  86. if (config.proxyCenterEnable){
  87. if (o2.typeOf(config.center)==="array"){
  88. config.center.forEach(function(c){
  89. c.port = window.location.port || 80;
  90. });
  91. }else{
  92. config.port = window.location.port || 80;
  93. }
  94. }
  95. layout.config = config;
  96. MWF.xDesktop.getServiceAddress(layout.config, function (service, center) {
  97. layout.serviceAddressList = service;
  98. layout.centerServer = center;
  99. layout.load();
  100. }.bind(this));
  101. //layout.getServiceAddress(function(){
  102. // layout.load();
  103. //});
  104. });
  105. })();
  106. });
  107. // });
  108. });