chenbo 4 anos atrás
pai
commit
b9d68e2735

+ 0 - 93
lib/input_163_index.class.php

@@ -1,93 +0,0 @@
-<?php
-/**
- * @author:王刚涛
- * 用于获取历史数据各种指数
- * http://hq.sinajs.cn/list=s_sz000002
- */
-
-
-class Input_163_index
-{
-
-    /****
-     * @param $code
-     * @return string
-     * 返回股票指数所属的板块,在股票代码前拼接0或者1
-     */
-    static public function stock_block($code)
-    {
-        $f = substr($code, 0, 1);
-        if ($f == "6" || $f == "0") {
-            $stock_code = "0" . $code;
-        } else {
-            $stock_code = "1" . $code;
-        }
-        return $stock_code;
-    }
-    /****
-     * @param $url
-     * @return array|bool|string
-     * 对curl_setopt进行封装,消除代码冗余
-     */
-    static private function curl_get_data($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);//以换行符进行分割字符串
-        return $content1;
-    }
-
-    static public function get_history_index($stock_code,$start_date,$end_date)
-    {
-        $msg=array();
-        $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
-        $content1=self::curl_get_data($url);
-        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;
-                }
-//                解析返回的历史数据
-                $data['timestamp'] = strtotime($content3[0]);//当日零点的时间戳
-                $data['date'] = (int)date("Ymd",strtotime($content3[0]));//用于创建表
-                $data['code'] = explode("'",$content3[1])[1];
-                $data['name'] = $content3[2];
-                $data['open_price'] = floatval($content3[3]);
-                $data['highest_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_ratio'] = floatval($content3[10]);
-                //将所要存储的数据放入一个数组中
-                $stock_name = $content3[1];
-                if ($data['close_price'] == 0) {//当收盘价为0的时候,表示此时的基于9-3点,所以不存储
-                    continue;
-                }
-                if (!empty($data)) {
-                    $msg= Index_day_k::insert($data);//将这支股票的历史数据存入数据库
-
-                }
-            }
-        }
-        return $msg;
-    }
-
-
-
-
-
-}
-
-?>

+ 1 - 1
setting.inc.php

@@ -33,7 +33,7 @@ function ConverseDate($originDate)
 function EmptyToZero($str)
 {
     $str = trim($str);
-    return (empty($str) ? 0 : $str);
+    return (empty($str) ? '0' : $str);
 }
 
 ?>

+ 0 - 19
task/task_get_history_index.php

@@ -1,19 +0,0 @@
-<?php
-/**
- * Created by PhpStorm.
- * User: 王刚涛
- * Date: 2020/12/1
- * Time: 19:35
- * 获取指数历史的数据
- */
-require('../init.php');
-
-$start_date=20140101;
-$end_date=date("Ymd",time());
-$indexList=Index::getAllList();//获取指数代码
-foreach ($indexList as $key=>$value){
-    Input_163_index::get_history_index($value["code"],$start_date,$end_date);
-}
-
-
-?>

+ 0 - 8
task/task_get_history_index.sh

@@ -1,8 +0,0 @@
-#!/bin/sh
-
-cd /home/wwwroot/default/boniu/task
-echo '正在获取所有股票的历史指数数据...'
-nohup php ./task_get_history_index.php &
-sleep 1s
-echo "完成!"
-sleep 1s