fix: 加固支付宝定时任务启动环境 #799
@ -27,4 +27,6 @@ pwsh -File scripts\company-alipay-direct\install-daily-task.ps1
|
||||
|
||||
账号、密码、账户简称和浏览器登录态仅保存在 `runtime/private/`,不会进入 Git。私有文件需包含 `账号:`、`密码:` 和 `支付宝账户简称:` 三项。任一登录失效、验证页面出现、空数据或导入失败都会保留上一版数据并记录日志。
|
||||
|
||||
定时任务通过 `run-alipay-daily.cmd` 启动,并优先使用系统 Node.js;若仅在 Codex 运行时可用,会自动使用当前固定运行时路径。任务宿主错误记录在同目录的 `task-host.log`,业务错误记录在日期日志中。
|
||||
|
||||
账单导入生产时统一通过服务器受限批处理入口执行,使用独立批处理容器、上游同步锁和资源上限;支付宝登录与账单导出仍只在本机运行。
|
||||
|
||||
@ -11,14 +11,12 @@ param(
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
$runner = (Resolve-Path -LiteralPath (Join-Path $PSScriptRoot 'run-alipay-daily.ps1')).Path
|
||||
$windowsPowerShell = Join-Path $env:SystemRoot 'System32\WindowsPowerShell\v1.0\powershell.exe'
|
||||
$cmdPath = (Resolve-Path -LiteralPath (Join-Path $PSScriptRoot 'run-alipay-daily.cmd')).Path
|
||||
$currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
|
||||
$arguments = @(
|
||||
'-NoProfile',
|
||||
'-ExecutionPolicy', 'Bypass',
|
||||
'-WindowStyle', 'Hidden',
|
||||
'-File', ('"' + $runner + '"')
|
||||
'/d',
|
||||
'/c',
|
||||
('""' + $cmdPath + '""')
|
||||
) -join ' '
|
||||
|
||||
if (-not $PSCmdlet.ShouldProcess($TaskName, "register daily Alipay export at $Time")) {
|
||||
@ -51,7 +49,7 @@ try {
|
||||
$trigger.Enabled = $true
|
||||
|
||||
$action = $definition.Actions.Create(0)
|
||||
$action.Path = $windowsPowerShell
|
||||
$action.Path = $env:ComSpec
|
||||
$action.Arguments = $arguments
|
||||
$action.WorkingDirectory = $PSScriptRoot
|
||||
|
||||
|
||||
10
scripts/company-alipay-direct/run-alipay-daily.cmd
Normal file
10
scripts/company-alipay-direct/run-alipay-daily.cmd
Normal file
@ -0,0 +1,10 @@
|
||||
@echo off
|
||||
setlocal EnableExtensions
|
||||
|
||||
set "SCRIPT_DIR=%~dp0"
|
||||
set "LOG_DIR=%SCRIPT_DIR%..\..\runtime\private\alipay-exports\logs"
|
||||
if not exist "%LOG_DIR%" mkdir "%LOG_DIR%"
|
||||
set "TASK_LOG=%LOG_DIR%\task-host.log"
|
||||
|
||||
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_DIR%run-alipay-daily.ps1" %* >> "%TASK_LOG%" 2>&1
|
||||
exit /b %ERRORLEVEL%
|
||||
@ -53,7 +53,19 @@ $localFile = Join-Path $outputDir ('alipay-company-' + $Date + '.csv')
|
||||
if (-not [string]::IsNullOrWhiteSpace($InputFile)) {
|
||||
$localFile = (Resolve-Path -LiteralPath $InputFile -ErrorAction Stop).Path
|
||||
} else {
|
||||
$node = (Get-Command node.exe -ErrorAction Stop).Source
|
||||
$nodeCommand = Get-Command node.exe -ErrorAction SilentlyContinue | Select-Object -First 1
|
||||
$node = if ($null -ne $nodeCommand) { $nodeCommand.Source } else { $null }
|
||||
if ([string]::IsNullOrWhiteSpace($node)) {
|
||||
$nodeCandidates = @(
|
||||
(Join-Path $env:ProgramFiles 'nodejs\node.exe'),
|
||||
(Join-Path $env:USERPROFILE '.cache\codex-runtimes\codex-primary-runtime\dependencies\node\bin\node.exe')
|
||||
)
|
||||
$node = $nodeCandidates | Where-Object { Test-Path -LiteralPath $_ -PathType Leaf } | Select-Object -First 1
|
||||
}
|
||||
if ([string]::IsNullOrWhiteSpace($node)) {
|
||||
Write-Log '未找到 node.exe;未写入财务台账'
|
||||
throw '未找到 Node.js,请安装 Node.js 后重新触发任务'
|
||||
}
|
||||
Write-Log ('开始导出支付宝账单:' + $Date)
|
||||
$exportOutput = (& $node $exportScript ('--date=' + $Date) ('--out=' + $outputDir) 2>&1 | Out-String)
|
||||
if ($LASTEXITCODE -ne 0 -or -not (Test-Path -LiteralPath $localFile -PathType Leaf)) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user