第一版修正測試完成 可以用utf-8 傳送 20250523
This commit is contained in:
parent
962acb199f
commit
6d64ba0e85
@ -1,7 +1,6 @@
|
||||
{
|
||||
"apiUrl": "https://superstar.dnsnet.cc",
|
||||
"branchName": "測試",
|
||||
"roomName": "102",
|
||||
"email": "MachineKTV@gmail.com",
|
||||
"password": "aa147258-"
|
||||
}
|
@ -12,7 +12,12 @@ if (!(Test-Path $configPath)) {
|
||||
exit 1
|
||||
}
|
||||
|
||||
$config = Get-Content $configPath | ConvertFrom-Json
|
||||
try {
|
||||
$config = Get-Content $configPath -Encoding UTF8 | Out-String | ConvertFrom-Json
|
||||
} catch {
|
||||
Log "error Failed to read config.json: $($_.Exception.Message)"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Config values
|
||||
$apiUrl = $config.apiUrl.TrimEnd('/') # 移除結尾的 /
|
||||
@ -38,10 +43,13 @@ function Get-Token {
|
||||
|
||||
$url = "$apiUrl/api/room/receiveRegister"
|
||||
Log "curl Requesting token from: $url"
|
||||
# 將送出的 JSON log 起來
|
||||
Log "curl Payload: $body"
|
||||
|
||||
try {
|
||||
$response = Invoke-RestMethod -Uri $url -Method Post `
|
||||
-Body $body -ContentType "application/json"
|
||||
-Body $body `
|
||||
-ContentType "application/json; charset=utf-8"
|
||||
|
||||
if ($response.data.token) {
|
||||
Log "ok Token acquired: $($response.data.token)"
|
||||
@ -57,6 +65,7 @@ function Get-Token {
|
||||
}
|
||||
|
||||
function Send-Heartbeat($token, $ip) {
|
||||
Log "start Send - Heartbeat $token ,$ip"
|
||||
while ($true) {
|
||||
$heartbeat = @{
|
||||
branch_name = $branchName
|
||||
@ -70,7 +79,7 @@ function Send-Heartbeat($token, $ip) {
|
||||
try {
|
||||
Invoke-RestMethod -Uri "$apiUrl/api/room/heartbeat" -Method Post `
|
||||
-Headers @{ Authorization = "Bearer $token" } `
|
||||
-Body $heartbeat -ContentType "application/json"
|
||||
-Body $heartbeat -ContentType "application/json; charset=utf-8"
|
||||
|
||||
} catch {
|
||||
Log "error Heartbeat failed: $($_.Exception.Message)"
|
||||
|
Loading…
x
Reference in New Issue
Block a user