-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathapi.php
More file actions
46 lines (45 loc) · 1.61 KB
/
Copy pathapi.php
File metadata and controls
46 lines (45 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
$method = isset($_POST['method']) ? htmlspecialchars($_POST['method']) : '';
require_once('./db/Pdomysql.php');
$db = Pdomysql::getInstance();
//swoole server IP and port
$ip = '192.168.1.131';
$port = '9503';
switch($method)
{
case 'thridLogin':
$token = isset($_POST['token']) ? htmlspecialchars($_POST['token']) : '';
$username = isset($_POST['username']) ? htmlspecialchars($_POST['username']) : '';
if(empty($token)) { echo 'token must be set.'; exit();}
// write to db
$sql = 'update `qrlogin` set uname="'.$username.'" where token="'.$token.'"';
$status = $db->execute($sql);
$data = [
'method' => 'verify',
'username' => $username,
'token' => $token,
];
// send to swoole server use UDP
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
$msg = json_encode($data);
$len = strlen($msg);
socket_sendto($sock, $msg, $len, 0, $ip, $port);
socket_close($sock);
break;
case 'islogin':
// ajax 轮询 可用(low 逼做法)
$token = isset($_POST['token']) ? htmlspecialchars($_POST['token']) : '';
$where = 'token="'.$token.'"';
$result = $db->fetOne('qrlogin','uname',$where);
if($result){
if(empty($result['uname'])) {
echo 0;
} else {
echo 1;
}
}
break;
default:
echo 'The method is not allowed';
break;
}