-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetToken2.js
More file actions
63 lines (53 loc) · 1.78 KB
/
getToken2.js
File metadata and controls
63 lines (53 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const axios = require("axios");
const fs = require("fs");
const BASE_URL = "http://live-rest-api-lb-271378262.ap-southeast-1.elb.amazonaws.com";
const FILE_PATH = "tokens2.json";
// Thông tin người dùng
const time = "1751365760069";
const password = "Orics@727965";
const from = 10001;
const to = 12000;
async function getOrCreateTokens() {
let tokens = [];
// Đọc file nếu có
if (fs.existsSync(FILE_PATH)) {
try {
const content = fs.readFileSync(FILE_PATH, "utf-8");
const parsed = JSON.parse(content);
if (Array.isArray(parsed)) {
tokens = parsed;
if (tokens.length >= to - from + 1) {
console.log("✅ Đã sử dụng lại token từ file.");
return tokens;
}
}
} catch (err) {
console.warn("⚠️ File tokens.json bị lỗi, sẽ tạo lại.");
}
}
console.log("🔐 Đang tạo token mới...");
for (let userNo = from + tokens.length; userNo <= to; userNo++) {
const username = `0107_${time}_test${10000 + userNo}`;
try {
const res = await axios.post(`${BASE_URL}/customer`, {
username,
password,
});
const token = res?.data?.data?.accessToken;
if (token) {
tokens.push(token);
const count = tokens.length;
console.log(`✅ Token OK: ${username} (${count})`);
// Ghi ngay sau mỗi token thành công
fs.writeFileSync(FILE_PATH, JSON.stringify(tokens, null, 2), "utf-8");
} else {
console.warn(`⚠️ Không lấy được token cho ${username}`);
}
} catch (err) {
console.error(`❌ Lỗi login ${username}:`, err?.response?.data || err?.message);
}
}
console.log(`✅ Đã hoàn tất, tổng cộng ${tokens.length} token.`);
return tokens;
}
getOrCreateTokens();