<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 二手房后台系统共用函数文件
 *
 * @package     CodeIgniter
 * @subpackage  Helpers
 * @category    Helpers
 * @author      HOUSE365 ESF Dev Team
 * @link        http://nj.sell.house365.com/
 */

/**
 * 请求接口函数
 * @param   string   $url 接口地址
 * @param   int $nocache  是否需要缓存0加缓存，1清除缓存
 * @return  mixed 接口返回内容
 * @update  2014/5/30 esf dev team
 */
if(!function_exists('get_api'))
{
    function get_api( $url , $nocache = 0 )
    {
        return curl_get_contents($url,$nocache);
    }
}


/**
 * 提供 URL 请求
 * @param   string  $url 请求地址
 * @param   string  $t_url 设置header中"Referer: " 部分的值
 * @return  mixed 返回请求结果
 * @update  2014/5/30 esf dev team
 */
if(!function_exists('curl_get_contents'))
{
    function curl_get_contents( $str , $t_url="")
    {
        $ch = curl_init();
        $t_url = $t_url ? 
                $t_url : "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
        curl_setopt($ch, CURLOPT_URL, $str);
		curl_setopt($ch, CURLOPT_TIMEOUT, 3);
        curl_setopt($ch, CURLOPT_REFERER, $t_url);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);

        $str = curl_exec($ch);
        curl_close($ch);

        return $str;
    }
}

if(!function_exists('curl_post_contents'))
{
    function curl_post_contents($url , $post)
    {
        $ch = curl_init ();
        // print_r($ch);
        curl_setopt ( $ch, CURLOPT_URL, $url);
        curl_setopt ( $ch, CURLOPT_POST, 1);
        curl_setopt ( $ch, CURLOPT_HEADER, 0);
        curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post);
        $return = curl_exec($ch);
        curl_close ( $ch );
        return $return;
    }
}

/**
 * Notes:房源状态变更提醒
 * User: zhangkg
 */
function houseOptions($broker_id,$house_id,$type){

    if(!$broker_id || !$house_id || !$type){
        return false;
    }
    $curl='http://newrent.house365.com/weixin/zsb/house-options';
    $param['broker_id'] = $broker_id;
    $param['house_id'] = $house_id;
    $param['type'] = $type;
    return curl_post_contents($curl,$param);
}


/* End of file common_api_helper.php */
/* Location: ./applications/helpers/common_api_helper.php */