服务端
如果到时候用的人多了我可能会停掉。
以下源码,可自行复制放在自己的服务器上,再把上面javascript
中的https://bili.imba97.cn/translate.php
改成你的。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| <?php
header('content-type:application/json;charset=utf-8'); header('Access-Control-Allow-Origin: *');
function curlRequest($ipUrl) {
$curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $ipUrl); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.2) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13'); $resultData = curl_exec($curl); curl_close($curl);
return $resultData;
}
$kw = rawurlencode($_GET['kw']);
$data = curlRequest('https://translate.google.cn/translate_a/single?client=gtx&dt=t&dj=1&ie=UTF-8&sl=auto&tl=zh_CN&q=' . trim($kw));
echo $data;
|