qq查绑接口api代码自己找数据库绑定才能使用!查qq绑定信息api代码 第5张插图

使用教程

域名/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"); class Sql { public $link; public function __construct() { $this->conn(); $this->query('set names utf8'); } //链接数据库 public function conn() { $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()); } //执行查询 public function query($sql) { return mysqli_query($this->link, $sql); } //查询数据 public function get_row($sql) { $res = $this->query($sql); if (!$res) return false; return mysqli_fetch_assoc($res); } //查询全部数据 public function getAll($sql) { $res = $this->query($sql); while ($row = mysqli_fetch_assoc($res)) { $data[] = $row; } return $data; } //报错信息 public function error() { return mysqli_error($this->link); } //关闭数据库链接 public function close() { return mysqli_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; } function jiabai($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 = new Sql; if ($db->get_row("SELECT * FROM `bmd` WHERE `qq` = '{$qq}'")['qq'] != '') { return ['code' => 200, 'msg' => 'QQ:' . $qq . '已在白名单,无需加白']; } if ($db->query("INSERT INTO `bmd` (`qq`) VALUES ('{$qq}')")) { return ['code' => 200, 'msg' => 'QQ:' . $qq . '成功加入白名单']; } else { return ['code' => 200, '加入白名单失败,系统异常']; } } function cha($qq) { $db = new Sql; 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'] ] ]; } echo json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);```