瀏覽代碼

指数接口

wanggangtao 5 年之前
父節點
當前提交
8015750748

文件差異過大導致無法顯示
+ 1 - 0
api/v1.0/api_boniu_index_day5.php


+ 103 - 0
api/v1.0/demo/api_boniu_index_day5.html

@@ -0,0 +1,103 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+    <title>指数历史数据接口</title>
+    <script type="text/javascript" src="js/jquery.1.9.1.min.js"></script>
+    <script type="text/javascript" src="js/func.common.js"></script>
+    <script type="text/javascript" src="js/func.js"></script>
+    <script type="text/javascript" src="js/jquery.md5.js">//$.md5()</script>
+    <script type="text/javascript" src="js/jquery.base64.js">//$.base64.encode()</script>
+    <script src="js/c.js" type="text/javascript"></script>
+    <script src="js/urchin.js" type="text/javascript"></script>
+    <link href="css/s.css" type="text/css" rel="stylesheet">
+    <link href="css/base.css" type="text/css" rel="stylesheet">
+    <script type="text/javascript">
+        $(function(){
+            $('#btn').click(function(){
+                var method = $('input[name="method"]').val();
+                var timestamp = $('input[name="timestamp"]').val();
+                var sign = $.md5(method+timestamp);
+                var code = $('input[name="code"]').val();
+                var start_date = $('input[name="start_date"]').val();
+                var end_date = $('input[name="end_date"]').val();
+                var index_type = $('input[name="index_type"]').val();
+
+
+                $('#sign').val(sign);
+                $.ajax({
+                    type : 'POST',
+                    data : {
+                        'method'     : method,
+                        'code'       : code,
+                        'start_date' : start_date,
+                        'index_type' : index_type,
+                        'end_date'   : end_date,
+                        'timestamp'  : timestamp,
+                        'sign'       : sign
+                    },
+                    url : "../api.php",
+                    beforeSend :  function(data){
+
+                        $('#Canvas').html('<p>请求处理中...</p>');
+                    },
+                    success :     function(data){
+//                        alert(data);
+                        Process(data);
+                    },
+                    error :       function(request, errtext, e){
+                        $('#Canvas').html('<p><b>发生错误</b></p><p>'+request.status+'<br/>'+errtext+'</p>');
+                    }
+                });
+            });
+        });
+    </script>
+</head>
+<body>
+<div id="head"><p>指数历史数据</p></div>
+<div id="content">
+    <div id="left">
+        <div class ="message"><p>接口返回:</p></div>
+        <div id="Canvas" class="Canvas"></div>
+    </div>
+    <div id="right">
+        <div class ="message"><p>请求数据:</p></div>
+        <form>
+            <p>
+                <span>method:</span>
+                <input type="text" class="input-text"  name="method" value="api_boniu_index_day5"/>
+            </p>
+
+            <p>
+                <span>timestamp:</span>
+                <input type="text" class="input-text"  name="timestamp" value="11111111"/>
+            </p>
+
+            <p>
+                <span>code:</span>
+                <input type="text" class="input-text"  name="code" value="600004"/>
+            </p>
+
+            <p>
+                <span>start_date:</span>
+                <input type="text" class="input-text"  name="start_date" value="2020/11/01"/>
+            </p>
+            <p>
+                <span>end_date</span>
+                <input type="text" class="input-text"  name="end_date" value="2020/12/11"/>
+            </p>
+
+            <p>
+                <span>index_type:0:表示全部指数,1:上证指数,2:深成指数 3:上证50指数 4:沪深300 5:创业板指数 6:科创50指数 </span>
+                <input type="text" class="input-text"  name="index_type" value=0 />
+            </p>
+
+            <p><span>校验码:</span><input type="text" class="input-text" id="sign" readonly/></p>
+            <p><button class="button success small" id="btn" type="button">发送请求</button></p>
+        </form>
+    </div>
+</div>
+
+
+</body>
+</html>

