|
域名/xxx.php?mod=cha&qq=扣扣号码
表8eqq字段username,mobile
<?php
header('content-type:application/json');
header("Access-Control-Allow-Origin:*");
header("Access-Control-Allow-Methods:GET,POST");
classSql
{
public$link;
publicfunction__construct()
{
$this->conn();
$this->query('setnamesutf8');
}
//链接数据库
publicfunctionconn()
{
$DbConfig=[
'host'=>'localhost',
'port'=>3306,
'user'=>'数据库用户名',
'pwd'=>'数据库密码',
'name'=>'数据库名字',
'long'=>false,
];
if(empty($DbConfig['port']))$DbConfig['port']=3306;
$this->link=mysqli_connect($DbConfig['host'],$DbConfig['user'],$DbConfig['pwd'],$DbConfig['name'],$DbConfig['port']);
if(!$this->link)exit(mysqli_connect_error());
}
//执行查询
publicfunctionquery($sql)
{
returnmysqli_query($this->link,$sql);
}
//查询数据
publicfunctionget_row($sql)
{
$res=$this->query($sql);
if(!$res)returnfalse;
returnmysqli_fetch_assoc($res);
}
//查询全部数据
publicfunctiongetAll($sql)
{
$res=$this->query($sql);
while($row=mysqli_fetch_assoc($res)){
$data[]=$row;
}
return$data;
}
//报错信息
publicfunctionerror()
{
returnmysqli_error($this->link);
}
//关闭数据库链接
publicfunctionclose()
{
returnmysqli_close($this->link);
}
}
$mod=$_GET['mod'];
$qq=$_GET['qq'];
switch($mod){
case'cha':
$json=cha($qq);
break;
case'jiabai':
$json=jiabai($qq,$_GET['key']);
break;
default:
$json=['code'=>202,'msg'=>'非法请求'];
break;
}
functionjiabai($qq,$k)
{
$key='abeim.cn';
if($key!=$k)return['code'=>201,'msg'=>'key错误'];
if($qq=='')return['code'=>202,'msg'=>'QQ不能为空'];
if(!If_Qq($qq))return['code'=>203,'msg'=>'QQ格式错误'];
$db=newSql;
if($db->get_row("SELECT*FROM`bmd`WHERE`qq`='{$qq}'")['qq']!=''){
return['code'=>200,'msg'=>'QQ:'.$qq.'已在白名单,无需加白'];
}
if($db->query("INSERTINTO`bmd`(`qq`)VALUES('{$qq}')")){
return['code'=>200,'msg'=>'QQ:'.$qq.'成功加入白名单'];
}else{
return['code'=>200,'加入白名单失败,系统异常'];
}
}
functioncha($qq)
{
$db=newSql;
if($db->get_row("SELECT*FROM`bmd`WHERE`qq`='{$qq}'"))return['code'=>200,'msg'=>'此QQ处于白名单中,禁止查询'];
if($qq=='')return['code'=>201,'msg'=>'QQ不能为空'];
$data=$db->get_row("SELECT*FROM`8eqq`WHERE`username`='{$qq}'");
if($data['username']=='')return['code'=>200,'qq'=>$qq,'msg'=>'库中并没有这个记录'];
else
return[
'code'=>200,
'msg'=>'ok',
'data'=>[
'qq'=>$data['username'],
'mobile'=>$data['mobile']
]
];
}
echojson_encode($json,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
复制代码 |
|