auto-login.html 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <!DOCTYPE html>
  2. <meta charset="UTF-8">
  3. <html>
  4. <head>
  5. <title>景宁教育魔方</title>
  6. <!-- 这个必须引入的啊,钉钉的前端js SDK, 使用框架的请自行参照开发文档 -->
  7. <script src="https://g.alicdn.com/dingding/dingtalk-jsapi/2.7.13/dingtalk.open.js"></script>
  8. <!-- 这个jquery 想不想引入自己决定,没什么影响 -->
  9. <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
  10. <style type="text/css">
  11. .loading {
  12. position: fixed;
  13. left: 0;
  14. top: 0;
  15. width: 100%;
  16. height: 100%;
  17. z-index: 100;
  18. background: url("loading.gif") center no-repeat rgba(255, 255, 255, .55);
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <!--TODO...替换成之前亲亲云的一个登录中转过度loading-->
  24. <div class="loading"></div>
  25. <!--<div id="user_info" style="color: #000;font-size: 15px;position: fixed;left: 0;top: 0;width: 100%;height: 100%;z-index: 150"></div>-->
  26. <!--<hr>-->
  27. <!--<h1>教育魔方-免登验证-线上环境</h1>-->
  28. <!--<p>当前页面的url:</p>-->
  29. <!--<p id="url"></p>-->
  30. <!--<br>-->
  31. <!--<p>解析url,获取的corpID:</p>-->
  32. <!--<p id="corpId"></p>-->
  33. <!--<br>-->
  34. <!--<p>SDK初始化获取的code:</p>-->
  35. <!--<p id="code"></p>-->
  36. <!--<br>-->
  37. <!--<p>请求我们服务端,登录返回的结果:</p>-->
  38. <p id="myresponse"></p>
  39. <script type="text/javascript">
  40. let login_obj = {
  41. url: '',
  42. code: '',
  43. api: ''
  44. };
  45. if (location.href.includes('.bozedu.')) {
  46. login_obj = {
  47. url: 'https://daily-cube.zjedu.com',
  48. code: 'suitemie4qeftvmhnufp1',
  49. api: 'http://jnjymf_api.bozedu.top'
  50. }
  51. } else {
  52. login_obj = {
  53. url: 'https://cube.zjedu.com',
  54. code: 'suiteecoywfohhm68lkix',
  55. api: 'http://60.188.226.44:8090'
  56. }
  57. }
  58. $(function () {
  59. var params = new Object();
  60. params = GetRequest();
  61. // if (localStorage.getItem('userInfo')) {
  62. // localStorage.removeItem('userInfo');
  63. // }
  64. localStorage.clear()
  65. // debug
  66. // {
  67. // var corpId = params.corpId ? params.corpId : '';
  68. // var tag = params.tag ? params.tag : '';
  69. // let follow = '';
  70. // const t = tag.split('_');
  71. // if (t.length > 1) {
  72. // tag = t.splice(0, 1)[0];
  73. // follow = t.join('/');
  74. // }
  75. // window.open('http://localhost:3000/' + (follow ? ('#/' + follow) : ''), '_blank');
  76. // }
  77. console.log('init ', '2023/7/13 10:30:01')
  78. var corpId = params.corpId ? params.corpId : '';
  79. var tag = params.tag ? params.tag : '';
  80. let follow = '';
  81. const t = tag.split('_');
  82. if (t.length > 1) {
  83. tag = t.splice(0, 1)[0];
  84. follow = t.join('/');
  85. }
  86. if (params.debug || follow == '') {
  87. localStorage.setItem('debug', '1')
  88. }
  89. // debug area
  90. if (tag === 'hlwxx') {
  91. console.log('href : ', '/app/hlwxx/#/autoLogin?user_id=' + 'userInfo.user_id')
  92. } else {
  93. console.log('href : ', '/app/' + tag + '/' + (follow ? ('#/' + follow) : ''))
  94. }
  95. // 钉钉sdk 初始化
  96. // dd.ready参数为回调函数,在环境准备就绪时触发,jsapi的调用需要保证在该回调函数触发后调用,否则无效。
  97. dd.ready(function () {
  98. //使用SDK 获取免登授权码
  99. dd.runtime.permission.requestAuthCode({
  100. corpId: corpId,
  101. onSuccess: function (result) {
  102. var code = result.code;
  103. $.ajax({
  104. type: "POST",
  105. //TODO...下面的域名要从配置文件中获取,不写死
  106. url: login_obj.url + '/user/api/v1/login/autoLogin',
  107. contentType: "application/json;charset=utf-8",
  108. data: JSON.stringify({ code: code, accessKey: login_obj.code, corpId: corpId }),
  109. dataType: "json",
  110. success: function (response) {
  111. // $('#user_info').html('22222'+ JSON.stringify(response.data));
  112. if (response.success == false) {
  113. alert(JSON.stringify(response.msg) + JSON.stringify(response.code));
  114. } else {
  115. //TODO...开始
  116. $.ajax({
  117. type: 'POST',
  118. url: login_obj.api + '/user/main/login',
  119. // contentType: "application/json;charset=utf-8",
  120. data: {
  121. cubeinfo: JSON.stringify(response.data)
  122. },
  123. dataType: "json",
  124. success: (res) => {
  125. if (res.code == 1) {
  126. const userInfo = res.data
  127. console.log('userInfo : ', userInfo)
  128. if (tag === 'hlwxx') {
  129. location.href = '/app/hlwxx/#/autoLogin?user_id=' + userInfo.user_id
  130. } else {
  131. if ((!Array.isArray(userInfo.user_org.length)) && userInfo.user_org.length == 0) {
  132. alert('账号未绑定机构,您没有权限访问该应用')
  133. return
  134. }
  135. // uo_type 2是学校 1是教育局
  136. const uo_type = userInfo.user_org[userInfo.user_org.length - 1].uo_type
  137. if (uo_type == '1' && tag.startsWith('xd')) {
  138. alert('您是教育局用户,无法访问该应用')
  139. return
  140. }
  141. if (uo_type == '2' && tag.startsWith('jd')) {
  142. alert('您是学校用户,无法访问该应用')
  143. return
  144. }
  145. localStorage.setItem('userInfo', JSON.stringify(res.data));
  146. location.href = '/app/' + tag + '/' + (follow ? ('#/' + follow) : '');
  147. // location.href = 'test.html';}
  148. }
  149. } else {
  150. alert(res.msg);
  151. }
  152. },
  153. error: function (re) {
  154. alert("失败" + JSON.stringify(res));
  155. }
  156. })
  157. //TODO...结束
  158. }
  159. // alert("成功" + JSON.stringify(response));
  160. //成功以后将response.data的信息提交给 本地用户获取接口(开发中),初始化登录用户信息
  161. },
  162. error: function (response) {
  163. alert("失败" + JSON.stringify(response));
  164. }
  165. });
  166. },
  167. onFail: function (err) {
  168. // 调用失败时回调
  169. alert("requestAuthCode失败" + JSON.stringify(err));
  170. }
  171. });
  172. });
  173. })
  174. function GetRequest() {
  175. var url = location.search;
  176. var theRequest = new Object();
  177. if (url.indexOf("?") != -1) {
  178. var str = url.substr(1);
  179. strs = str.split("&");
  180. for (var i = 0; i < strs.length; i++) {
  181. theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
  182. }
  183. }
  184. return theRequest;
  185. }
  186. </script>
  187. </body>
  188. </html>