@@ -77,7 +77,8 @@ public function uploadToken(
7777 $ expires = 3600 ,
7878 $ policy = null ,
7979 $ strictPolicy = true
80- ) {
80+ )
81+ {
8182 $ deadline = time () + $ expires ;
8283 $ scope = $ bucket ;
8384 if ($ key !== null ) {
@@ -142,4 +143,51 @@ public function authorization($url, $body = null, $contentType = null)
142143 $ authorization = 'QBox ' . $ this ->signRequest ($ url , $ body , $ contentType );
143144 return array ('Authorization ' => $ authorization );
144145 }
146+
147+ public function authorizationV2 ($ url , $ method , $ body = null , $ contentType = null )
148+ {
149+ $ urlItems = parse_url ($ url );
150+ $ host = $ urlItems ['host ' ];
151+
152+ if (isset ($ urlItems ['port ' ])) {
153+ $ port = $ urlItems ['port ' ];
154+ } else {
155+ $ port = '' ;
156+ }
157+
158+ $ path = $ urlItems ['path ' ];
159+ if (isset ($ urlItems ['query ' ])) {
160+ $ query = $ urlItems ['query ' ];
161+ } else {
162+ $ query = '' ;
163+ }
164+
165+ //write request uri
166+ $ toSignStr = $ method . ' ' . $ path ;
167+ if (!empty ($ query )) {
168+ $ toSignStr .= '? ' . $ query ;
169+ }
170+
171+ //write host and port
172+ $ toSignStr .= "\nHost: " . $ host ;
173+ if (!empty ($ port )) {
174+ $ toSignStr .= ": " . $ port ;
175+ }
176+
177+ //write content type
178+ if (!empty ($ contentType )) {
179+ $ toSignStr .= "\nContent-Type: " . $ contentType ;
180+ }
181+
182+ $ toSignStr .= "\n\n" ;
183+
184+ //write body
185+ if (!empty ($ body )) {
186+ $ toSignStr .= $ body ;
187+ }
188+
189+ $ sign = $ this ->sign ($ toSignStr );
190+ $ auth = 'Qiniu ' . $ sign ;
191+ return array ('Authorization ' => $ auth );
192+ }
145193}
0 commit comments