您好,欢迎访问一九零五行业门户网

达人们帮小弟看看【百度PHP翻译AP】I咋用?

$query,
        'appid' => app_id,
        'salt' => rand(10000,99999),
        'from' => $from,
        'to' => $to,
    );
    $args['sign'] = buildsign($query, app_id, $args['salt'], sec_key);
    $ret = call(url, $args);
    $ret = json_decode($ret, true);
    return $ret; 
}
//加密
function buildsign($query, $appid, $salt, $seckey)
{/*{{{*/
    $str = $appid . $query . $salt . $seckey;
    $ret = md5($str);
    return $ret;
}/*}}}*/
//发起网络请求
function call($url, $args=null, $method=post, $testflag = 0, $timeout = curl_timeout, $headers=array())
{/*{{{*/
    $ret = false;
    $i = 0; 
    while($ret === false) 
    {
        if($i > 1)
            break;
        if($i > 0) 
        {
            sleep(1);
        }
        $ret = callonce($url, $args, $method, false, $timeout, $headers);
        $i++;
    }
    return $ret;
}/*}}}*/
function callonce($url, $args=null, $method=post, $withcookie = false, $timeout = curl_timeout, $headers=array())
{/*{{{*/
    $ch = curl_init();
    if($method == post) 
    {
        $data = convert($args);
        curl_setopt($ch, curlopt_postfields, $data);
        curl_setopt($ch, curlopt_post, 1);
    }
    else 
    {
        $data = convert($args);
        if($data) 
        {
            if(stripos($url, ?) > 0) 
            {
                $url .= &$data;
            }
            else 
            {
                $url .= ?$data;
            }
        }
    }
    curl_setopt($ch, curlopt_url, $url);
    curl_setopt($ch, curlopt_timeout, $timeout);
    curl_setopt($ch, curlopt_returntransfer, 1);
    if(!empty($headers)) 
    {
        curl_setopt($ch, curlopt_httpheader, $headers);
    }
    if($withcookie)
    {
        curl_setopt($ch, curlopt_cookiejar, $_cookie);
    }
    $r = curl_exec($ch);
    curl_close($ch);
    return $r;
}/*}}}*/
function convert(&$args)
{/*{{{*/
    $data = '';
    if (is_array($args))
    {
        foreach ($args as $key=>$val)
        {
            if (is_array($val))
            {
                foreach ($val as $k=>$v)
                {
                    $data .= $key.'['.$k.']='.rawurlencode($v).'&';
                }
            }
            else
            {
                $data .=$key=.rawurlencode($val).&;
            }
        }
        return trim($data, &);
    }
    return $args;
}/*}}}*/
?>
回复讨论(解决方案) 直接调用就可以了,但首先你要在百度申请一个app_id
直接调用就可以了,但首先你要在百度申请一个app_id
申请过了。但是不太会用,还有一个htm版本的您看看
nbsp;html>
可打开浏览器控制台查看结果
其它类似信息

推荐信息