forked from 5ime/Tiktok_Signature
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
101 lines (92 loc) · 2.69 KB
/
index.js
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const axios = require('axios');
const crypto = require('crypto');
const express = require("express");
const { sign } = require("./Signer.js");
const app = express();
app.use(express.json());
app.post("/", async (req, res) => {
try {
const { url, userAgent } = req.body;
if (!url || !userAgent) {
throw new Error("Missing required parameters.");
}
const query = url.includes("?") ? url.split("?")[1] : "";
const xbogus = sign(query, userAgent);
const newUrl = `${url}&X-Bogus=${xbogus}`;
const [xbogusToken, ttwid] = await Promise.all([msToken(107), getTtwid()]);
res.status(200).json({
code: 200,
msg: "success",
data: {
xbogus: xbogus,
mstoken: xbogusToken,
ttwid: ttwid,
url: newUrl
}
});
} catch (err) {
console.error(err);
res.status(400).json({ code: 201, msg: err.message });
}
});
app.get("/", (req, res) => {
res.status(200).send(`
<html>
<head>
<title>Tiktok_Signature</title>
<style>
body {
background-color: #f2f2f2;
font-family: Arial, sans-serif;
text-align: center;
}
h1 {
color: #333;
font-size: 3rem;
margin-top: 3rem;
}
p {
color: #666;
font-size: 1.5rem;
margin-top: 1.5rem;
}
</style>
</head>
<body>
<h1>Tiktok_Signature</h1>
<p>自动生成抖音 xbogus、mstoken 和 ttwid</p>
<p>使用方法:<a href="https://github.com/5ime/Tiktok_Signature" target="_blank">https://github.com/5ime/Tiktok_Signature</a></p>
</body>
</html>
`);
});
function msToken(length) {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const randomBytes = crypto.randomBytes(length);
return Array.from(randomBytes, byte => characters[byte % characters.length]).join('');
}
async function getTtwid() {
try {
const url = 'https://ttwid.bytedance.com/ttwid/union/register/';
const data = {
"region": "cn",
"aid": 1768,
"needFid": false,
"service": "www.ixigua.com",
"migrate_info": { "ticket": "", "source": "node" },
"cbUrlProtocol": "https",
"union": true
};
const response = await axios.post(url, data, { headers: { 'Content-Type': 'application/json' } });
const setCookie = response.headers['set-cookie'];
const regex = /ttwid=([^;]+)/;
const match = regex.exec(setCookie[0]);
return match && match.length > 1 ? match[1] : '';
} catch (error) {
console.error(error);
return '';
}
}
app.listen(80, () => {
console.log("Server is running on port 80");
});