PS5 Invoke-RestMethod 对字符串 body 默认按 Latin-1 编码导致中文变 ???, 改为手动转 UTF-8 字节数组并声明 charset=utf-8。
This commit is contained in:
1 parent
3faeba0589
commit
eba7d400e1
1 file changed
+5
-2
+5
-2
@@ -25,12 +25,15 @@ function Write-Log($msg) {
|
|||||||
|
|
||||||
function Send-Alert($title, $msg) {
|
function Send-Alert($title, $msg) {
|
||||||
if (-not $FeishuWebhook) { return }
|
if (-not $FeishuWebhook) { return }
|
||||||
$body = @{
|
$json = @{
|
||||||
msg_type = "text"
|
msg_type = "text"
|
||||||
content = @{ text = "[$title] $msg" }
|
content = @{ text = "[$title] $msg" }
|
||||||
} | ConvertTo-Json -Depth 3
|
} | ConvertTo-Json -Depth 3
|
||||||
try {
|
try {
|
||||||
Invoke-RestMethod -Uri $FeishuWebhook -Method Post -Body $body -ContentType "application/json" -TimeoutSec 10
|
# PS5 的 Invoke-RestMethod 对字符串 body 默认按 Latin-1 编码,中文会变成 ???,
|
||||||
|
# 必须手动转 UTF-8 字节数组发送
|
||||||
|
$bytes = [System.Text.Encoding]::UTF8.GetBytes($json)
|
||||||
|
Invoke-RestMethod -Uri $FeishuWebhook -Method Post -Body $bytes -ContentType "application/json; charset=utf-8" -TimeoutSec 10
|
||||||
} catch {
|
} catch {
|
||||||
Write-Log "飞书告警发送失败: $_"
|
Write-Log "飞书告警发送失败: $_"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user