<?php
header("Content-Type:text/html;charset=utf-8");

 
$p	= null;
$p	= new newpost();
global $HTTP_RAW_POST_DATA;
$res = $HTTP_RAW_POST_DATA;
$res=trim($res);
$res=rawurldecode($res);

	
	$ExternalId = trim($_POST["ExternalId"]);
	$Sender = trim($_POST["Sender"]);
	$Message = trim($_POST["Message"]);	
	//$systemid = $data[XML][SYSTEM][SYSTEMID];
	$type = 'qq';
	if ($type=="qq" or $type==""){
if($p->yz($ExternalId,$Sender,$Message))
	{


if( $ExternalId == "0")
		{
			
			$r = $db2->query('SELECT id FROM applications WHERE name="QQ" LIMIT 1');
		
		while($obj = $db2->fetch_object($r)) {
			
			$apiid=$obj->id;
			
			}
			
		}
		else 
		{
			$r = $db2->query('SELECT id FROM applications WHERE name="QQ签名" LIMIT 1');
		
		while($obj = $db2->fetch_object($r)) {
			
			$apiid=$obj->id;
			
			}
		}
	$r = $db2->query('SELECT uid FROM cdb_qq WHERE qq="'.$Sender.'" ');
		
		while($obj = $db2->fetch_object($r)) {
			
			$uid=$obj->uid;
			
			}
	
		
		$p->set_api_id($apiid);
		$p->set_message($Message);
		$tmpu = $network->get_user_by_id($uid);
		$tmpu->info	= $tmpu;
		$tmpu->is_logged	= TRUE;
		$p->set_user_advanced( $network,  $tmpu );
		$res = $p->save();
		if(  $res ) {
			if( $ExternalId == "0")
				echo("您的留言已经同步到微博。");
			else if( $ExternalId == "-3")
				echo("您的签名已经同步到微博。");
			}	

		else 
			{
				echo("微博发布失败");
			}
			
}
}
else{
if ($type=="sms"){
	$r = $db2->query('SELECT id FROM applications WHERE name="短信" LIMIT 1');
		
		while($obj = $db2->fetch_object($r)) {
			
			$apiid=$obj->id;
			
			}
	$r = $db2->query('SELECT id FROM users WHERE tel="'.$Sender.'" ');
		
		while($obj = $db2->fetch_object($r)) {
			
			$uid=$obj->id;
			
			}	
				$p->set_api_id($apiid);
		$p->set_message($Message);
		$tmpu = $network->get_user_by_id($uid);
		$tmpu->info	= $tmpu;
		$tmpu->is_logged	= TRUE;
		$p->set_user_advanced( $network,  $tmpu );
		$res = $p->save();
		if(  $res ) {

			echo("ok");

			}	

		else 
			{
				echo("wrong");
			}
	
}
}
?>
