<?php
/**
 * @Cscms 3.5 open source management system
 * @copyright 2009-2013 chshcms.com. All rights reserved.
 * @Author:Cheng Jie
 * @Dtime:2013-06-12
 */
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class CsdjOpen extends CI_Model
{
    function __construct (){
	   parent:: __construct ();
           $this->load->library('session'); //加载session
    }


    /*
       发表同步微博接口调用示例：
    */
    function add_weibo($content,$format='json')
    {
        if(!$this->session->userdata('qq_access_token') || !$this->session->userdata('qq_openid')){
	   return false;
        }

        //字符转成UTF-8发送
        $content=iconv("gbk", "utf-8", $content);
        $url  = "https://graph.qq.com/t/add_t";
        $post = "access_token=".$this->session->userdata('qq_access_token')
            ."&oauth_consumer_key=".CS_Appid
            ."&openid=".$this->session->userdata('qq_openid')
            ."&format=".$format
            ."&content=".urlencode($content);
            $ret = $this->get_url_contents($url,$post);
	return $ret;
    }

    //POST 、 GET
    function get_url_contents($url,$post='',$type='post'){

                $ch = curl_init();
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
                if($type=='post') {
		    curl_setopt($ch, CURLOPT_POST, 1);
                    curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
                }else{
		    curl_setopt($ch, CURLOPT_POST, 0);
                }
		curl_setopt($ch, CURLOPT_USERAGENT, 'cscms');
		$result = curl_exec($ch);
                curl_close($ch);
            return $result;
    }
}
