http://www.51boxue.net/phper/php-cy/95985.htm
股票資訊查詢功能我們是需要抓取第三方的資料,然後我們再把這些資料進行分析組成自己想要的,下面我們來看一個php 股票資訊查詢類。
GitHub 地址:Github.com/widuu/stock
Exception($result['errMsg'], 1); return; } return $result['retData']; } /** * 輸入拼音或者漢字來擷取股票代號 * @param name string * @return stockid string */ private static function getStockId($name){ $result = self::httpGet( self::SOCKET_SUGGEST.urlencode(iconv('utf-8', 'GBK', $name)),false ); if (empty($result)){ throw new Exception("stock name not exists", 2); return; } $stockid = $result['Result'][0]['code']; $stock = explode('.', $stockid); return $stock[1].$stock[0]; } /** * GET擷取方法 * @param param string 參數 * @author widuu */ private static function httpGet($url,$header=false) { $curlHandle = curl_init(); curl_setopt( $curlHandle , CURLOPT_URL, $url ); if( $header ){ curl_setopt( $curlHandle , CURLOPT_HTTPHEADER , array('apikey:'.self::$apikey)); } curl_setopt( $curlHandle , CURLOPT_RETURNTRANSFER, 1 ); curl_setopt( $curlHandle , CURLOPT_SSL_VERIFYPEER, false); curl_setopt( $curlHandle , CURLOPT_SSL_VERIFYHOST, false); curl_setopt( $curlHandle , CURLOPT_TIMEOUT, 10 ); $content = curl_exec( $curlHandle ); curl_close( $curlHandle ); return $header ? json_decode($content,true) :json_decode(iconv('GBK','utf-8',trim($content)),true); }}//測試代碼stock::getInstance("5040bcbfebb0a4cffc7be278723255aa");print_r(stock::getSingleStock('sh601000'));echo stock::getKline('紫金礦業');?>
以上就介紹了php 股票資訊查詢類,包括了Exception,Git,github方面的內容,希望對PHP教程有興趣的朋友有所協助。