rcube_platform.php
2.7 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/**
* 接入平台
* @author:dc
* @time 2022/7/22 14:10
* Class rcube_email_server_address
*/
class rcube_platform {
const STATUS_ACTIVE = 1;
const STATUS_DISABLED = 0;
private $db;
/**
* 表
* @var string
*/
public $table;
/**
* rcube_platform constructor.
* @param null $db
*/
public function __construct($db = null)
{
$this->db = $db ? $db : rcube::get_instance()->get_dbh();
$this->table = $this->db->table_name('platform',true);
}
public function lists(){
// 查询数据
$result = $this->db->query("select * from ". $this->table);
return $result->fetchAll(PDO::FETCH_ASSOC);
}
/**
* 查询一条数据
* @param $id
* @return array|false
* @author:dc
* @time 2022/7/23 14:50
*/
public function firstById($id)
{
// 查询数据
$result = $this->db->query("select * from ". $this->table ." where `id` = ? limit 1",$id);
return $this->db->fetch_assoc($result);
}
/**
* 查询一条数据
* @param $appid
* @return array|false
* @author:dc
* @time 2022/7/23 14:50
*/
public function firstByAppId($appid)
{
// 查询数据
$result = $this->db->query("select * from ". $this->table ." where `appid` = ? limit 1",$appid);
return $this->db->fetch_assoc($result);
}
/**
* 根据appid获取id
* @param $appid
* @return int|mixed
* @author:dc
* @time 2022/7/23 15:14
*/
public function getIdByAppId($appid){
// 查询数据
$result = $this->db->query("select `id` from ". $this->table ." where `appid` = ? limit 1",$appid);
$row = $this->db->fetch_assoc($result);
if($row){
return $row['id'];
}
return 0;
}
/**
* 创建验证规则
* @param $user_id
* @param $appid
* @param $appkey
* @return string
* @author:dc
* @time 2022/7/23 9:56
*/
public static function create_token($user_id,$appid,$appkey)
{
// 有效时间一分钟
$sign = md5("ui={$user_id}&ai={$appid}&ak={$appkey}&t=".date('ymdhi'));
return strtoupper($sign);
}
/**
* 验证token规则
* @param $user_id
* @param $appid
* @param $sign
* @return bool
* @author:dc
* @time 2022/7/23 10:00
*/
public static function check_token($user_id,$appid,$sign):bool {
if($sign){
$row = (new static())->firstByAppId($appid);
if($row){
return self::create_token($user_id,$appid,$row['appkey']) === $sign;
}
}
return false;
}
}