PHP – based fund financial data interface call code example associated data: fund financial data interface address: www.juhe.cn/docs/api/id…

  1. [PHP] code
<! -? php // +---------------------------------------------------------------------- // | JuhePHP [ NO ZUO NO DIE ] // +---------------------------------------------------------------------- // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved. // +---------------------------------------------------------------------- // | Author: Juhedata <[email protected]> // +---------------------------------------------------------------------- / / -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - / / fund financial data call sample code - the aggregated data / / online interface document: http://www.juhe.cn/docs/28 //---------------------------------- header('Content-type:text/html; charset=utf-8'); $appKey = "*********************"; / / * * * * * * * * * * * * 1. The main financial indicators of * * * * * * * * * * * * $url = "http://web.juhe.cn:8080/fund/findata/main"; $params= array("key"=> $appKey,// appkey); $paramstring= http_build_query($params); $content= juhecurl($url,$paramstring); $result= json_decode($content,true); if($result){ if($result['error_code']=='0'){ print_r($result); }else{ echo$result['error_code'].":".$result['reason']; }}else{echo" request failed "; } / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * * * * * * * * * * * * 2. The fund size * * * * * * * * * * * * $url = "http://web.juhe.cn:8080/fund/findata/size"; $params= array("key"=> $appKey,// appkey); $paramstring= http_build_query($params); $content= juhecurl($url,$paramstring); $result= json_decode($content,true); if($result){ if($result['error_code']=='0'){ print_r($result); }else{ echo$result['error_code'].":".$result['reason']; }}else{echo" request failed "; } / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / * * * * * * * * * * * * 3. Asset allocation * * * * * * * * * * * * $url = "http://web.juhe.cn:8080/fund/findata/config"; $params= array("key"=> $appKey,// appkey); $paramstring= http_build_query($params); $content= juhecurl($url,$paramstring); $result= json_decode($content,true); if($result){ if($result['error_code']=='0'){ print_r($result); }else{ echo$result['error_code'].":".$result['reason']; }}else{echo" request failed "; } / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / * * * request interface returned content * @ param string $[] to the url request url * @ param string $params[request] * @param int $iPOST [POST] * @return string */ functionjuhecurl($url,$params=false,$isPOST =0){ $httpInfo= array(); $ch= curl_init(); curl_setopt($ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 ); curl_setopt($ch, CURLOPT_USERAGENT , 'JuheData'); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT , 60 ); curl_setopt($ch, CURLOPT_TIMEOUT , 60); curl_setopt($ch, CURLOPT_RETURNTRANSFER , true ); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); if($ispost) { curl_setopt($ch, CURLOPT_POST , true ); curl_setopt($ch, CURLOPT_POSTFIELDS , $params); curl_setopt($ch, CURLOPT_URL , $url); } else { if($params){ curl_setopt($ch, CURLOPT_URL , $url.'? '.$params); }else{ curl_setopt($ch, CURLOPT_URL , $url); } } $response= curl_exec( $ch); if($response=== FALSE) { //echo "cURL Error: " . curl_error($ch); returnfalse; } $httpCode= curl_getinfo( $ch, CURLINFO_HTTP_CODE ); $httpInfo= array_merge($httpInfo, curl_getinfo( $ch) ); curl_close($ch); return$response; }Copy the code