代码如下,酌情访问 | | | cls | | | | | | $whr = New-Object -ComObject 'WinHttp.WinHttpRequest.5.1' | | | | $url = 'https://www2.deepl.com/jsonrpc?method=LMT_handle_jobs' | | | | $body = '{"jsonrpc":"2.0","method" : "LMT_handle_jobs","params":{"jobs":[{"kind":"default","sentences":[{"text":"{#txt}","id":0,"prefix":""}],"raw_en_context_before":[],"raw_en_context_after":[],"preferred_num_beams":4}],"lang":{"preference":{"weight":{},"default":"default"},"source_lang_computed":"EN","target_lang":"ZH"},"priority":1,"commonJobParams":{"browserType":1,"formality":null},"timestamp":#time},"id":84240007}' | | | | | | function Trans-Text($txt){ | | | | $whr.Open('POST',$url,$false) | | $whr.SetRequestHeader('content-type','application/json') | | $dat = $body -replace '#txt',$txt -replace '#time',([datetime]::Now - (Get-Date '1970-01-01 08:00:00')).Ticks.ToString().SubString(0,13) | | $whr.Send($dat) | | if($whr.Status -ne 200){ return $whr.StatusText } | | | | $json = [regex]::Unescape($whr.ResponseText) | ConvertFrom-Json | | | | $whr.Abort() | | | | return $json.result.translations[0].beams.sentences.text | | } | | | | Trans-Text -txt 'This sample demonstrates how to read inputs from a gamepad in a Universal Windows Platform (UWP) app.'COPY |
|