<?php
require_once("config.php");
/*
  //发布分享接口调用示例：
   $ret = add_share('标题','连接地址','内容','简介','图片');
*/
function add_share($title='Mc爱好者',$url='http://www.chshcms.com',$comment,$summary,$pic='')
{

    //字符转成UTF-8发送
    $title=iconv("gb2312", "utf-8", $title);
    $comment=iconv("gb2312", "utf-8", $comment);
    $summary=iconv("gb2312", "utf-8", $summary);

    //发布一条动态的接口地址, 不要更改!!
    $url = "https://graph.qq.com/share/add_share?"
        ."access_token=".$_SESSION["access_token"]
        ."&oauth_consumer_key=".$_SESSION["appid"]
        ."&openid=".$_SESSION["openid"]
        ."&format=json"
        ."&title=".urlencode($title)
        ."&url=".urlencode($url)
        ."&comment=".urlencode($comment)
        ."&summary=".urlencode($summary)
        ."&images=".urlencode($pic);

    $ret = get_url_contents($url);
	return $ret;
}

/*
  //发表微博接口调用示例：
   $ret = add_weibo('标题','连接地址','内容','简介','图片');
*/
function add_weibo($content,$img='',$format='json',$type=1)
{

    //字符转成UTF-8发送
    $format=iconv("gb2312", "utf-8", $format);
    $comment=iconv("gb2312", "utf-8", $comment);

    //发表微博的接口地址, 不要更改!!
    $url  = "https://graph.qq.com/wb/add_weibo?"
        ."access_token=".$_SESSION["access_token"]
        ."&oauth_consumer_key=".$_SESSION["appid"]
        ."&openid=".$_SESSION["openid"]
        ."&format=".$format
        ."&type=".$type
        ."&content=".urlencode($content)
        ."&img=".urlencode($img);
    $ret = get_url_contents($url);
	return $ret;
}

/*
  //获取用户的基本信息 泥称 nickname, 小头像 figureurl, 中头像 figureurl_1, 大头像 figureurl_2
*/
function get_user_info()
{
    $get_user_info = "https://graph.qq.com/user/get_user_info?"
        . "access_token=" . $_SESSION['access_token']
        . "&oauth_consumer_key=" . $_SESSION["appid"]
        . "&openid=" . $_SESSION["openid"]
        . "&format=json";

    $info = get_url_contents($get_user_info);
    $arr = json_decode($info, true);

    return $arr;
}

/*
  //获取远程返回信息
*/
function get_url_contents($url)
{
    if (ini_get("allow_url_fopen") == "1")
        return @file_get_contents($url);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_URL, $url);
    $result =  curl_exec($ch);
    curl_close($ch);

    return $result;
}

