login.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. var _uuid = "",_yzuuid = null;
  2. var ylToken = {}, _pwskey;
  3. $(document).ready(function(){
  4. _pwskey = `rueigao-${getTime(new Date())[0].replace(/-/g,'')}`;
  5. let query = window.location.search;
  6. if(query!=""){
  7. localStorage.setItem("ptType",query.split("=")[1]);
  8. }
  9. if (localStorage.getItem("_yz_TT") != "null" && localStorage.getItem("_yz_TT") != null) {
  10. top.location.href = IsPC()?"./view/Main.html?sn=P0":"./view/MainPh.html?sn=0";
  11. return;
  12. } else {
  13. getCode();
  14. // getYzCode();
  15. }
  16. })
  17. function getCode(){
  18. $.ajax({
  19. url: "https://eims.bds100.com/auth/code?v="+(new Date().getTime()),
  20. type: "GET",
  21. dataType: "JSON",
  22. async: true, //同步请求
  23. data:{},
  24. error: function(XMLHttpRequest) {
  25. console.log(11111)
  26. },
  27. success:function (res) {
  28. _uuid = res.uuid;
  29. $("#codeImg").attr("src",res.img);
  30. }
  31. })
  32. }
  33. function getYzCode(){
  34. $.ajax({
  35. url: vipUrl+"/captchaImage",
  36. type: "GET",
  37. dataType: "JSON",
  38. async: true, //同步请求
  39. data:{},
  40. error: function(XMLHttpRequest) {
  41. console.log(11111)
  42. },
  43. success:function (res) {
  44. _yzuuid = res.uuid;
  45. $("#yzcodeImg").attr("src","data:image/jpg;base64,"+res.img);
  46. }
  47. })
  48. }
  49. $('input').bind('keyup', function(event) {
  50. if (event.keyCode == "13") {
  51. loginYZ();
  52. }
  53. });
  54. $(".logBtn").on("click","",function(){
  55. loginYZ();
  56. })
  57. function loginErr(){
  58. $(".logBtn i").css("display","none");
  59. $(".logBtn").removeAttr("disabled").removeClass("btnds");
  60. }
  61. function loginYZ(){
  62. let _user = $("input[name='user']").val();
  63. let _password = $("input[name='pwd']").val();
  64. let _codepwd = $("input[name='codepwd']").val();
  65. let _cyzodepwd = $("input[name='yzcodepwd']").val();
  66. if(_password!=""&&_user!=""&&_codepwd!=""){
  67. $(".logBtn i").css("display","inline-block");
  68. $(".logBtn").attr("disabled","disabled").addClass("btnds");
  69. setTimeout(()=>{
  70. $.ajax({
  71. url: vipUrl +"/login",
  72. type: "POST",
  73. dataType: "JSON",
  74. async: false, //同步请求
  75. data:JSON.stringify({
  76. username: encrypt(_user, _pwskey),
  77. password: encrypt(_password, _pwskey),
  78. code:_cyzodepwd,
  79. uuid:"f53582934d844429a52be829a9291789"
  80. }),
  81. headers: {
  82. "Content-Type": "application/json"
  83. },
  84. success:function (json) {
  85. let data = eval(json);
  86. if (data.code == 200){
  87. ylToken["yzTok"] = data.token;
  88. loginYL(_codepwd);
  89. // loginYSY();
  90. }else{
  91. // getYzCode();
  92. loginErr();
  93. ShowLoading("错误原因:"+data.msg+"!",1)
  94. }
  95. },
  96. error:function(err){
  97. loginErr();
  98. // getYzCode();
  99. ShowLoading("登录失败",1)
  100. $("input[name='yzcodepwd']").val("");
  101. },
  102. })
  103. },100)
  104. }else{
  105. ShowLoading("请填写完信息再登录!",1);
  106. }
  107. }
  108. // 易聊登录
  109. function loginYL(_key){
  110. $.ajax({
  111. url: "https://eims.bds100.com/auth/login",
  112. type: "POST",
  113. dataType: "JSON",
  114. async: false,
  115. headers:{
  116. "Content-Type": "application/json"
  117. },
  118. data:JSON.stringify({
  119. code: _key,
  120. password: "I8zZGBdzG+YloVHgTyjdZ3wox0oUU1xr5UpG0oSS5jrGOXGAZBUnAlSvD/eGzjzy+vnz6rWu4rVLkNcRc/o1x57FT0YO8Ak9OSdTcgzycE7kz3ZhK//taMCxnmGEBPiZmM4IUz5JxU9LGb5r0mnNEii4lTRFo7Nvn3zTqMTgfMU=",
  121. username: "yq",
  122. uuid: _uuid
  123. }),
  124. error:function(err){
  125. ShowLoading(err.responseJSON.message,1);
  126. loginErr()
  127. getCode();
  128. $("input[name='codepwd']").val("");
  129. },
  130. success:function (res) {
  131. ylToken["ylId"] = res.jwtUserDto.user.id;
  132. ylToken["ylTok"] = res.token;
  133. loginYSY();
  134. }
  135. })
  136. }
  137. // ysy设备列表登录
  138. function loginYSY(){
  139. $.ajax({
  140. url: "https://open.ys7.com/api/lapp/token/get",
  141. type: "POST",
  142. dataType: "JSON",
  143. async: false, //同步请求
  144. data:{
  145. appKey:"443b2b196905436dbdf1ad6f30b0ac0d",
  146. appSecret:"08d8c3401a809115d442108883735c70"
  147. },
  148. success:function (json) {
  149. if(json.code==200){
  150. ylToken["ysyTok"] = json.data.accessToken;
  151. getHTok();
  152. // top.location.href =IsPC()?"./view/Main.html?sn=P0":"./view/MainPh.html?sn=0";
  153. }else{
  154. loginErr();
  155. }
  156. }
  157. })
  158. }
  159. function getHTok(){
  160. $.ajax({
  161. url: "https://caps.runde.pro/api/index.php?ctl=tool&act=get_token",
  162. type: "POST",
  163. dataType: "JSON",
  164. async: false,
  165. data:{
  166. user_name: "易站智联",
  167. pkey: "e7d7cbe91171c493e8022a418d16bb7d"
  168. },
  169. success:function (res) {
  170. if(res.status){
  171. ShowLoading("登录成功!",1);
  172. ylToken["hemlTok"] = res.token;
  173. ylToken["hemlId"] = "2f503fe26d3278f89e593612c12e68d2";
  174. localStorage.removeItem("_yz_TT");
  175. localStorage.setItem("_yz_TT",JSON.stringify(ylToken));
  176. top.location.href =IsPC()?"./view/Main.html?sn=P0":"./view/MainPh.html?sn=0";
  177. }else{
  178. ShowLoading(res.msg,1);
  179. loginErr();
  180. }
  181. }
  182. })
  183. }
  184. // 判断是PC端还是移动端
  185. function IsPC() {
  186. var userAgentInfo = navigator.userAgent;
  187. var Agents = ["Android", "iPhone",
  188. "SymbianOS", "Windows Phone",
  189. "iPad", "iPod"];
  190. var flag = true;
  191. for (var v = 0; v < Agents.length; v++) {
  192. if (userAgentInfo.indexOf(Agents[v]) > 0) {
  193. flag = false;
  194. break;
  195. }
  196. }
  197. return flag;
  198. }
  199. function encrypt(word, keyStr) {
  200. keyStr = keyStr ? keyStr : 'abc';
  201. var key = CryptoJS.enc.Utf8.parse(keyStr);
  202. var srcs = CryptoJS.enc.Utf8.parse(word);
  203. var encrypted = CryptoJS.AES.encrypt(srcs, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 });
  204. return encrypted.toString();
  205. };