import base64
import ctypes
import hashlib
import hmac
import json
import math
import random
import time
from datetime import datetime

import execjs
import requests

from path import getRandomPath

ctx1 = execjs.compile(open('./src.js', 'r').read())


def left_shift(based, counter):
    # a << 5
    val = based << (counter % 32)
    maxint = 2147483647
    if not -maxint - 1 <= val <= maxint:
        val = (val + (maxint + 1)) % (2 * (maxint + 1)) - maxint - 1
    return val


def unsigned_right_shift(n, i):
    """
    js中 >>>
    :param n:
    :param i:
    :return:
    """
    x, y = ctypes.c_uint32(n).value, i % 32
    return ctypes.c_uint32(x >> y).value


def Y0(Z0, h0):
    # a |= b
    return unsigned_right_shift(Z0, h0) | left_shift(Z0, (32 - h0))


def createPx1(t):
    t = '' + str(t)
    e = 0
    n = 0
    for r in range(len(t)):
        # print(n, ord(t[r]))
        n = left_shift(n, 5) - n + ord(t[r])
        n = Y0(n, 0)
        # print(r, n)

    e = n
    e |= 0
    if e < 0:
        e += 4294967296
    return hex(e)[2:]


def encrypt(data, param):
    n = bytearray()
    if isinstance(data, str):
        bytess = data.encode()
    else:
        bytess = data
    for i in bytess:
        n.append(i ^ param)
    return n


def randomInt(param, param1):
    return random.randint(param, param1)


def randomFloat(a, b):
    return random.random() * (b - a) + a


