1 | <?php |
||
10 | class Utils |
||
11 | { |
||
12 | /** |
||
13 | * @var Filesystem |
||
14 | */ |
||
15 | protected static $filesystem; |
||
16 | |||
17 | /** |
||
18 | * Get filesystem |
||
19 | * @return Filesystem |
||
20 | */ |
||
21 | public static function getFilesystem() |
||
28 | |||
29 | /** |
||
30 | * hash |
||
31 | * @param int $uin |
||
32 | * @param string $ptWebQQ |
||
33 | * @return string |
||
34 | */ |
||
35 | public static function hash($uin, $ptWebQQ) |
||
53 | |||
54 | /** |
||
55 | * 生成ptqrtoken的哈希函数 |
||
56 | * @param string $string |
||
57 | * @return int |
||
58 | */ |
||
59 | public static function hash33($string) |
||
69 | |||
70 | /** |
||
71 | * 入转换为32位无符号整数,若溢出,则只保留低32位 |
||
72 | * @link http://outofmemory.cn/code-snippet/18291/out-switch-32-place-sign-integer-spill-maintain-32-place |
||
73 | * @param mixed $var |
||
74 | * @return float|int|string |
||
75 | */ |
||
76 | public static function toUint32val($var) |
||
77 | { |
||
78 | if (is_string($var)) { |
||
79 | if (PHP_INT_MAX > 2147483647) { |
||
80 | $var = intval($var); |
||
81 | } else { |
||
82 | $var = floatval($var); |
||
83 | } |
||
84 | } |
||
85 | if (!is_int($var)) { |
||
86 | $var = intval($var); |
||
87 | } |
||
88 | if ((0 > $var) || ($var > 4294967295)) { |
||
89 | $var &= 4294967295; |
||
90 | if (0 > $var) { |
||
91 | $var = sprintf('%u', $var); |
||
92 | } |
||
93 | } |
||
94 | return $var; |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * 计算字符的unicode,类似js中charCodeAt |
||
99 | * [Link](http://www.phpjiayuan.com/90/225.html) |
||
100 | * @param string $str |
||
101 | * @param int $index |
||
102 | * @return null|number |
||
103 | */ |
||
104 | public static function charCodeAt($str, $index) |
||
114 | |||
115 | /** |
||
116 | * 获取当前时间的毫秒数 |
||
117 | * @return float |
||
118 | */ |
||
119 | public static function getMillisecond() |
||
124 | |||
125 | /** |
||
126 | * 用于发送消息时生成msg id |
||
127 | * @return int |
||
128 | */ |
||
129 | public static function makeMsgId() |
||
142 | } |
||
143 |