Home  >  Article  >  Backend Development  >  How to get market prices through PHP stock interface

How to get market prices through PHP stock interface

小云云
小云云Original
2018-03-31 16:32:514125browse

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[&#39;format&#39;]=empty($a_parm[&#39;format&#39;])?&#39;json&#39;:$a_parm[&#39;format&#39;];
    $apiurl=empty($a_parm[&#39;apiurl&#39;])?&#39;http://api.k780.com:88/?&#39;:$a_parm[&#39;apiurl&#39;].&#39;/?&#39;;
    unset($a_parm[&#39;apiurl&#39;]);
    foreach($a_parm as $k=>$v){
        $apiurl.=$k.&#39;=&#39;.$v.&#39;&&#39;;
    }
    $apiurl=substr($apiurl,0,-1);
    if(!$callapi=file_get_contents($apiurl)){
        return false;
    }
    //format
    if($a_parm[&#39;format&#39;]==&#39;base64&#39;){
        $a_cdata=unserialize(base64_decode($callapi));
    }elseif($a_parm[&#39;format&#39;]==&#39;json&#39;){
        if(!$a_cdata=json_decode($callapi,true)){
            return false;
        }
    }else{
        return false;
    }
    //array
    if($a_cdata[&#39;success&#39;]!=&#39;1&#39;){
        echo $a_cdata[&#39;msgid&#39;].&#39; &#39;.$a_cdata[&#39;msg&#39;];
        return false;
    }
    return $a_cdata[&#39;result&#39;];
}

$nowapi_parm[&#39;app&#39;]=&#39;finance.stock_realtime&#39;;
$nowapi_parm[&#39;symbol&#39;]=&#39;sh600000&#39;;
$nowapi_parm[&#39;appkey&#39;]=&#39;10003&#39;;
$nowapi_parm[&#39;sign&#39;]=&#39;b59bc3ef6191eb9f747dd4e83c99f2a4&#39;;
$nowapi_parm[&#39;format&#39;]=&#39;json&#39;;
$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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn