function http_request($url, $data = null)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);

        if (!empty($data)) {
            curl_setopt($curl, CURLOPT_POST, TRUE);
            curl_setopt($curl, CURLOPT_POSTFIELDS,$data);
            curl_setopt($curl, CURLOPT_HTTPHEADER, array(
                'Content-Type: application/json'
            ));
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
        exit();

    }
  function stock(){
       if($_POST){
       $code =  $this->frparam('code',1,'603906');
       $url = "http://yunhq.sse.com.cn:32041//v1/sh1/snap/".$code;
       $info = $this->http_request($url);
      // JsonReturn(['code'=>1,'msg'=>$info]);   
       if(strpos($info,'nginx')){
         JsonReturn(['code'=>1,'msg'=>'code Error!']);  
       }else{
       $info = json_decode($info);
       $dt = $info->date;
       $tm = $info->time;
       $dt = substr($dt,0,4).'.'. substr($dt,4,2).'.'. substr($dt,6,2);
       $tm = substr($tm,0,2).':'. substr($tm,2,2);
       $update=$tm.' '.$dt;
       $data = $info->snap;
        JsonReturn(['code'=>0,'time'=>$update,stp=>$data[5], de=>$data[6], dep=>$data[7],'info'=>$info]); 
          
       }
     }else{
         JsonReturn(['code'=>1,'msg'=>'Request method "GET" not supported']);
     }
 }

标签: none

您需要先登录才能发表评论。