-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublic_function.php
More file actions
58 lines (54 loc) · 1.24 KB
/
public_function.php
File metadata and controls
58 lines (54 loc) · 1.24 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
<?php
/**
* Created by PhpStorm.
* User: Tian
* Date: 2017/9/15
* Time: 下午8:23
*/
function str_length_check($str, $max, $min)
{
if (strlen($str) > $max || strlen($str) < $min) {
return true;
}
else {
return false;
}
}
function str_hmac($str, $key)
{
$signature = "";
if (function_exists('hash_hmac')) {
$signature = bin2hex(hash_hmac("sha1", $str, $key, true));
}
else {
$blocksize = 64;
$hashfunc = 'sha1';
if (strlen($key) > $blocksize) {
$key = pack('H*', $hashfunc($key));
}
$key = str_pad($key, $blocksize, chr(0x00));
$ipad = str_repeat(chr(0x36), $blocksize);
$opad = str_repeat(chr(0x5c), $blocksize);
$hmac = pack(
'H*', $hashfunc(
($key ^ $opad) . pack(
'H*', $hashfunc(
($key ^ $ipad) . $str
)
)
)
);
$signature = bin2hex($hmac);
}
return $signature;
}
function salt()
{
$str = md5(uniqid(md5(microtime(true)),true)); //生成一个不会重复的字符串
$str = sha1($str); //加密
return $str;
}
function current_time()
{
return '201709171204';
}