企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
~~~ <?php // +---------------------------------------------------------------------- //wangjikeji.com // 数据调用示例代码 - 网极科技 error_reporting(0); header('Content-Type: text/html; charset=UTF-8'); $url = "http://finance.api51.cn/real?en_prod_code=000001";//请求地址,可携带多个产品代码,用英文逗号隔开。如000001,000002 $content = wangji_curl($url); echo $content; function wangji_curl($url,$params=false,$ispost=0){ $httpInfo = array(); $ch = curl_init(); $appcode = "****";//购买后可获得 购买后在阿里云控制台 云市场 查看 $headers = array(); array_push($headers, "Authorization:APPCODE " . $appcode); 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); } curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); } $response = curl_exec( $ch ); if ($response === FALSE) { //echo "cURL Error: " . curl_error($ch); return false; } $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE ); $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) ); curl_close( $ch ); return $response; } /*返回数据举例 { "code": 200,状态码 "data": { "snapshot": { "000001": [ 产品代码 "上证综指", 产品名称 3217.96, 最新价格 5.52, 涨跌幅 0.17179999999999998, 涨跌额 3219.52, 最高价格 3195.29, 最低价格 3212.44, 今日开盘价 3212.44, 昨日收盘价 1499412603 数据时间 ], "fields": [ "prod_name", "last_px", "px_change", "px_change_rate", "high_px", "low_px", "open_px", "preclose_px", "update_time" ] } } } */ ~~~