86 lines
3.6 KiB
PowerShell
86 lines
3.6 KiB
PowerShell
# ASCII-only script: rewrite .env as UTF-8 BOM; Chinese via unicode escapes
|
|
$ErrorActionPreference = 'Stop'
|
|
$path = 'E:\wwwroot\.env'
|
|
$bak = 'E:\wwwroot\.env.bak-encoding-' + (Get-Date -Format 'yyyyMMdd-HHmmss')
|
|
Copy-Item $path $bak -Force
|
|
Write-Output ('backup=' + $bak)
|
|
|
|
function U([string]$escaped) {
|
|
return [System.Text.RegularExpressions.Regex]::Unescape($escaped)
|
|
}
|
|
|
|
$utf8BomEnc = New-Object System.Text.UTF8Encoding $true
|
|
$raw = [System.IO.File]::ReadAllText($path, $utf8BomEnc)
|
|
|
|
$map = [ordered]@{}
|
|
foreach ($line in ($raw -split "`r?`n")) {
|
|
$t = $line.Trim()
|
|
if (-not $t -or $t.StartsWith('#')) { continue }
|
|
$i = $t.IndexOf('=')
|
|
if ($i -lt 1) { continue }
|
|
$k = $t.Substring(0, $i).Trim()
|
|
$v = $t.Substring($i + 1)
|
|
if (-not $map.Contains($k)) { $map[$k] = $v }
|
|
}
|
|
|
|
# "询价智能体接通成功。已收到:{content}"
|
|
$goodReply = U '\u8be2\u4ef7\u667a\u80fd\u4f53\u63a5\u901a\u6210\u529f\u3002\u5df2\u6536\u5230\uff1a{content}'
|
|
$needFix = $true
|
|
if ($map.Contains('WECOM_CALLBACK_REPLY_TEXT')) {
|
|
$rt = [string]$map['WECOM_CALLBACK_REPLY_TEXT']
|
|
if ($rt -match '\{content\}' -and $rt.Contains([char]0x8BE2) -and $rt.Contains([char]0x4EF7)) {
|
|
$needFix = $false
|
|
}
|
|
}
|
|
if ($needFix) {
|
|
$map['WECOM_CALLBACK_REPLY_TEXT'] = $goodReply
|
|
Write-Output 'fixed_reply_text'
|
|
}
|
|
|
|
function V([string]$k, [string]$default = '') {
|
|
if ($map.Contains($k)) { return [string]$map[$k] }
|
|
return $default
|
|
}
|
|
|
|
$lines = New-Object System.Collections.Generic.List[string]
|
|
$lines.Add((U '# \u53cb\u901a\u8fbe\u8be2\u4ef7\u667a\u80fd\u4f53 \u00b7 \u73af\u5883\u53d8\u91cf\uff08\u670d\u52a1\u5668 E:\\wwwroot\\.env\uff09'))
|
|
$lines.Add((U '# \u7f16\u7801\uff1aUTF-8\uff08\u5e26 BOM\uff0c\u4fbf\u4e8e\u8bb0\u4e8b\u672c\u6b63\u786e\u6253\u5f00\uff09\u3002\u7981\u6b62\u63d0\u4ea4 Git\u3002'))
|
|
$lines.Add((U '# \u5bf9\u7167\uff1aprompt/13-\u73af\u5883\u5bf9\u7167.md'))
|
|
$lines.Add('')
|
|
$lines.Add('YTD_ENV=' + (V 'YTD_ENV' 'test'))
|
|
$lines.Add('')
|
|
$lines.Add((U '# \u516c\u7f51\u4e0e\u4f01\u5fae\uff08\u57df\u540d\u4e0e\u6b63\u5f0f\u76f8\u540c\uff09'))
|
|
$lines.Add('PUBLIC_BASE_URL=' + (V 'PUBLIC_BASE_URL'))
|
|
$lines.Add('WECOM_CALLBACK_URL=' + (V 'WECOM_CALLBACK_URL'))
|
|
$lines.Add('INQUIRY_FORM_PUBLIC_BASE_URL=' + (V 'INQUIRY_FORM_PUBLIC_BASE_URL'))
|
|
$lines.Add('WECOM_CORP_ID=' + (V 'WECOM_CORP_ID'))
|
|
$lines.Add('WECOM_AGENT_ID=' + (V 'WECOM_AGENT_ID'))
|
|
$lines.Add('WECOM_SECRET=' + (V 'WECOM_SECRET'))
|
|
$lines.Add('WECOM_CALLBACK_TOKEN=' + (V 'WECOM_CALLBACK_TOKEN'))
|
|
$lines.Add('WECOM_ENCODING_AES_KEY=' + (V 'WECOM_ENCODING_AES_KEY'))
|
|
$lines.Add('WECOM_CALLBACK_REPLY_TEXT=' + (V 'WECOM_CALLBACK_REPLY_TEXT' $goodReply))
|
|
$lines.Add('WECOM_OPS_AGENT_ID=' + (V 'WECOM_OPS_AGENT_ID'))
|
|
$lines.Add('DEV_INJECT_ENABLED=' + (V 'DEV_INJECT_ENABLED' 'false'))
|
|
$lines.Add('')
|
|
$lines.Add((U '# \u5176\u4f59\u914d\u7f6e\uff08\u7aef\u53e3 / \u5e93 / Redis / \u6a21\u578b\u7b49\uff09'))
|
|
|
|
$written = @(
|
|
'YTD_ENV','PUBLIC_BASE_URL','WECOM_CALLBACK_URL','INQUIRY_FORM_PUBLIC_BASE_URL',
|
|
'WECOM_CORP_ID','WECOM_AGENT_ID','WECOM_SECRET','WECOM_CALLBACK_TOKEN',
|
|
'WECOM_ENCODING_AES_KEY','WECOM_CALLBACK_REPLY_TEXT','WECOM_OPS_AGENT_ID','DEV_INJECT_ENABLED'
|
|
)
|
|
foreach ($k in $map.Keys) {
|
|
if ($written -contains $k) { continue }
|
|
$lines.Add($k + '=' + $map[$k])
|
|
}
|
|
|
|
$text = [string]::Join("`r`n", $lines.ToArray()) + "`r`n"
|
|
[System.IO.File]::WriteAllText($path, $text, $utf8BomEnc)
|
|
|
|
$check = [System.IO.File]::ReadAllText($path, $utf8BomEnc)
|
|
$first = ($check -split "`r?`n")[0]
|
|
Write-Output ('first_line=' + $first)
|
|
Write-Output ('keys=' + $map.Count)
|
|
Write-Output ('reply_has_cn=' + ($check.Contains([char]0x8BE2) -and $check.Contains('{content}')))
|
|
Write-Output 'ENV_REWRITE_OK'
|