<?php
error_reporting(0);
function ifdx($qq, $jcqq, $sid)
{
	$url = get_curl("http://m.qzone.com/friendship/get_friendship?g_tk=" . time() . "&fromuin=" . $qq . "&touin=$jcqq&isReverse=1&res_type=4&refresh_type=1&format=json&sid=" . $sid);
	$json = json_decode($url, true);//print_r($json);

	if ($json["code"] == 0) {

	if ($json["message"] == "请先登录") {
		exit('{"code":1,"msg":"SID已过期，请更新SID!"}');
	}
	else if ($json["data"]["friendShip"][0]["add_friend_time"] == "-1") {
		exit('{"code":0,"is":0}');
	}
	else {
		exit('{"code":0,"is":1}');
	}
	}else{
		exit('{"code":'.$json["code"].',"msg":"'.$json["message"].'"}');
	}
}

function get_curl($url, $post, $referer, $cookie, $header, $ua, $nobaody)
{
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

	if ($post) {
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
	}

	if ($header) {
		curl_setopt($ch, CURLOPT_HEADER, true);
	}

	if ($cookie) {
		curl_setopt($ch, CURLOPT_COOKIE, $cookie);
	}

	if ($referer) {
		curl_setopt($ch, CURLOPT_REFERER, "http://m.qzone.com/infocenter?g_f=");
	}

	if ($ua) {
		curl_setopt($ch, CURLOPT_USERAGENT, $ua);
	}
	else {
		curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; U; Android 4.0.4; es-mx; HTC_One_X Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0");
	}

	if ($nobaody) {
		curl_setopt($ch, CURLOPT_NOBODY, 1);
	}

	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	$ret = curl_exec($ch);
	curl_close($ch);
	return $ret;
}


session_start();
@header("Content-Type: text/html; charset=UTF-8");
$uin = $_POST["uin"];
$sid = $_POST["sid"];
$touin = $_POST["touin"];

ifdx($uin, $touin, $sid);

?>
