调用方式

调用get_response函数,第一个参数是接口key,第二个参数是接口地址,第三个参数是get参数列表,第四个参数是post参数列表,以Key-Value数组传值,该函数会带上参数访问该地址,得到对应的数据

注:此处的secret_key皆为大后台的SecretKey(不是OpenSecretKey)
// 调用示例
$url = 'http://{hostname}.qianfanapi.com/api1_2/side/list';

$secret_key = '若不知道该key,请联系千帆';

$get_params = array(
    'start_time'=>0,
    'end_time'=>1999999,
    'limit'=>10,
    'page'=>2   
);

$post_data = array(
    //'side_id'=>118626,
    //'user_id'=>1522202,
    //'content'=>'真贵啊',
);

$ret = get_response($secret_key,$url, $get_params,$post_data);
print_r($ret); 
function get_response($secret_key, $url, $get_params, $post_data = array())
{
    $nonce         = rand(10000, 99999);
    $timestamp  = time();
    $array = array($nonce, $timestamp, $secret_key);
    sort($array, SORT_STRING);
    $token = md5(implode($array));
    $params['nonce'] = $nonce;
    $params['timestamp'] = $timestamp;
    $params['token']     = $token;
    $params = array_merge($params,$get_params);
    $url .= '?';
    foreach ($params as $k => $v) {
        $url .= $k .'='. $v . '&';
    }
    $url = rtrim($url,'&');   
    $curlHandle = curl_init();
    curl_setopt($curlHandle, CURLOPT_URL, $url);   
    curl_setopt($curlHandle, CURLOPT_HEADER, 0);   
    curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);  
    curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, false);  
    curl_setopt($curlHandle, CURLOPT_SSL_VERIFYHOST, FALSE);   
    curl_setopt($curlHandle, CURLOPT_POST, count($post_data));  
    curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $post_data);  
    $data = curl_exec($curlHandle);    
    $status = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE);
    curl_close($curlHandle);    
    return $data;
}
文档更新时间: 2019-11-25 11:50   作者:漫漫