param( [Parameter(Mandatory)][ValidatePattern('^(?:[0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$')][string]$DeviceMac, [Parameter(Mandatory)][guid]$ClientUuid, [ValidateSet('ShowCode', 'CheckActivation')][string]$Mode = 'ShowCode' ) $ErrorActionPreference = 'Stop' $uuid = $ClientUuid.ToString() if ($uuid[14] -ne '4' -or $uuid[19] -notmatch '[89ab]') { throw 'Use the same UUID v4 as the firmware.' } $url = 'https://api.tenclass.net/xiaozhi/ota/' $headers = @{ 'Device-Id' = $DeviceMac.ToLowerInvariant() 'Client-Id' = $uuid 'Activation-Version' = '1' 'Accept-Language' = 'zh-CN' } $request = @{ Uri = $url; Method = 'Post'; Headers = $headers; UserAgent = 'lckfb-bk7258/1.0.0' ContentType = 'application/json'; TimeoutSec = 20; ErrorAction = 'Stop' } if ($Mode -eq 'CheckActivation') { $request.Uri = $url + 'activate' $result = Invoke-WebRequest @request -UseBasicParsing -Body '{}' Write-Output ("Activation HTTP {0}" -f [int]$result.StatusCode) return } $payload = @{ version = 2; language = 'zh-CN'; chip_model_name = 'bk7258' mac_address = $headers['Device-Id']; uuid = $uuid application = @{ name = 'bk7258-xiaozhi'; version = '1.0.0' } board = @{ type = 'bk7258'; name = 'lckfb-bk7258' } } | ConvertTo-Json -Depth 4 -Compress $result = Invoke-RestMethod @request -Body $payload if (!$result.activation.code) { Write-Output 'The OTA service returned no activation code.' return } # Keep the one-time code out of serial captures, console transcripts and files. Add-Type -AssemblyName System.Windows.Forms [void][System.Windows.Forms.MessageBox]::Show( ("Enter this code in your account at xiaozhi.me and close this window:`r`n`r`n{0}" -f $result.activation.code), 'XiaoZhi device activation')