代码如下,酌情访问- #&cls&@cd /d "%~dp0" & powershell -c "Get-Content '%~0' | Out-String | Invoke-Expression" & pause&exit
- cls
-
- #whr
- $whr = New-Object -ComObject 'WinHttp.WinHttpRequest.5.1'
- #url
- $url = 'https://www2.deepl.com/jsonrpc?method=LMT_handle_jobs'
- #body请求负载
- $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.'
复制代码
|