seimin hai 1 ano
pai
achega
1121a58c65
Modificáronse 1 ficheiros con 15 adicións e 2 borrados
  1. 15 2
      src/app/services/main.service.ts

+ 15 - 2
src/app/services/main.service.ts

@@ -2,8 +2,8 @@ import { Injectable } from "@angular/core";
2
 import { HttpClient, HttpHeaders } from "@angular/common/http";
2
 import { HttpClient, HttpHeaders } from "@angular/common/http";
3
 
3
 
4
 import host from "../../assets/js/http";
4
 import host from "../../assets/js/http";
5
-import { resolve } from "q";
6
 import { Observable } from "rxjs";
5
 import { Observable } from "rxjs";
6
+import { AES, mode, pad, enc } from "crypto-js";
7
 
7
 
8
 @Injectable({
8
 @Injectable({
9
   providedIn: "root",
9
   providedIn: "root",
@@ -22,13 +22,26 @@ export class MainService {
22
       headers: this.headers,
22
       headers: this.headers,
23
     });
23
     });
24
   }
24
   }
25
+  //aes加密
26
+  encryptByEnAES(data: string): string {
27
+    data = enc.Utf8.parse(data);
28
+    let Key = enc.Utf8.parse('Aes2Util666AQWER');
29
+    let tmpAES = AES.encrypt(data, Key, {
30
+      mode: mode.ECB,
31
+      padding: pad.Pkcs7,
32
+    });
33
+    return tmpAES.toString();
34
+  }
25
   // 登录
35
   // 登录
26
   login(name: string, pwd: string): any {
36
   login(name: string, pwd: string): any {
27
-    const data = {
37
+    let loginData = {
28
       username: name,
38
       username: name,
29
       password: pwd,
39
       password: pwd,
30
       type: "PC",
40
       type: "PC",
31
     };
41
     };
42
+    let data = {
43
+      k: this.encryptByEnAES(JSON.stringify(loginData))
44
+    };
32
     return this.http.post(host.host + "/auth/login", data, {
45
     return this.http.post(host.host + "/auth/login", data, {
33
       headers: this.headers,
46
       headers: this.headers,
34
     });
47
     });