+ 7 - 0
api/v1.0/demo/index.html

@@ -47,6 +47,13 @@
 		<td class="n4"><a href="#" target="_blank">下载文档</a></td>
 	</tr>
 
+	<tr>
+		<td class="n1">1.1</td>
+		<td class="n2"><a href="api_boniu_index_day5.html" target="_blank">获取指数最近5天的数据</a></td>
+		<td class="n3"><a href="api_boniu_index_day5.html" target="_blank">查看Demo</a></td>
+		<td class="n4"><a href="#" target="_blank">下载文档</a></td>
+	</tr>
+
 
 </table>
 </body>

+ 1 - 0
lib/index.class.php

@@ -19,6 +19,7 @@ class Index {
         return $Table_index->getIndexList();
     }
 
+
     /**
      * @return mixed
      * 各种指数入库

+ 6 - 0
lib/index_day_k.class.php

@@ -41,5 +41,11 @@ class Index_day_k {
         return $id;
     }
 
+    static public function getIndexListHistroy($code,$start_date,$end_date,$index_type)
+    {
+        $Table_index_day_k = new Table_index_day_k();
+        return $Table_index_day_k->getIndexListHistroy($code,$start_date,$end_date,$index_type);
+    }
+
 }
 ?>

+ 3 - 0
lib/table/table_index.class.php

@@ -61,5 +61,8 @@ class Table_index extends Table {
 
 
 
+
+
+
 }
 ?>

+ 41 - 3
lib/table/table_index_day_k.class.php

@@ -9,11 +9,8 @@
 
 class Table_index_day_k extends Table {
 
-    protected $base  = "";              //分表的后缀日期,在进行数据库操作的时候"Table_day_k_".$base
     protected $table_name       = "index_day_k";//表名,不带前缀,前缀在config中定义
     protected $table_id         = "index_day_k_id";//指定ID字段名称,必须
-    protected $table_status     = '';//指定状态字段名称,如果有
-    protected $table_order      = '';//指定排序字段名称,如果有
 
 	//数据库结构
 	protected function struct(){
@@ -35,6 +32,47 @@ class Table_index_day_k extends Table {
 		return $attr;
 	}
 
+    public function getIndexListHistroy($start_date,$end_date,$index_type)
+    {
+        //查询语句必须用sql_check_input检查参数
+        $start_date= $this->pdo->sql_check_input(array('number', $start_date));
+        $end_date = $this->pdo->sql_check_input(array('number', $end_date));
+        $sql = "select * from ". $this->table_fullname ." where 1=1 ";
+        if($index_type==1){
+            $stock_code="000001";
+            $sql.=" and index_day_k_code=".$stock_code ;
+        }else if($index_type==2){
+            $stock_code="399001";
+            $sql.=" and index_day_k_code=".$stock_code ;
+        }else if($index_type==3){
+            $stock_code="000016";
+            $sql.=" and index_day_k_code=".$stock_code ;
+        }else if($index_type==4){
+            $stock_code="399300";
+            $sql.=" and index_day_k_code=".$stock_code ;
+        }else if($index_type==5){
+            $stock_code="399006";
+            $sql.=" and index_day_k_code=".$stock_code ;
+        }else if($index_type==6){
+            $stock_code="000688";
+            $sql.=" and index_day_k_code=".$stock_code ;
+        }
+        $where =" and index_day_k_timestamp between ".$start_date." and ".$end_date ;
+        $sql.=$where;
+        $order=" order by index_day_k_timestamp desc";
+        $sql.=$order;
+        $rs = $this->pdo->sqlQuery($sql);
+        $r  = array();
+        if($rs){
+            foreach($rs as $key => $val){
+
+                $r[$key] = $this->dataToAttr($val);
+            }
+            return $r;
+        }else{
+            return $r;
+        }
+    }
 
 
     public function add($attr){