File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,19 @@ public static function httpRequest($url, $data = null)
30
30
return $ output ;
31
31
}
32
32
33
+ /**
34
+ * 是否为windows系统
35
+ * @return bool
36
+ */
37
+ public static function isWin ()
38
+ {
39
+ if (strtoupper (substr (PHP_OS ,0 ,3 )) === 'WIN ' ) {
40
+ return true ;
41
+ } else {
42
+ return false ;
43
+ }
44
+ }
45
+
33
46
/**
34
47
* 获取字符串
35
48
* @param int $type
@@ -58,6 +71,50 @@ public static function getNonce($type = 1, $length = 16)
58
71
return $ nonce ;
59
72
}
60
73
74
+ /**
75
+ * 根据URandom获取字符串
76
+ * @param int $length
77
+ * @return bool|string
78
+ */
79
+ public static function getNonceByURandom ($ length = 16 )
80
+ {
81
+ $ nonce = '' ;
82
+ $ binary = '' ;
83
+ $ fp = @fopen ('/dev/urandom ' , 'rb ' );
84
+ if ($ fp !== false ) {
85
+ $ binary .= @fread ($ fp , $ length );
86
+ @fclose ($ fp );
87
+ } else {
88
+ trigger_error ('Can not open /dev/urandom. ' );
89
+ }
90
+ $ string = base64_encode ($ binary );
91
+ $ nonce = substr ($ string , 0 , $ length );
92
+ return $ nonce ;
93
+ }
94
+
95
+ /**
96
+ * 扩展原数组的数据(仅更新原数组已有的键)
97
+ * @param $rawData
98
+ * @param $newData
99
+ * @return array
100
+ */
101
+ public static function extendArrayData ($ rawData , $ newData )
102
+ {
103
+ if (!is_array ($ rawData ) || count ($ rawData ) <= 0 ) {
104
+ return array ();
105
+ }
106
+
107
+ if (!is_array ($ newData )) {
108
+ return $ rawData ;
109
+ }
110
+
111
+ foreach ($ rawData as $ key =>$ value ) {
112
+ isset ($ newData [$ key ]) && $ rawData [$ key ] = $ newData [$ key ];
113
+ }
114
+
115
+ return $ rawData ;
116
+ }
117
+
61
118
/**
62
119
* 根据错误码获取错误信息
63
120
* @param $errorCode
You can’t perform that action at this time.
0 commit comments