File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments