| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- /**
- * Class Index_gem
- * * @author 王刚涛
- * 日线数据
- */
- class Index_gem {
- public function __construct()
- {
- }
- static public function getInfoById($id)
- {
- $Table_index_gem = new Table_index_gem();
- return $Table_index_gem->getInfoById($id);
- }
- static public function insert($attrs)
- {
- if (empty($attrs)) throw new Exception('参数不能为空', 102);
- $Table_index_gem = new Table_index_gem();
- $id = $Table_index_gem->insert($attrs);
- return $id;
- }
- static public function get_history_index_gem($stock_code,$start_date,$end_date)
- {
- $code = self::stock_block($stock_code);
- $url = "http://quotes.money.163.com/service/chddata.html?code=" . $code . "&start=" . $start_date . "&end=" . $end_date . "&fields=TOPEN;HIGH;LOW;TCLOSE;VATURNOVER;VOTURNOVER;CHG;PCHG";
- //构建所要发送的url
- $curlHandle = curl_init();
- curl_setopt($curlHandle, CURLOPT_URL, $url);
- 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);
- $content1 = explode("\n", $content);//以换行符进行分割字符串
- if (!empty($content1[1])) {
- for ($i = count($content1) - 1; $i >0; $i--) {//排除日期,代码等标题栏
- if (!empty($content1[$i])) {
- $content3 = explode(",", iconv("gbk", "utf-8", $content1[$i]));
- }
- else{
- continue;
- }
- var_dump($content3);
- // 解析返回的历史数据
- $t = explode("-",$content3[0]);
- $date = trim($t[0].$t[1]);
- $time = trim($t[0].$t[1].$t[2]);
- $data['date'] = $date;//用于创建表
- $data['time'] = $time;//用于获取时间戳
- $data['code'] = intval(explode("'",$content3[1])[1]);
- $data['open_price'] = floatval($content3[3]);
- $data['hightest_price'] = floatval($content3[4]);
- $data['lowest_price'] = floatval($content3[5]);
- $data['close_price'] = floatval($content3[6]);
- $data['value'] = floatval($content3[7]);
- $data['amount'] = floatval($content3[8]);
- $data['increase_price'] = floatval($content3[9]);
- $data['increase_value'] = floatval($content3[10]);
- //将所要存储的数据放入一个数组中
- $stock_name = $content3[1];
- if ($data['close_price'] == 0) {//当收盘价为0的时候,表示此时的基于9-3点,所以不存储
- continue;
- }
- if (!empty($data)) {
- $msg= Index_csi300::insert($data);//将这支股票的历史数据存入数据库
- }
- }
- }
- return $msg;
- }
- /***
- * @param $log
- * @return mixed
- * @throws Exception
- *
- */
- static public function add($attrs){
- if (empty($attrs)) throw new Exception('参数不能为空', 102);
- $Table_index_gem = new Table_index_gem();
- $id = $Table_index_gem->add($attrs);
- return $id;
- }
- static public function getList($filter = array(), $count=0, $page=0, $pageSize=0)
- {
- $Table_index_gem = new Table_index_gem();
- return $Table_index_gem->getList($filter, $count, $page, $pageSize);
- }
- }
- ?>
|