@@ -8,11 +8,19 @@ final class Auth
88{
99 private $ accessKey ;
1010 private $ secretKey ;
11+ public $ options ;
1112
12- public function __construct ($ accessKey , $ secretKey )
13+ public function __construct ($ accessKey , $ secretKey, $ options = null )
1314 {
1415 $ this ->accessKey = $ accessKey ;
1516 $ this ->secretKey = $ secretKey ;
17+ $ defaultOptions = array (
18+ 'disableQiniuTimestampSignature ' => null
19+ );
20+ if ($ options == null ) {
21+ $ options = $ defaultOptions ;
22+ }
23+ $ this ->options = array_merge ($ defaultOptions , $ options );
1624 }
1725
1826 public function getAccessKey ()
@@ -216,14 +224,29 @@ public function authorization($url, $body = null, $contentType = null)
216224
217225 public function authorizationV2 ($ url , $ method , $ body = null , $ contentType = null )
218226 {
219- $ headers = null ;
227+ $ headers = new Header () ;
220228 $ result = array ();
221229 if ($ contentType != null ) {
222- $ headers = new Header (array (
223- 'Content-Type ' => array ($ contentType ),
224- ));
230+ $ headers ['Content-Type ' ] = $ contentType ;
225231 $ result ['Content-Type ' ] = $ contentType ;
226232 }
233+
234+ $ signDate = gmdate ('Ymd\THis\Z ' , time ());
235+ if ($ this ->options ['disableQiniuTimestampSignature ' ] !== null ) {
236+ if (!$ this ->options ['disableQiniuTimestampSignature ' ]) {
237+ $ headers ['X-Qiniu-Date ' ] = $ signDate ;
238+ $ result ['X-Qiniu-Date ' ] = $ signDate ;
239+ }
240+ } elseif (getenv ("DISABLE_QINIU_TIMESTAMP_SIGNATURE " )) {
241+ if (strtolower (getenv ("DISABLE_QINIU_TIMESTAMP_SIGNATURE " )) !== "true " ) {
242+ $ headers ['X-Qiniu-Date ' ] = $ signDate ;
243+ $ result ['X-Qiniu-Date ' ] = $ signDate ;
244+ }
245+ } else {
246+ $ headers ['X-Qiniu-Date ' ] = $ signDate ;
247+ $ result ['X-Qiniu-Date ' ] = $ signDate ;
248+ }
249+
227250 list ($ sign ) = $ this ->signQiniuAuthorization ($ url , $ method , $ body , $ headers );
228251 $ result ['Authorization ' ] = 'Qiniu ' . $ sign ;
229252 return $ result ;
0 commit comments