Home > Article > Backend Development > How to get market prices through PHP stock interface
This article mainly shares with you how to obtain market information through the PH and P stock interfaces. It is mainly shared with you in the form of code. I hope it can help everyone.
Paste php to get the market listing code,
Note: The result.lists returned by the Shanghai and Shenzhen stock markets, the Hong Kong stock market, and the U.S. stock market are different
<?php header("Content-Type:text/html;charset=UTF-8"); function nowapi_call($a_parm){ if(!is_array($a_parm)){ return false; } //combinations $a_parm['format']=empty($a_parm['format'])?'json':$a_parm['format']; $apiurl=empty($a_parm['apiurl'])?'http://api.k780.com:88/?':$a_parm['apiurl'].'/?'; unset($a_parm['apiurl']); foreach($a_parm as $k=>$v){ $apiurl.=$k.'='.$v.'&'; } $apiurl=substr($apiurl,0,-1); if(!$callapi=file_get_contents($apiurl)){ return false; } //format if($a_parm['format']=='base64'){ $a_cdata=unserialize(base64_decode($callapi)); }elseif($a_parm['format']=='json'){ if(!$a_cdata=json_decode($callapi,true)){ return false; } }else{ return false; } //array if($a_cdata['success']!='1'){ echo $a_cdata['msgid'].' '.$a_cdata['msg']; return false; } return $a_cdata['result']; } $nowapi_parm['app']='finance.stock_realtime'; $nowapi_parm['symbol']='sh600000'; $nowapi_parm['appkey']='10003'; $nowapi_parm['sign']='b59bc3ef6191eb9f747dd4e83c99f2a4'; $nowapi_parm['format']='json'; $result=nowapi_call($nowapi_parm); var_dump($result); print_r($result);
The above is the detailed content of How to get market prices through PHP stock interface. For more information, please follow other related articles on the PHP Chinese website!