class PxEnv():
    def __init__(self, url, sid, vid, ts, num1, num2, str1, uuid, startTs, startTs2, performanceNow, px11280,
                 px755='', token='', token2='',
                 hash='', hash2='', hashv=''):
        # o1oo11
        self.hash = hash
        self.hash2 = hash2
        self.hashv = hashv
        # 11oo1o
        self.token = token
        self.token2 = token2
        self.px755 = px755
        self.ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36';

        # 初始化参数
        self.url = url
        self.sid = sid
        self.vid = vid
        self.ts = ts
        self.num1 = num1
        self.num2 = num2
        self.str1 = str1
        self.uuid = uuid
        self.startTs = startTs
        self.startTs2 = startTs2
        self.performanceNow = performanceNow
        self.px11280 = px11280
        totalJSHeapSize = randomInt(35903195, 39903195)
        self.memory_data = dict(
            totalJSHeapSize=totalJSHeapSize,
            usedJSHeapSize=math.floor(randomFloat(0.65, 0.9) * totalJSHeapSize),
            jsHeapSizeLimit=4294705152
        )
        self.mouses = []
        self.createMouse()

    @property
    def memory(self):
        self.memory_data['usedJSHeapSize'] = self.memory_data['usedJSHeapSize'] + randomInt(1903195, 2903195)
        return self.memory_data

    def _to_json(self, data):
        return json.dumps(data, separators=(',', ':'))

    def get_px11590(self):
        px11590_d = {"PX11431": int(self.ts),
                     "PX12454": int(self.num1),
                     "PX11701": self.num2[:80],
                     "PX11529": self.memory_data.get('usedJSHeapSize'),
                     "PX11555": self.memory_data.get('jsHeapSizeLimit'),
                     "PX11833": self.memory_data.get('totalJSHeapSize'),
                     "PX11840": datetime.now().strftime('%a %b %d %Y %H:%M:%S GMT+0800 (中国标准时间)'),
                     "PX12573": self.getPX12573(math.floor(int(self.ts) / 1e3), self.vid, self.uuid),
                     "PX11804": self.createPX2(self.ua, self.uuid),
                     "PX12118": self.str1,
                     "PX11746": self.createPX2(self.ua, self.vid),
                     "PX11371": self.createPX2(self.ua, self.sid),
                     "PX12501": self.md5(self.vid),
                     "PX12169": 1, "PX11902": 1,
                     "PX11560": self.performanceNow + randomInt(1000, 2500),
                     "PX11332": self.startTs + randomInt(1000, 2500),
                     "PX12248": 3600,
                     "PX11385": self.startTs,
                     "PX12280": self.px11280,
                     "PX11496": self.uuid,

                     "PX11663": "9f762773",
                     "PX12347": "dae10548",
                     "PX12389": "",
                     "PX11883": "a3d12c4",
                     "PX11959": "82002457",
                     "PX12483": "a3d12c4",
                     "PX12477": True,
                     "PX11847": True,
                     "PX12588": "unknown",
                     "PX12555": {
                         "plugext": {
                             "0": {
                                 "f": "internal-pdf-viewer",
                                 "n": "PDF Viewer"
                             },
                             "1": {
                                 "f": "internal-pdf-viewer",
                                 "n": "Chrome PDF Viewer"
                             },
                             "2": {
                                 "f": "internal-pdf-viewer",
                                 "n": "Chromium PDF Viewer"
                             },
                             "3": {
                                 "f": "internal-pdf-viewer",
                                 "n": "Microsoft Edge PDF Viewer"
                             },
                             "4": {
                                 "f": "internal-pdf-viewer",
                                 "n": "WebKit built-in PDF"
                             }
                         },
                         "plugins_len": 5
                     },
                     "PX12583": {
                         "smd": {
                             "ok": True,
                             "ex": False
                         }
                     },
                     "PX12582": 3,
                     "PX12587": False,
                     "PX12036": True,
                     "PX12356": True,
                     "PX11522": True,
                     "PX12204": True,
                     "PX12408": [
                     ],
                     "PX12053": True,
                     "PX12029": False,
                     "PX11503": True,
                     "PX11570": True,
                     "PX11406": True,
                     "PX12449": True,
                     "PX11636": False,
                     "PX11650": True,

                     "PX12330": "109|66|66|70|80",
                     "PX11705": 111,
                     "PX11938": True, "PX11602": True, "PX12021": "false", "PX12421": "false", "PX12124": 1,
                     "PX11609": 1,
                     "PX12291": "", "PX11881": ["app", "csi", "loadTimes"], "PX12207": 0, "PX11538": 2,
                     "PX11984": "TypeError: Cannot read properties of None (reading '0')\n    at he (https://client.px-cloud.net/PXVb73hTEg/main.min.js:1136:13)\n    at Zo (https://client.px-cloud.net/PXVb73hTEg/main.min.js:3320:22)\n    at Eo (https://client.px-cloud.net/PXVb73hTEg/main.min.js:2892:23)\n    at https://client.px-cloud.net/PXVb73hTEg/main.min.js:3265:9",
                     "PX11645": "https://booking.flyfrontier.com/Flight/Select", "PX11597": [],
                     "PX12023": "https%3A%2F%2Fbooking.flyfrontier.com%2FFlight%2FSelect", "PX11337": False,
                     "PX12544": True, "PX12589": "succeeded", "PX11524": True,
                     "PX11843": 1920,
                     "PX11781": 1080,
                     "PX12121": 1920,
                     "PX12128": 1055,
                     "PX12387": "1920X1080",
                     "PX12003": 24,
                     "PX11380": 24,
                     "PX11494": 906,
                     "PX12411": 853, "PX12443": 0, "PX12447": 0, "PX11533": True, "PX12079": False, "PX12278": True,
                     "PX11694": False, "PX12294": False, "PX12514": True,
                     "PX12515": "TypeError: Cannot read properties of undefined (reading 'width')", "PX12516": "webkit",
                     "PX12517": 33, "PX12518": False, "PX12545": False, "PX12593": False,
                     "PX12595": "AudioData.SVGAnimatedAngle.SVGMetadataElement",
                     "PX12069": ["Chrome PDF Viewer", "Chromium PDF Viewer", "Microsoft Edge PDF Viewer", "PDF Viewer",
                                 "WebKit built-in PDF"], "PX12286": 5, "PX11576": True, "PX12318": True,
                     "PX11384": True,
                     "PX11886": True, "PX11583": "en-US", "PX12458": "MacIntel", "PX11681": ["en-US"],
                     "PX11754": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36",
                     "PX12037": True, "PX11390": -480, "PX11621": 8, "PX11657": 1, "PX12081": "Gecko",
                     "PX11908": "20030107",
                     "PX12314": "5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36",
                     "PX11829": True, "PX11464": True, "PX12054": 2, "PX11821": "Netscape", "PX11479": "Mozilla",
                     "PX11674": True, "PX12241": 400, "PX11372": False, "PX11683": 1.5, "PX11561": "3g",
                     "PX11877": True,
                     "PX12100": True, "PX12506": "arm", "PX12507": "64", "PX12509": False, "PX12510": "",
                     "PX12511": "macOS",
                     "PX12512": "13.5.0", "PX12513": "117.0.5938.149", "PX12548": True, "PX12578": {},
                     "PX12579": {"support": True,
                                 "status": {"effectiveType": "3g", "rtt": 400, "downlink": 1.5, "saveData": False}},
                     "PX12508": [{"brand": "Google Chrome", "version": "117"}, {"brand": "Not;A=Brand", "version": "8"},
                                 {"brand": "Chromium", "version": "117"}], "PX12549": True,
                     "PX11539": "64556c77",
                     "PX11528": "", "PX12271": "10207b2f", "PX11849": "10207b2f", "PX12464": "90e65465",
                     "PX11356": True,
                     "PX12426": True, "PX11791": True, "PX11517": True, "PX12520": True,
                     "PX12524": "4YC14YCd4YCd4YCV4YCe4YCX4YGS5J256aus7r266YaI5oCR7r27",
                     "PX12527": "3207084bd110f1ac964863e23aa78e04",
                     "PX12260": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36",
                     "PX12249": False, "PX11897": "90e65465", "PX12597": 2, "PX11526": False, "PX11684": False,
                     "PX11812": False, "PX12335": True, "PX12080": 0, "PX11678": False, "PX11349": "visible",
                     "PX12397": False, "PX11387": 0, "PX12150": 1920, "PX12304": True, "PX11651": 970,
                     "PX11867": "missing",
                     "PX12254": True, "PX11540": True, "PX11548": False, "PX11446": True, "PX12550": 1, "PX12431": 0,
                     "PX11991": 10, "PX11837": 34, "PX11632": 0, "PX11409": 9, "PX11508": "49e5084e",
                     "PX11452": "7c5f9724",
                     "PX12218": "65d826e0", "PX12481": "a9269e00", "PX11780": "50a5ec55", "PX12551": "https:",
                     "PX12553": "Asia/Shanghai", "PX12567": "w3c", "PX12576": "screen",
                     "PX12594": False, "PX12566": False,
                     "PX12571": "74d9c66", "PX12581": "default", "PX11303": False, "PX11515": False, "PX12133": False,
                     "PX12340": False, "PX11738": False, "PX11723": False, "PX11389": False, "PX11839": False,
                     "PX11460": False, "PX12102": False, "PX11378": False, "PX12317": False, "PX12564": None,
                     "PX12565": -1,
                     }
        noPx1, noPx2 = self.getNoPx(px11590_d)
        px11590_d[noPx1] = noPx2
        data = {"t": "PX11590",
                "d": px11590_d}
        return data

    def getPX12573(self, a, b, c):
        t = a * 2866 + ord(b[2])
        return createPx1(t)

    def createPX2(self, e, t):
        h = hmac.new(e.encode(), t.encode(), hashlib.md5)
        t = h.hexdigest()
        return t

    def md5(self, vid):
        m = hashlib.md5()
        m.update(vid.encode())
        return m.hexdigest()

    def getNoPx(self, data):
        return encrypt(data['PX11701'], data['PX11431'] % 10 + 2).decode(), encrypt(data['PX11701'],
                                                                                    data['PX11431'] % 10 + 1).decode()

    def get_px12123(self):
        px12123_d = {
            "PX12108": randomInt(401, 601),
            "PX12414": randomInt(15, 61),
            "PX11984": "TypeError: Cannot read properties of null (reading '0')\n    at he (https://client.px-cloud.net/PXVb73hTEg/main.min.js:1136:13)\n    at Zo (https://client.px-cloud.net/PXVb73hTEg/main.min.js:3320:22)\n    at Eo (https://client.px-cloud.net/PXVb73hTEg/main.min.js:2892:23)\n    at https://client.px-cloud.net/PXVb73hTEg/main.min.js:3265:9",
            "PX12303": "mouseover",
            "PX11699": 58848,
            "PX11987": "True",
            "PX12461": True,
            "PX11652": "#wisepops-instance-429858",
            "PX11902": 3,
            "PX11560": self.performanceNow,
            "PX12280": self.px11280,
            "PX11496": self.uuid,
            "PX12564": None,
            "PX12565": -1,
            "PX11719": True,
            # "PX11379": False,
            # "PX11645": url
        }
        return {
            "t": "PX12123",
            "d": px12123_d
        }

    def get_px11891(self):
        px11891_d = {
            "PX11913": True,
            "PX11900": 240000,
            "PX12159": 1,
            "PX11754": self.ua,
            "PX12256": 0,
            "PX12445": 0,
            "PX11804": self.createPX2(self.ua, self.uuid),
            "PX11746": self.createPX2(self.ua, self.vid),
            "PX11371": self.createPX2(self.ua, self.sid),
            "PX11902": 4,
            "PX11560": self.performanceNow,
            "PX12280": self.px11280,
            "PX11496": self.uuid,
            "PX12564": None,
            "PX12565": -1,
            # // "PX11379": False
        }
        return {
            "t": "PX11891",
            "d": px11891_d
        }

    def get_px11547(self):
        px11547_d = {
            # todo
            "PX12492": "78f763eab3a2082c63c66cf47f9e05a0",
            "PX12570": "78f763eab3a2082c63c66cf47f9e05a0",
            "PX11352": "e089aa3d700a35da7244dd4da7a68f9c",
            "PX12292": "WebKit",
            "PX11811": [],
            "PX11567": "WebKit WebGL",
            "PX12032": "WebGL 1.0 (OpenGL ES 2.0 Chromium)",
            "PX11536": [
                "ANGLE_instanced_arrays",
                "EXT_blend_minmax",
                "EXT_color_buffer_half_float",
                "EXT_disjoint_timer_query",
                "EXT_float_blend",
                "EXT_frag_depth",
                "EXT_shader_texture_lod",
                "EXT_texture_compression_rgtc",
                "EXT_texture_filter_anisotropic",
                "EXT_sRGB",
                "KHR_parallel_shader_compile",
                "OES_element_index_uint",
                "OES_fbo_render_mipmap",
                "OES_standard_derivatives",
                "OES_texture_float",
                "OES_texture_float_linear",
                "OES_texture_half_float",
                "OES_texture_half_float_linear",
                "OES_vertex_array_object",
                "WEBGL_color_buffer_float",
                "WEBGL_compressed_texture_s3tc",
                "WEBGL_compressed_texture_s3tc_srgb",
                "WEBGL_debug_renderer_info",
                "WEBGL_debug_shaders",
                "WEBGL_depth_texture",
                "WEBGL_draw_buffers",
                "WEBGL_lose_context",
                "WEBGL_multi_draw"
            ],
            "PX12149": [
                "[1, 1]",
                "[1, 64]",
                8,
                "yes",
                8,
                24,
                8,
                16,
                32,
                16384,
                1024,
                16384,
                16,
                16384,
                31,
                16,
                16,
                1024,
                "[16384, 16384]",
                "no_fp",
                23,
                127,
                127,
                23,
                127,
                127,
                23,
                127,
                127,
                23,
                127,
                127,
                23,
                127,
                127,
                23,
                127,
                127,
                23,
                127,
                127,
                23,
                127,
                127,
                23,
                127,
                127,
                23,
                127,
                127,
                23,
                127,
                127,
                23,
                127,
                127
            ],
            "PX12352": "Google Inc. (Apple)",
            "PX11455": "ANGLE (Apple, Apple M1 Max, OpenGL 4.1)",
            "PX11534": "WebGL GLSL ES 1.0 (OpenGL ES GLSL ES 1.0 Chromium)",
            "PX12503": "d9153fa5509ac1e988e36776dd8d598a",
            "PX12502": "32fe0262ba56767dfd83466855e47bec",
            "PX11927": "a02e9e2368744e62770d4a78862f75fa",
            "PX12572": "7ec700f02277463745cc71774c12c8aa",
            "PX11477": "126.8696939282454",
            "PX12109": "b908567e93d9ed24c036da7986349e97",
            # todo
            "PX12362": "5a86e326549d99b7d916101a127153a1",
            "PX12491": "be9996f96141c689cda7a1e4e1c28787",
            # todo end
            "PX12130": [
                "Sha256",
                "_init",
                "_open",
                "_close",
                "F9Storage",
                "$",
                "F9Qubit",
                "F9Social",
                "html5",
                "$A",
                "_fbq",
                "_uxa",
                "__core-js_shared__",
                "_",
                "__f9publicCache",
                "ueto_9786ebd4fb",
                "Native2JSBridge",
                "_jelly_sdks",
                "wisepops429858JsonP",
                "_upliftFlag"
            ],
            "PX12351": [
                "jQuery3510402196117429823861",
                "_html5shiv",
                "AccDC1698805894620"
            ],
            "PX11386": [
                "webdriver"
            ],
            "PX12525": "b1199c2b7aa9aa43f16fc345099c3f04",
            "PX12526": "c9a6cb64a9c6b14c5c489fd18fc4c35d",
            "PX11948": 1,
            "PX11685": 10,
            "PX11986": True,
            "PX12299": True,
            "PX12331": True,
            "PX11316": False,
            "PX11448": True,
            "PX12196": "missing",
            "PX12427": [
                "_init",
                "_open",
                "_close",
                "$",
                "$A",
                "_pxCustomAbrDomains",
                "_pxAppId",
                "_Vb73hTEghandler",
                "_fbq",
                "_uxa",
                "__core-js_shared__",
                "_",
                "__f9publicCache"
            ],
            "PX11842": [
                "_html5shiv"
            ],
            "PX12439": [
                "PDF Viewer::Portable Document Format::application/pdf~pdf::text/pdf~pdf",
                "Chrome PDF Viewer::Portable Document Format::application/pdf~pdf::text/pdf~pdf",
                "Chromium PDF Viewer::Portable Document Format::application/pdf~pdf::text/pdf~pdf",
                "Microsoft Edge PDF Viewer::Portable Document Format::application/pdf~pdf::text/pdf~pdf",
                "WebKit built-in PDF::Portable Document Format::application/pdf~pdf::text/pdf~pdf"
            ],
            "PX11993": self.ts,
            "PX12228": "TypeError: Cannot read properties of null (reading '0') at de (https://client.px-cloud.net/PXVb73hTEg/main.min.js:796:13) at func (https://client.px-cloud.net/PXVb73hTEg/main.min.js:4899:19) at ve (https://client.px-cloud.net/PXVb73hTEg/main.min.js:790:13) at https://client.px-cloud.net/PXVb73hTEg/main.min.js:5048:13",
            "PX12288": True,
            "PX12446": 33,
            "PX12236": "fd7149bbfb316699ef918fa7bb7510a8",
            "PX11309": "d41d8cd98f00b204e9800998ecf8427e",
            "PX11551": "fd7149bbfb316699ef918fa7bb7510a8",
            "PX12586": 1,
            "PX11843": 1920,
            "PX11781": 1080,
            "PX12121": 1920,
            "PX12128": 1055,
            "PX12387": "1920X1080",
            "PX12003": 24,
            "PX11380": 24,
            "PX11849": "10207b2f",
            "PX11583": "en-US",
            "PX12458": "MacIntel",
            "PX11681": [
                "en-US"
            ],
            "PX11754": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36",
            "PX12037": True,
            "PX11621": 8,
            "PX11390": -480,
            "PX11678": False,
            "PX11840": datetime.now().strftime('%a %b %d %Y %H:%M:%S GMT+0800 (中国标准时间)'),
            "PX11540": True,
            "PX11539": "64556c77",
            "PX11555": 4294705152,
            "PX11452": "7c5f9724",
            "PX12527": "3207084bd110f1ac964863e23aa78e04",
            "PX11484": [],
            "PX12501": self.md5(self.vid),
            "PX11902": 2,
            "PX11560": self.performanceNow,
            "PX11719": True,
            "PX12280": self.px11280,
            "PX11496": self.uuid,
            "PX12564": None,
            "PX12565": -1
        }
        return {
            "t": "PX11547",
            "d": px11547_d
        }

    def get_px11782(self):
        return {
            "t": "PX11782",
            "d": {
                "PX11719": True,
                "PX11984": "TypeError: Cannot read properties of null (reading '0')\n    at he (https://client.perimeterx.net/PXVb73hTEg/main.min.js:1136:13)\n    at Tc (https://client.perimeterx.net/PXVb73hTEg/main.min.js:3957:26)\n    at Object.Nc [as PX763] (https://client.perimeterx.net/PXVb73hTEg/main.min.js:4044:21)\n    at https://captcha.perimeterx.net/PXVb73hTEg/captcha.js?a=c&u=83398d3d-8aa8-11ee-b037-092ff4a06041&v=&m=0:3:491629\n    at r (https://captcha.perimeterx.net/PXVb73hTEg/captcha.js?a=c&u=83398d3d-8aa8-11ee-b037-092ff4a06041&v=&m=0:3:491049)\n    at Object.L [as onSolvedCallback] (https://captcha.perimeterx.net/PXVb73hTEg/captcha.js?a=c&u=83398d3d-8aa8-11ee-b037-092ff4a06041&v=&m=0:3:491088)\n    at u (https://captcha.perimeterx.net/PXVb73hTEg/captcha.js?a=c&u=83398d3d-8aa8-11ee-b037-092ff4a06041&v=&m=0:3:290410)\n    at Object.r [as controllerCallback] (https://captcha.perimeterx.net/PXVb73hTEg/captcha.js?a=c&u=83398d3d-8aa8-11ee-b037-092ff4a06041&v=&m=0:3:288058)\n    at Pf (https://captcha.perimeterx.net/PXVb73hTEg/captcha.js?a=c&u=83398d3d-8aa8-11ee-b037-092ff4a06041&v=&m=0:3:275662)",
                "PX11933": True,
                "PX11454": "visible",
                "PX12099": "4YCJ4YGQ4YCa4YCG4YCf4YCe4YGQ4YGI4YGD4YGe4YGQ4YCa4YCX4YCT4YCW4YGQ4YGI4YGD4YGe4YGQ4YCf4YCX4YCG4YCT4YGQ4YGI4YGB4YGe4YGQ4YCG4YCb4YCG4YCe4YCX4YGQ4YGI4YGD4YGe4YGQ4YCB4YCR4YCA4YCb4YCC4YCG4YGQ4YGI4YGG4YGe4YGQ4YCB4YCG4YCL4YCe4YCX4YGQ4YGI4YGB4YGe4YGQ4YCQ4YCd4YCW4YCL4YGQ4YGI4YGD4YGe4YGQ4YCW4YCb4YCE4YGQ4YGI4YGA4YGG4YGe4YGQ4YCQ4YCA4YGQ4YGI4YGD4YGe4YGQ4YCT4YGQ4YGI4YGD4YGe4YGQ4YCQ4YCH4YCG4YCG4YCd4YCc4YGQ4YGI4YGB4YGe4YGQ4YCB4YCC4YCT4YCc4YGQ4YGI4YGE4YGe4YGQ4YCB4YCE4YCV4YGQ4YGI4YGD4YGe4YGQ4YCV4YGQ4YGI4YGB4YGe4YGQ4YCC4YCT4YCG4YCa4YGQ4YGI4YGG4YGe4YGQ4YCU4YCd4YCA4YCf4YGQ4YGI4YGD4YGe4YGQ4YCb4YCc4YCC4YCH4YCG4YGQ4YGI4YGG4YGe4YGQ4YCe4YCT4YCQ4YCX4YCe4YGQ4YGI4YGG4YGe4YGQ4YCa4YGG4YGQ4YGI4YGD4YGe4YGQ4YCG4YCX4YCK4YCG4YCT4YCA4YCX4YCT4YGQ4YGI4YGD4YCP",
                "PX11699": 11659,
                "PX755": self.px755,
                "PX12057": "pxCaptcha",
                "PX11490": "booking.flyfrontier.com",
                "PX11874": "en-US",
                "PX12049": False,
                "PX12489": "v1.8.7",
                "PX11902": 6,
                "PX11560": self.performanceNow,
                "PX12280": self.px11280,
                "PX11496": self.uuid,
                "PX12564": None,
                "PX12565": -1
            }
        }

    def get_px12419(self):
        return {
            "t": "PX12419",
            "d": {
                "PX12040": [],
                "PX12170": "PX11994",
                "PX11934": "https://booking.flyfrontier.com/Flight/InternalSelect?o1=DEN&d1=LAS&dd1=2023-11-30&ADT=1&umnr=false&mon=true",
                "PX12160": {},
                "PX11875": self.uuid,
                "PX11844": 0,
                "PX12465": True,
                "PX11393": self.createPX11393(),
                "PX12470": int(time.time() * 1000),
                "PX11698": self.createPX11698(),
                #  p["body"]["offsetWidth"]xp["body"]["offsetHeight"]
                "PX11679": "1904x0",
                "PX11902": 7,
                "PX11560": 14311,
                "PX11719": True,
                "PX12280": self.px11280,
                "PX11496": self.uuid,
                "PX12564": None,
                "PX12565": -1
            }
        }

    def get_px561(self):
        r = requests.get('http://127.0.0.1:3000', params={
            'uuid': self.uuid,
            'hash': self.hash,
            'hash2': self.hash2,
            'hashv': self.hashv,
        })
        print(r.json())
        px1132 = r.json()[0]
        px12590 = r.json()[1]
        px12610 = r.json()[2]

        touchX = round(random.randint(240, 293) + random.random(), 2)
        touchScreenX = round(random.randint(2668, 2695) + random.random(), 6)
        touchY = round(random.randint(25, 30) + random.random(), 2)
        touchScreenY = round(random.randint(640, 660) + random.random(), 6)
        downTime = random.randint()

        return {
            "t": "PX561",
            "d": {
                "PX11719": True,
                "PX11984": "TypeError: Cannot read properties of null (reading '0')\n    at he (https://client.perimeterx.net/PXVb73hTEg/main.min.js:1136:13)\n    at Tc (https://client.perimeterx.net/PXVb73hTEg/main.min.js:3957:26)\n    at bc (https://client.perimeterx.net/PXVb73hTEg/main.min.js:3950:13)\n    at https://captcha.perimeterx.net/PXVb73hTEg/captcha.js?a=c&u=83398d3d-8aa8-11ee-b037-092ff4a06041&v=&m=0:3:491583\n    at r (https://captcha.perimeterx.net/PXVb73hTEg/captcha.js?a=c&u=83398d3d-8aa8-11ee-b037-092ff4a06041&v=&m=0:3:491049)\n    at Object.L [as onSolvedCallback] (https://captcha.perimeterx.net/PXVb73hTEg/captcha.js?a=c&u=83398d3d-8aa8-11ee-b037-092ff4a06041&v=&m=0:3:491088)\n    at u (https://captcha.perimeterx.net/PXVb73hTEg/captcha.js?a=c&u=83398d3d-8aa8-11ee-b037-092ff4a06041&v=&m=0:3:290410)\n    at Object.r [as controllerCallback] (https://captcha.perimeterx.net/PXVb73hTEg/captcha.js?a=c&u=83398d3d-8aa8-11ee-b037-092ff4a06041&v=&m=0:3:288058)\n    at Pf (https://captcha.perimeterx.net/PXVb73hTEg/captcha.js?a=c&u=83398d3d-8aa8-11ee-b037-092ff4a06041&v=&m=0:3:275662)",
                "PX11933": True,
                "PX11454": "visible",
                "PX12099": "4YCJ4YGQ4YCa4YCG4YCf4YCe4YGQ4YGI4YGD4YGe4YGQ4YCa4YCX4YCT4YCW4YGQ4YGI4YGD4YGe4YGQ4YCf4YCX4YCG4YCT4YGQ4YGI4YGB4YGe4YGQ4YCG4YCb4YCG4YCe4YCX4YGQ4YGI4YGD4YGe4YGQ4YCB4YCR4YCA4YCb4YCC4YCG4YGQ4YGI4YGG4YGe4YGQ4YCB4YCG4YCL4YCe4YCX4YGQ4YGI4YGB4YGe4YGQ4YCQ4YCd4YCW4YCL4YGQ4YGI4YGD4YGe4YGQ4YCW4YCb4YCE4YGQ4YGI4YGA4YGG4YGe4YGQ4YCQ4YCA4YGQ4YGI4YGD4YGe4YGQ4YCT4YGQ4YGI4YGD4YGe4YGQ4YCQ4YCH4YCG4YCG4YCd4YCc4YGQ4YGI4YGB4YGe4YGQ4YCB4YCC4YCT4YCc4YGQ4YGI4YGE4YGe4YGQ4YCB4YCE4YCV4YGQ4YGI4YGD4YGe4YGQ4YCV4YGQ4YGI4YGB4YGe4YGQ4YCC4YCT4YCG4YCa4YGQ4YGI4YGG4YGe4YGQ4YCU4YCd4YCA4YCf4YGQ4YGI4YGD4YGe4YGQ4YCb4YCc4YCC4YCH4YCG4YGQ4YGI4YGG4YGe4YGQ4YCe4YCT4YCQ4YCX4YCe4YGQ4YGI4YGG4YGe4YGQ4YCa4YGG4YGQ4YGI4YGD4YGe4YGQ4YCG4YCX4YCK4YCG4YCT4YCA4YCX4YCT4YGQ4YGI4YGD4YCP",
                "PX11699": self.performanceNow,
                "PX1133": 594.2000000476837,
                "PX12126": True,
                "PX11657": 1,
                "PX12501": self.md5(self.vid),
                "PX12520": True,
                "PX11991": 1,
                "PX11837": 0,
                "PX11632": 0,
                "PX11409": 0,
                "PX11926": [
                    {
                        "PX12343": "mouseover",
                        "PX11652": 0,
                        "PX11699": 8221,
                        "PX12270": "true"
                    },
                    {
                        "PX12343": "mouseover",
                        "PX11652": 1,
                        "PX11699": 5353,
                        "PX12270": "true"
                    },
                    {
                        "PX12343": "mouseout",
                        "PX11652": 1,
                        "PX11699": 5405,
                        "PX12270": "true"
                    },
                    {
                        "PX12343": "mouseover",
                        "PX11652": 1,
                        "PX11699": 5405,
                        "PX12270": "true"
                    },
                    {
                        "PX12343": "mouseout",
                        "PX11652": 1,
                        "PX11699": 10795,
                        "PX12270": "true"
                    },
                    {
                        "PX12343": "mouseover",
                        "PX11652": 1,
                        "PX11699": 10795,
                        "PX12270": "true"
                    },
                    {
                        "PX12343": "mouseout",
                        "PX11652": 1,
                        "PX11699": 10825,
                        "PX12270": "true"
                    },
                    {
                        "PX12343": "mouseover",
                        "PX11652": 1,
                        "PX11699": 10825,
                        "PX12270": "true"
                    },
                    {
                        "PX12343": "pointerup",
                        "PX11652": 1,
                        "PX11699": 11157,
                        "PX12270": "true"
                    }
                ],
                "PX11698": self.createPX11698(all=True),
                "PX12160": [
                    "#px-captcha",
                    ""
                ],
                "PX11427": 458,
                "PX12208": 695,
                "PX11824": 530,
                "PX11631": 50,
                "PX11843": 1920,
                "PX11781": 1080,
                "PX11906": [
                    "getAttribute",
                    "className",
                    "nodeName",
                    "nodeName"
                ],
                # 按下的点
                "PX11945": touchX,
                "PX12174": touchY,
                "PX11882": "pointerdown",
                "PX11642": touchScreenX,
                "PX11313": touchScreenY,
                "PX11772": downTime,

                "PX11529": 9232191,
                "PX11555": 4294705152,
                "PX11833": 16707175,
                # 松开的
                "PX12024": touchX,
                "PX11759": touchY,
                "PX11896": "pointerup",
                "PX11633": round(touchScreenX + random.random(), 6),
                "PX11445": touchScreenY,
                "PX12417": upTime,
                "PX12382": [
                    5367
                ],
                "PX11735": True,
                "PX11874": "en-US",
                "PX12205": self.token,
                # todo
                "PX11357": 5053,
                # todo challengeTime sha256
                "PX11360": 374,
                "PX12563": "51db060f8b387c240edbcff07da87103e9af772f8533f456663d9a565e0b8274",
                "PX11321": random.randint(11179, 12179),
                "PX11351": False,
                "PX11919": False,
                "PX11710": False,
                "PX12407": False,
                "PX12411": 853,
                "PX11494": 1920,
                "PX12265": 1,
                "PX11706": "PX12374",
                "PX12489": "v1.8.7",
                "PX12499": False,
                "PX12500": False,
                "PX12521": True,
                "PX12522": False,
                "PX12528": False,
                "PX12529": True,
                "PX12585": "https://booking.flyfrontier.com/Flight/InternalSelect?o1=DEN&d1=LAS&dd1=2023-11-30&ADT=1&umnr=false&mon=true",
                "PX12596": False,
                "PX12538": True,
                "PX12537": 5,
                "PX12544": True,
                "PX12589": "succeeded",
                # todo 返回值不同
                "PX12590": px12590,
                # createPX1132
                "PX1132": px1132,
                "PX12610": px12610,
                "PX12504": random.randint(11179, 12179),
                "PX12547": False,
                "PX11902": 5,
                "PX11560": self.performanceNow,
                "PX12280": self.px11280,
                "PX11496": self.uuid,
                "PX12564": None,
                "PX12565": -1
            }
        }

    def createPX11393(self):
        # "-9,-6,2889|-8,-6,2903|-7,-7,2926|-6,-6,2931|-5,-5,2946|-8,-7,2962|-6,-7,2976|-13,-12,3006|-5,-2,3035|-8,-8,3039"
        res = []
        t = random.randint(2260, 3360)
        for i in range(random.randint(3, 10)):
            x = random.randint(-20, -2)
            y = random.randint(-20, -2)
            res.append(f'{x},{y},{t}')

            t += random.randint(4, 8)
        return '|'.join(res)

    def createPX11698(self, all=False):

        # [
        #     "814,595,3644"
        #     "799,582,3678"
        #     "788,571,3702"
        #     "774,557,3732"
        #     "756,543,3792"
        # ]
        lens = len(self.mouses) if all else random.randint(3, 5)
        t = random.randint(3260, 3560)
        res = []
        for i in self.mouses[:lens]:
            x, y = i
            res.append(f'{x},{y},{t}')
            t += random.randint(25, 45)

        return res

    def createMouse(self):
        paths = getRandomPath(50)
        t = random.randint(3260, 3560)
        res = []
        for i in range(random.choice([40, 50])):
            x = int(paths[i]['x'])
            y = int(paths[i]['y'])
            res.append((x, y))
            t += random.randint(25, 45)
        self.mouses = res


