first
This commit is contained in:
@@ -14,9 +14,9 @@ import json # JSON处理模块
|
||||
import os # 操作系统接口模块
|
||||
import pickle # 序列化模块
|
||||
import random # 随机数生成模块
|
||||
import shutil
|
||||
import subprocess # 子进程管理模块
|
||||
import time # 时间处理模块
|
||||
from functools import partial
|
||||
from typing import Optional, Tuple, Dict, List, Any # 类型提示
|
||||
|
||||
import requests # HTTP请求库
|
||||
@@ -34,17 +34,25 @@ SLIDE_OFFSET = 290 # 滑块偏移量
|
||||
SLIDE_DURATION = 611 # 滑动持续时间
|
||||
|
||||
|
||||
class MySubprocessPopen(subprocess.Popen): # 自定义子进程类
|
||||
_ORIGINAL_POPEN = subprocess.Popen
|
||||
|
||||
|
||||
class MySubprocessPopen(_ORIGINAL_POPEN): # 自定义子进程类
|
||||
def __init__(self, *args, **kwargs): # 初始化方法
|
||||
kwargs['encoding'] = "UTF-8" # 设置编码为UTF-8
|
||||
super().__init__(*args, **kwargs) # 调用父类初始化
|
||||
|
||||
|
||||
subprocess.Popen = MySubprocessPopen # 替换默认的Popen类
|
||||
os.environ["EXECJS_RUNTIME"] = "Node" # 设置JavaScript运行时为Node.js
|
||||
startupinfo = subprocess.STARTUPINFO()
|
||||
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
||||
subprocess.Popen = partial(subprocess.Popen, encoding='utf-8', startupinfo=startupinfo)
|
||||
|
||||
|
||||
def create_subprocess(*args, **kwargs):
|
||||
kwargs.setdefault("encoding", "utf-8")
|
||||
if hasattr(subprocess, "STARTUPINFO") and hasattr(subprocess, "STARTF_USESHOWWINDOW"):
|
||||
startupinfo = subprocess.STARTUPINFO()
|
||||
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
||||
kwargs.setdefault("startupinfo", startupinfo)
|
||||
return MySubprocessPopen(*args, **kwargs)
|
||||
|
||||
|
||||
def resolve_node_executable() -> str:
|
||||
@@ -53,6 +61,19 @@ def resolve_node_executable() -> str:
|
||||
bundled_node = os.path.join(project_dir, "tools", "node-v20.19.4-win-x64", "node.exe")
|
||||
if os.path.exists(bundled_node):
|
||||
return bundled_node
|
||||
detected = shutil.which("node")
|
||||
if detected:
|
||||
return detected
|
||||
fallback_candidates = [
|
||||
"/usr/bin/node",
|
||||
"/usr/local/bin/node",
|
||||
os.path.expanduser("~/.nvm/versions/node/current/bin/node"),
|
||||
os.path.expanduser("~/.nvm/versions/node/v20.20.2/bin/node"),
|
||||
"/root/.nvm/versions/node/v20.20.2/bin/node",
|
||||
]
|
||||
for candidate in fallback_candidates:
|
||||
if os.path.exists(candidate):
|
||||
return candidate
|
||||
return "node"
|
||||
|
||||
def calculate_seed(t: int) -> str: # 计算验证码种子值
|
||||
@@ -230,7 +251,7 @@ class JM(object): # 聚名网API封装类
|
||||
return False, f"缺少签名脚本: {jsFile_path}" # 返回失败
|
||||
|
||||
try: # 异常处理
|
||||
with subprocess.Popen( # 执行Node.js脚本
|
||||
with create_subprocess( # 执行Node.js脚本
|
||||
[resolve_node_executable(), jsFile_path], # 命令和参数
|
||||
stdin=subprocess.PIPE, # 标准输入
|
||||
stdout=subprocess.PIPE, # 标准输出
|
||||
|
||||
Reference in New Issue
Block a user