Files
li 1b24994e74 feat: 后端全量更新 - 含所有本次需求
- Contract.php: 返回合约账户余额(balance_contract)
- My.php: 地址管理增加BTC/ETH
- AppContract.php: 一键平仓(closeall)
- AppProxy.php: 代理专属注册链接 + 分级权限(L1/L2)
- site.php: 手续费减半(0.018→0.009)
- agent_permission_setup.sql: 代理权限SQL
- crypto_news_crawler.py: 新闻自动采集脚本
2026-03-30 20:16:32 +08:00
..

介绍

谷歌翻译插件 是一个可以自动调用谷歌翻译,帮您将语言翻译为任意语种。 使用只需要简简单单一句话:

$result = doGoogleTranslate('您好', 'en');
var_dump($result);
output: 
Array[
    'status' => true,
    'data'   => 'hello',
    'msg'    => '',
]

翻译的方法定义如下

/**
 * @param $text 需要翻译的内容-可以是任意语种文本-不超过5000字符
 * @param $toLang 要翻译成目标语种
 * @param string $fromLang 原始文本的语种-不填写可以自动识别-填写错误会导致翻译无效
 * @param bool $useProxy 是否使用代理-可以传入代理 true 自动随机代理 false 不使用代理
 * @param int $timout 超时时间
 * @param int $retryTime 失败重试次数
 * @return array ['status' => boolean 'data' => result, 'msg' => 'errormsg']
 * @throws ErrorException
 */
function doGoogleTranslate($text, $toLang, $fromLang = '', $useProxy = false, $timout = 5, $retryTime = 5){
    ...省略
}

支持全球所有语种-具体可见配置文件
支持失败自动重试

运行环境

  • Linux, OS X or Cygwin, WSL
  • PHP 7.0+
  • Swoole 4.x+ [如果需要使用协程]

查看swoole版本

需要开启短名协程

php --ri swoole

安装翻译代理和使用

默认不需要代理也可以使用,但是调用频率大的时候,需要使用不同IP

  • 安装插件
  • 配置代理阀值

代理阀值是低于配置数量的时候 就会自动从代理网站抓取代理 默认100

  • 配置定时任务

    1. application/command.php文件中 数组加入一行
     'app\admin\command\Proxy',
    
    1. 配置crontab 定时任务-可以10分钟[具体时间你可以自己调节,不要低于5分钟]执行一次
    */10 * * * * /usr/bin/php  /path/think proxy
    

    path 是你的代码根目录

其他

  • 使用指定swoole配置
    假如 你的swoole默认配置是关闭短名或者开启协程情况 可以再启动时候指定配置,比如: 指定运行时候开启短名
php -d swoole.use_shortname=ON think proxy