Skip to content

Commit b745cea

Browse files
1. Common.php新增getNonce函数
1 parent 887ffe6 commit b745cea

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/Common.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,33 @@ public static function httpRequest($url, $data = null)
3131
curl_close($curl);
3232
return $output;
3333
}
34+
35+
/**
36+
* 获取字符串
37+
* @param int $type
38+
* @param int $length
39+
* @return string
40+
*/
41+
public static function getNonce($type = 1, $length = 16)
42+
{
43+
$nonce = '';
44+
switch ($type) {
45+
case 1:
46+
$string = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
47+
break;
48+
case 2:
49+
$string = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
50+
break;
51+
case 3:
52+
$string = '0123456789';
53+
break;
54+
default:
55+
$string = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
56+
}
57+
for ($i = 0; $i < $length; $i++) {
58+
$nonce .= substr($string, mt_rand(0, strlen($string) - 1), 1);
59+
}
60+
return $nonce;
61+
}
3462
}
3563

0 commit comments

Comments
 (0)