if __name__ == '__main__':
    a2 = "WQcHBwdZFAsEAV0OWFobCxwGAVhZX14LWVgPFhYWFgdZWQdZWQcHFFBdWF4KDVENRVAMWFlFWVkNDUUJCgwJRV4LCVBQX1xQC1xQCxQcGh0NFhYWFllZB1lZWRRQW11bDltZCV5ZX1xaXl9eCQtYDl1RW1pRDl5cDl5QXw4LW1FfClgLXwxQWVtbDFBeX11RXFlfCVsKClkNUF9eFhYWFgdZWVkHBwcHFF9aX1kWFhYWWVlZBwdZFAsLFF5YFD1aLhwyPiYYDC89UTwvLlwnH1VVFhYWFgdZWVkHBwdZFFlfWFlYX1xQWV5ZXlgWFhYWWVlZB1kHFFlbWFFcXFFaWl5ZXF1ZUVxYWl9ZFhYWFlkHWQcHWRQLCwtSWBYWFhZZWVkHB1kUDhgUXlgUWRYWFhYHWQcHWQcUUF1YXgkJXQ1FUAxYWUVZWQ0NRQkKDAlFWlpdDFENDlxaC1xYFFtZXVteWFhYFBwaHQ0WFhYWB1kHB1lZFFkUXQ5bClBfDFBRWFFZWVkKCQ5YXVlfXw4NCgsLDA5dWFFbUVxcXgxRWAkNWVoKWwxZDgkNCg5RDAsKWF8LXBRRWVEMWV1RXlhcWV1aCg5eDlteCl1cCl8LC18KDlxeCQpaCVtYW1BRUFlfXV9dXlAKClpcUVhbCgsOCQpfXQpfFFlaFA4JBBsNFhYWFllZBwdZBxRZFFBdWAleCVhYRVAMWFlFWVkNDUUJCwkMRV1dUFAKW1hfC1gMCxRQWllYFApaW1hcXwlRDQsKDA0KWAleDlgLUFtfC1kKCQ4NXVxYDVBbXFheXFgJWFwJW1xaCVwLWAkKXVxdXllaClFfUVFdXQpfC18OCQxYDVpZXwlcWlAJXVtaDF9fXVpYC11dCgtbXw5RXF4KCV5aDVkNC1heWQtQC14KDFwMClBcX15cN1dSVlMUWBQmKRYWFhYHWVkHWVkUUF1YXgpQCg1FUAxYWUVZWQ0NRQkKDAlFXgsJUFBfXFALXFALFhYWFllZWQcHWRQaDhReWBRZFhYWFgdZB1lZWRQLHQ=="
    a2 = 'B1lZWQcHB1kUWV9YWVlbX1BdXFhYXBYWFhZZWVkHWQcUXlFQX19YWV9dUF9aXl5fXF9fX14WFhYWB1kHWVlZFAsdFhYWFllZWQcHWRQOGBReWBRZFhYWFgdZBwdZWRRZFA0NWg5cDQpZDVBYX1sMDlwOWA5eXlsNWQpaXFANCVANDF8OXVtbX1hQXgpZDV9QDlsMXl9fXglRDVpQWQ4UCVBaWF1eXVwJXlBbDFAKWVpQW15dWg5ZX1AMXlhZCVhcDlBfUVwMCwpfXgleWVsOWl9cDlheCQtQC1oLWl4OWBRZWhQOCQQbDRYWFhZZWVkHB1kUCwsUXlgUPVouHDI+JhgMLz1RPC8uXCcfVVUWFhYWB1kHB1kHFFxRW1sLUFhYRVAMUVxFWVkNDUVQW1xdRV5aCw5eWl8LDA0MXhRbWV1bXlhYWBQcGh0NFhYWFllZWQcHWRQaDhReWBRZFhYWFgdZWVkHBwcHFF1cXhYWFhZZB1kHB1kUCwsLUlgWFhYWWVkHWVlZFFsJX1gJWF8KCVtaWg1bWAxZCV8KCQ1cXgxaXF9fX1BRCV8JUVEMCV0NX1xfDF9RXlhYDQ1QWgoNXVpaWVhYCg4WFhYWB1lZB1lZBwcUXAlQW10MWFBFUAxRXEVZWQ0NRQoOCQxFCQxeWVsNCgleW19YFBwaHQ0WFhYWB1lZB1lZFFwJUFtdX1xfRVAMUVxFWVkNDUUKDgkMRQkMXllbDQoJXltfWBYWFhZZBwcHB1kUCwQBAxoOCloJGwIBWFldBwYbDFgWFhYWWVkHB1kHFFkUXAlQXlgOXFhFUAxRXEVZWQ0NRVFRXFhFCwwMXg1aC10JCwlcFF5QXVwUXV5ZXl0JWFAODl0NDgxaCQkLUVFRW1EJX19QXVoLXgpaWlxRXgtYXFgLW1gNUF9fWQwMWV1fDAxQUVFQXQoKC1FZXl5ZWgpdWVFfCgtbDg0MXVgMUFEKCloMXFkNDFEOC1kLDA0KDl5ZDlBQDVlcDVFRDFpYX1FbWgtbWVoKDQw3V1tTVBRYFCYp'
    b2 = base64.b64decode(a2.encode())
    for i in bytes(encrypt(b2, 872 % 128)).decode().split('~~~~'):
        print('o11o111o' in i, i)
        tmp = i.split('|')
        if tmp[0] == '11oo1o':
            px755 = tmp[2]
            token = tmp[4].split('_')[0]
            token2 = tmp[4].split('_')[1]
        if tmp[0] == 'o1oo11':
            # "o1oo11|1|22b0f3c54180124fd02b1bcce129b9992f252bc858988104f0632a9640099
            # |5393fe46579bdd80d081f53b9bb41917d06401059d4db662cafd3aa36748aa2b
            # |12|false"
            hash = tmp[2]
            hash2 = tmp[3]
            hashv = tmp[4]
        if tmp[0] == 'o111ooo1':
            ts = tmp[1]
        if tmp[0] == 'o111oooo':
            num1 = int(tmp[1])
        if tmp[0] == '111o1o':
            num2 = tmp[1]

        if tmp[0] == '1oooo1':
            str1 = tmp[1]
        if tmp[0] == 'o1oo1o':
            vid = tmp[1]

        if tmp[0] == 'o11o11':
            sid = tmp[1]
        if tmp[0] == '11o111':
            cs = tmp[1]
        if tmp[0] == 'o11o11oo':
            cts = tmp[1]
    uuid = '4082bd4f-8d94-11ee-82c3-22aacb22c0fa'
    px = PxEnv('https://www.flyfrontier.com/',
               sid, vid, ts, num1, num2, str1, uuid

               , 1700552863875, 1700464712550
               , 1700552863903, 1700552863903, px755=px755, token=token, token2=token2, hash=hash, hash2=hash2,
               hashv=hashv)
    print(json.dumps(px.get_px561()))
    print(json.dumps([px.get_px11590()]))
