Skip to content

Commit

Permalink
💥将XB计算单独放入Server目录并添加启动、打包命令
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnserf-Seed committed Dec 26, 2023
1 parent 67b4a11 commit 0ac2702
Show file tree
Hide file tree
Showing 13 changed files with 464 additions and 6 deletions.
197 changes: 197 additions & 0 deletions Server/Server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@Description:Server.py
@Date :2023/02/25 17:03:32
@Author :JohnserfSeed
@version :0.0.1
@License :MIT License
@Github :https://github.com/johnserf-seed
@Mail :[email protected]
-------------------------------------------------
Change Log :
2023/02/25 17:03:32 - Create Flask Server XB Gen
2023/08/03 16:48:34 - Fix ttwid
-------------------------------------------------
'''

import time
import execjs
# import sqlite3
import requests

from flask import Flask
from flask import request
from flask import jsonify
# from flask import make_response
# from flask import render_template

from urllib.parse import urlencode
from urllib.parse import unquote
from urllib.parse import parse_qsl

class Server:
def __init__(self) -> None:
# 工厂模式
self.app = Flask(__name__)

self.app.config.from_mapping(
SECRET_KEY='douyin-xbogus'
)

self.app.config['JSON_AS_ASCII'] = False

with open("x-bogus.js", "r", encoding="utf-8") as fp:
self.xbogust_func = execjs.compile(fp.read())

with open("x-tt-params.js", "r", encoding="utf-8") as fp:
self.xttm_func = execjs.compile(fp.read())

self.ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"

# 获取xg参数
def getXG(self, url_path, params):
xbogus = self.xbogust_func.call("getXB", url_path)
# 字典中添加xg
params["X-Bogus"] = xbogus
tips = {
"status_code": "200",
"time": {
"strftime": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
"timestamp": int(round(time.time() * 1000))
},
"result": [{
"params": params,
"paramsencode": urlencode(params, safe="="),
"user-agent": self.ua,
"X-Bogus": {
0: xbogus,
1: "X-Bogus=%s" % xbogus
}
}]
}
print(tips)
return jsonify(tips)

# 生成x-tt-params
def getxttparams(self, url_path):
xttp = self.xttm_func.call("getXTTP", url_path)
tips = {
"status_code": "200",
"time": {
"strftime": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
"timestamp": int(round(time.time() * 1000))
},
"result": [{
"headers": {
"user-agent": self.ua,
"x-tt-params": xttp
}
}]
}
print(tips)
return jsonify(tips)

def gen_ttwid(self) -> str:
"""生成请求必带的ttwid
param :None
return:ttwid
"""
url = 'https://ttwid.bytedance.com/ttwid/union/register/'
data = '{"region":"cn","aid":1768,"needFid":false,"service":"www.ixigua.com","migrate_info":{"ticket":"","source":"node"},"cbUrlProtocol":"https","union":true}'
response = requests.request("POST", url, data=data)
# j = ttwid k = 1%7CfPx9ZM.....
for j, k in response.cookies.items():
tips = {
"status_code": "200",
"time": {
"strftime": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
"timestamp": int(round(time.time() * 1000))
},
"result": [{
"headers": {
"user-agent": self.ua,
"cookie": "ttwid=%s;" % k
}
}]
}
print(tips)
return jsonify(tips)


if __name__ == "__main__":
server = Server()
# 首页
@server.app.route('/', methods=['GET', 'POST'])
def index():
tips = {
"status_code": "-1",
"time": {
"strftime": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
"timestamp": int(round(time.time() * 1000))
},
"path": {
0: "/xg/path/?url=",
2: "/x-tt-params/path"
}
}
print(tips)
return jsonify(tips)

# xg参数
@server.app.route('/xg/path/', methods=['GET', 'POST'])
def xgpath():
path = request.args.get('url', '')
# 如果str路径为空
if not path:
tips = {
"status_code": "-3",
"time": {
"strftime": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
"timestamp": int(round(time.time() * 1000))
},
"message": {
0: "The key url cannot be empty and the need for url encoding, The '&' sign needs to be escaped to '%26', Use urllib.parse.quote(url) to escape. Example:/xg/path/?url=aid=6383%26sec_user_id=xxx%26max_cursor=0%26count=10",
1: "url参数不能为空,且需要注意传入值中的“&”需要转义成“%26”,使用urllib.parse.quote(url)转义. 例如:/xg/path/?url=aid=6383%26sec_user_id=xxx%26max_cursor=0%26count=10"
}
}
print(tips)
return jsonify(tips)
else:
# url转字典
params = dict(parse_qsl(path))
# 字典转url
url_path = urlencode(params, safe="=")
return server.getXG(url_path, params)

# x-tt-params参数
@server.app.route('/x-tt-params/path', methods=['GET', 'POST'])
def xttppath():
try:
path = request.json
except:
pass
if not path:
tips = {
"status_code": "-5",
"time": {
"strftime": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
"timestamp": int(round(time.time() * 1000))
},
"message": {
0: "Body uses raw JSON format to pass dictionary parameters, such as %s" % '{"aid": 1988,"app_name": "tiktok_web","channel": "tiktok_web".........}',
1: "body中使用raw json格式传递字典参数,如%s" % '{"aid": 1988,"app_name": "tiktok_web","channel": "tiktok_web".........}'
}
}
print(tips)
return jsonify(tips)
else:
return server.getxttparams(path)

# ttwid
@server.app.route('/xg/ttwid', methods=['GET', 'POST'])
def ttwid():
return server.gen_ttwid()


server.app.run(host='0.0.0.0',port='8889')
41 changes: 41 additions & 0 deletions Server/Server.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# UTF-8
#
# For more details about fixed file info 'ffi' see:
# http://msdn.microsoft.com/en-us/library/ms646997.aspx
VSVersionInfo(
ffi=FixedFileInfo(
# filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4)
# Set not needed items to zero 0.
filevers=(1, 4, 2, 2),
prodvers=(1, 4, 2, 2),
# Contains a bitmask that specifies the valid bits 'flags'r
mask=0x3f,
# Contains a bitmask that specifies the Boolean attributes of the file.
flags=0x0,
# The operating system for which this file was designed.
# 0x4 - NT and there is no need to change it.
OS=0x40004,
# The general type of file.
# 0x1 - the file is an application.
fileType=0x1,
# The function of the file.
# 0x0 - the function is not defined for this fileType
subtype=0x0,
# Creation date and time stamp.
date=(0, 0)
),
kids=[
StringFileInfo(
[
StringTable(
u'080404b0',
[StringStruct(u'CompanyName', u'JohnserfSeed'),
StringStruct(u'FileDescription', u'本地解析服务'),
StringStruct(u'FileVersion', u'1.4.2.2'),
StringStruct(u'LegalCopyright', u'Copyright (C) 2019-2023 JohnserfSeed. All Rights Reserved'),
StringStruct(u'ProductName', u'本地解析服务'),
StringStruct(u'ProductVersion', u'1.4.2.2')])
]),
VarFileInfo([VarStruct(u'Translation', [2052, 1200])])
]
)
9 changes: 9 additions & 0 deletions Server/build-win.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@echo off
echo Install Npm Require
npm i
echo Install Pip Require
pip install -r requirements.txt
echo Build EXE version, Press Ctrl + C to Exit
echo Build Server
pyinstaller -F -i f2-logo.ico --version-file Server.txt --hidden-import=charset_normalizer.md__mypyc Server.py
pause
6 changes: 6 additions & 0 deletions Server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"crypto-js": "^4.1.1",
"md5": "^2.3.0"
}
}
2 changes: 2 additions & 0 deletions Server/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flask==2.2.5
PyExecJS==1.5.1
15 changes: 15 additions & 0 deletions Server/s_v_web_id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function create_s_v_web_id() {
var e = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("")
, t = e.length
, n = (new Date).getTime().toString(36)
, r = [];

r[8] = r[13] = r[18] = r[23] = "_",
r[14] = "4";
for (var o, i = 0; i < 36; i++)
r[i] || (o = 0 | Math.random() * t,
r[i] = e[19 == i ? 3 & o | 8 : o]);
return "verify_" + n + "_" + r.join("")
}

console.log(create_s_v_web_id())
31 changes: 31 additions & 0 deletions Server/s_v_web_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import time
import random

def create_s_v_web_id():
e = list("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
t = len(e)
n = base36_encode(int(time.time()*1000)) # Convert timestamp to base 36

r = [''] * 36
r[8] = r[13] = r[18] = r[23] = "_"
r[14] = "4"

for i in range(36):
if not r[i]:
o = int(random.random() * t)
r[i] = e[3 & o | 8 if i == 19 else o]

return "verify_" + n + "_" + "".join(r)

def base36_encode(number):
"""Converts an integer to a base36 string."""
alphabet = '0123456789abcdefghijklmnopqrstuvwxyz'
base36 = []

while number:
number, i = divmod(number, 36)
base36.append(alphabet[i])

return ''.join(reversed(base36))

print(create_s_v_web_id())
Loading

0 comments on commit 0ac2702

Please sign in to comment.