wanggangtao 5 years ago
parent
commit
fdd61ed473
4 changed files with 16 additions and 35 deletions
  1. 5 11
      api/v1.0/demo/index_info.html
  2. 1 1
      api/v1.0/index_info.php
  3. 2 2
      lib/index.class.php
  4. 8 21
      lib/table/table_index.class.php

+ 5 - 11
api/v1.0/demo/index_info.html

@@ -2,7 +2,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-    <title>股票信息接口</title>
+    <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>
@@ -16,8 +16,7 @@
         $(function(){
             $('#btn').click(function(){
                 var method = $('input[name="method"]').val();
-                var index_type = $('input[name="index_type"]').val();
-                var date = $('input[name="date"]').val();
+                var code = $('input[name="code"]').val();
                 var timestamp = $('input[name="timestamp"]').val();
                 var sign = $.md5(method+timestamp);
                 $('#sign').val(sign);
@@ -25,9 +24,7 @@
                     type         : 'POST',
                     data         : {
                         'method' :method,
-                        'index_type' :index_type,
-                        'date' :date,
-
+                        'code' :code,
                         'timestamp' :timestamp,
                         'sign'   : sign
                     },
@@ -68,14 +65,11 @@
             </p>
 
             <p>
-                <span>1:上证指数,2:深成指数 3:上证50指数 4:沪深300 5:创业板指数 6:科创50指数 </span>
-                <input type="text" class="input-text"  name="index_type" value=5 />
+                <span>code:</span>
+                <input type="text" class="input-text"  name="code" value=399006 />
             </p>
 
 
-            <p>
-
-            </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>

File diff suppressed because it is too large
+ 1 - 1
api/v1.0/index_info.php


+ 2 - 2
lib/index.class.php

@@ -18,10 +18,10 @@ class Index {
      * wanggangtao
      * 获取指数的基本信息
      */
-    static public function get_index_info($type)
+    static public function get_index_info($code)
     {
         $Table_index = new Table_index();
-        return $Table_index->get_index_info($type);
+        return $Table_index->get_index_info($code);
     }
 
 

+ 8 - 21
lib/table/table_index.class.php

@@ -64,36 +64,23 @@ class Table_index extends Table {
         }
     }
 
-    public function get_index_info($index_type){
+    /***
+     * @param $code
+     * @return array
+     * 获取指数的基本信息
+     */
+    public function get_index_info($code){
 
         $where=" where 1=1 ";
         $sql = "select "."`*`". "from ". $this->table_fullname . $where ;
-        if($index_type==1){
-            $stock_code="000001";
-            $sql.=" and index_code=".$stock_code ;
-        }else if($index_type==2){
-            $stock_code="399001";
-            $sql.=" and index_code=".$stock_code ;
-        }else if($index_type==3){
-            $stock_code="000016";
-            $sql.=" and index_code=".$stock_code ;
-        }else if($index_type==4){
-            $stock_code="399300";
-            $sql.=" and index_code=".$stock_code ;
-        }else if($index_type==5){
-            $stock_code="399006";
-            $sql.=" and index_code=".$stock_code ;
-        }else if($index_type==6){
-            $stock_code="000688";
-            $sql.=" and index_code=".$stock_code ;
-        }
+        $sql.=" and index_code=".$code ;
         $rs = $this->pdo->sqlQuery($sql);
         $r  = array();
         if($rs){
             foreach($rs as $key => $val){
                 $r[$key] = $this->dataToAttr($val);
             }
-            return $r;
+            return $r[0];
         }else{
             return $r;
         }