<?php
require_once('congif.php');
mysql_connect("$host","$user","$password") or die("无法连接MySQL数据库服务器！");
$db = mysql_select_db("$dbname") or die("无法连接数据库！");
mysql_query("set names 'gbk'");
$connection = mysql_connect ("$host","$user","$password") or die ('不能连接到MySQL Server: '.mysql_error());
mysql_select_db($dbname) or die ('不通选择数据库');
$timestamp = time();
$members= $dbqianzhui.'_members';
$topic= $dbqianzhui.'_topic';
$qqsend= $dbqianzhui.'_qq_send';
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$ExternalId = trim($_POST["ExternalId"]);
$Sender = trim($_POST["Sender"]);
$Message = trim($_POST["Message"]);
if ($ExternalId >"0"){
$sql = "select * from $members where qq='$Sender'";
$rst = mysql_query($sql) or die("无法执行SQL语句：$sql ！");
$row = mysql_fetch_array($rst);
$rowcount = $row["content"];
if ($row['uid']){
if ($Message ==$Sender){
$sql="UPDATE $members SET qq='' WHERE qq=".$Sender;
mysql_query($sql);
echo($jiechu);
$msg='';
}
if (strpos($Message,$zifuchuan) !== false) {
$didaa = explode($zifuchuan,$Message);
$sql = "select uid,username from $members where qq=".$Sender;
$rst = mysql_query($sql) or die("无法执行SQL语句：$sql ！");
$row = mysql_fetch_array($rst);
$winduid = $row['uid'];
$username = $row['username'];
$username= mb_convert_encoding($username,"GBK","UTF-8");
$neir = mb_convert_encoding($didaa[1],"GBK","UTF-8");
$sql="INSERT INTO $topic (`tid` ,`uid` ,`username` ,`content` ,`content2` ,`imageid` ,`videoid` ,`musicid` ,`roottid` ,`replys` ,`totid` ,`touid` ,`tousername` ,`dateline` ,`lastupdate` ,`from` ,`forwards`)
VALUES (NULL , '$winduid', '$username', '$neir', '', '0', '0', '0', '0', '0', '0', '0', '', '$timestamp', '$timestamp', 'qq','0');";
mysql_query($sql);
$sql="UPDATE $members SET topic_count =topic_count+1 WHERE qq=".$Sender;
mysql_query($sql);
echo($chengg);
$msg='';
}
}else{
$msg='请将http://xmutalk.com/?mod=profile&code=qqrobot 页面的验证码发给我，以便完成帐户绑定';
if(preg_match('/^([0-9]+)j([0-9a-f]{32})$/',$Message,$result))
{
$sql = "select password,username from $members where uid=".$result[1];
$rst = mysql_query($sql) or die("无法执行SQL语句：$sql ！");
$row = mysql_fetch_array($rst);
if($result[2] == md5($row['password'].$row['username'])){
echo($bangding);
$sql="UPDATE $members SET qq=$Sender WHERE uid=".$result[1];
mysql_query($sql);
$msg='';
}else{
echo($bangdingns);
}
}
}
}elseif	($ExternalId =="-1"){
echo($jiahaoyou);
}elseif ($ExternalId == "-3"){
$sql = "select * from $members where qq='$Sender'";
$rst = mysql_query($sql) or die("无法执行SQL语句：$sql ！");
$row = mysql_fetch_array($rst);
$rowcount = $row["content"];
if ($row['uid']){
$winduid = $row['uid'];
$username = $row['username'];
$username= mb_convert_encoding($username,"GBK","UTF-8");
$neir = mb_convert_encoding($Message,"GBK","UTF-8");
$sql="INSERT INTO $topic (`tid` ,`uid` ,`username` ,`content` ,`content2` ,`imageid` ,`videoid` ,`musicid` ,`roottid` ,`replys` ,`totid` ,`touid` ,`tousername` ,`dateline` ,`lastupdate` ,`from` ,`forwards`)
VALUES (NULL , '$winduid', '$username', '【QQ签名更新】$neir', '', '0', '0', '0', '0', '0', '0', '0', '', '$timestamp', '$timestamp', 'qq','0');";
mysql_query($sql);
$sql="UPDATE $members SET topic_count =topic_count+1 WHERE qq=".$Sender;
mysql_query($sql);
echo($qianm);
}else{
echo($qianmno);
}
}elseif ($ExternalId == "0"){
$sql = "select * from $members where qq='$Sender'";
$rst = mysql_query($sql) or die("无法执行SQL语句：$sql ！");
$row = mysql_fetch_array($rst);
$rowcount = $row["content"];
if ($row['uid']){
if ($Message ==$Sender){
$sql="UPDATE $members SET qq='' WHERE qq=".$Sender;
mysql_query($sql);
echo($jiechu);
$msg='';
}
if (strpos($Message,$zifuchuan) !== false) {
$didaa = explode($zifuchuan,$Message);
$sql = "select uid,username from $members where qq=".$Sender;
$rst = mysql_query($sql) or die("无法执行SQL语句：$sql ！");
$row = mysql_fetch_array($rst);
$winduid = $row['uid'];
$username = $row['username'];
$username= mb_convert_encoding($username,"GBK","UTF-8");
$neir = mb_convert_encoding($didaa[1],"GBK","UTF-8");
$sql="INSERT INTO $topic (`tid` ,`uid` ,`username` ,`content` ,`content2` ,`imageid` ,`videoid` ,`musicid` ,`roottid` ,`replys` ,`totid` ,`touid` ,`tousername` ,`dateline` ,`lastupdate` ,`from`  ,`forwards` )
VALUES (NULL , '$winduid', '$username', '$neir', '', '0', '0', '0', '0', '0', '0', '0', '', '$timestamp', '$timestamp', 'qq','0');";
mysql_query($sql);
$sql="UPDATE $members SET topic_count =topic_count+1 WHERE qq=".$Sender;
mysql_query($sql);
echo($chengg);
$msg='';
}
}else{
$msg='请将http://xmutalk.com/?mod=profile&code=qqrobot 页面的验证码发给我，以便完成帐户绑定';
if(preg_match('/^([0-9]+)j([0-9a-f]{32})$/',$Message,$result))
{
$sql = "select password,username from $members where uid=".$result[1];
$rst = mysql_query($sql) or die("无法执行SQL语句：$sql ！");
$row = mysql_fetch_array($rst);
if($result[2] == md5($row['password'].$row['username'])){
echo($bangding);
$sql="UPDATE $members SET qq=$Sender WHERE uid=".$result[1];
mysql_query($sql);
$msg='';
}else{
echo($bangdingns);
}
}
}
echo($msg);
}else{
}
}else{
$sql = "select * from $qqsend order by id";
$rst = mysql_query($sql) or die("无法执行SQL语句：$sql ！");
$row = mysql_fetch_array($rst);
$rowcount = $row["content"];
if ($row['id']){
echo($aa);
$sql = "delete from $qqsend where id=".$row['id'];
mysql_query($sql);
}
}
?>