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

How to get market prices through PHP stock interface

小云云
Release: 2023-03-22 22:14:01
Original
4244 people have browsed it

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);
Copy after login

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!

Related labels:
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template