class fanyi{
    public function fahui($res)
    {
     $url="http://api.fanyi.baidu.com/api/trans/vip/translate";
     $q=urlencode($res);
     $from="auto";
     $to="auto";
     $appid="你的appid";
     $salt= rand(10000,99999);
     $mishi="你的密钥";
     $sign= md5($appid.$res.$salt.$mishi);

     
     $url="http://api.fanyi.baidu.com/api/trans/vip/translate?q=".$q."&from=".$from."&to=".$to."&app>;
     $result= json_decode($this->crul($url));
    
     $r= (array)$result->trans_result; 
     
    
     echo "yuan:".$r[0]->src;
     echo "<br>";
     echo "result:".$r[0]->dst;
    }
    
    public function crul($url){
        $ch= curl_init();
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,5);
        $file_contect=curl_exec($ch);
        curl_close($ch);
        file_put_contents("ccc", $file_contect);
        return $file_contect;
        
    }
}

 

相关文章:

  • 2021-12-25
  • 2021-07-27
  • 2022-12-23
  • 2022-12-23
  • 2021-07-11
  • 2021-10-21
  • 2021-07-02
猜你喜欢
  • 2022-02-21
  • 2022-02-15
  • 2021-04-10
  • 2021-07-26
  • 2022-01-09
  • 2021-07-11
相关资源
相似解决方案