<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Curl_data {
    private $base_url = 'http://yunhuati.mocuz.com:8080';
    private $result = array('status' => 0, 'msg' => '', 'data' => array());

    public function get_topic_type($params=array()){
        $ret = array();
        $params['code']=rand(100,10000);
        $params['encode']=md5("2".$params['code']."8");
        $url =$this->base_url.'/serviceForOld/topicManagementController/getTopicType.do';
        $ret = $this->post($url,$params,0);
        $ret=json_decode($ret,true);
        return $ret;
    }

    public function get_cloud_topic_list($params=array()){
        $ret = array();
        $params['code']=rand(100,10000);
        $params['encode']=md5("2".$params['code']."8");
        $url =$this->base_url.'/serviceForOld/topicManagementController/getTopicInfoBystationMaster.do';
        $ret = $this->post($url,$params,0);
        $ret=json_decode($ret,true);
        return $ret;
    }

    public function get_xf_topic_list($params=array()){
        $ret =array();
        $url =$this->base_url.'serviceForOld/topicManagementController/getIssuedTopic.do';
        $ret =$this->post($url,$params,0);
        $ret=json_decode($ret,true);
        return $ret;
    }
   //post传递
    function post($url, $keysArr, $flag = 0,$timeout=30){
    $ch = curl_init();
    if(! $flag) curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $keysArr);
    curl_setopt($ch, CURLOPT_URL, $url);
    $ret = curl_exec($ch);
    curl_close($ch);
    return $ret;
}


    public function request($method, $type, $params = array()) {
        //域名
        //        $base_url = base_url();
        $this->base_url .= '/serviceForOld/topicManagementController/' . $method . '.do';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->base_url);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
        if ($type === 'POST') {
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
        }
        $ret = curl_exec($ch);
        if(!$ret){
            $this->result['msg'] = curl_error($ch);
        } else {
            $data = json_decode($ret, true);
            $this->result['status'] = 1;
            $this->result['data'] = $data['data'];
        }
        curl_close($ch);
        return $this->result;
    }



}