I want to use qiniu to implement the offline download function. Then, extract some Encryption Algorithm functions. This is run by a shell script. The badtoken prompt is displayed. I don't know where the following script is wrong? Thank you ~ {Code...} download. php, get encodeURI, encodedEntr... want to use qiniu to implement the offline download function. Then, extract some Encryption Algorithm functions.
This is run by a shell script and prompts "bad token". I don't know where the following script is wrong?
Thank you ~
php download.php https://p.ssl.qhimg.com/t01d1f1a2ae31e3c3e4.png 111.png
Download. php, get encodeURI, encodedEntryURI, and accessToken;
?
\ N "$ signingStr =" {$ path }? {$ Query} \ n"; $ Sign = hmac_sha1 ($ signingStr, SecretKey); $ encodedSign = encrypt ($ sign); // $ encodeAccessKey = urlsafe_base64_encode (AccessKey ); // $ accessToken = "{$ encodeAccessKey }:{$ encodedSign}"; $ accessToken = AccessKey. ": {$ encodedSign}"; echo "AccessToken: \ r \ n {$ accessToken} \ r \ n ";
$ Data ['extension'] = BUCKET; $ data ['demoline'] = time () + 3600; // expiration time $ encoded = urlsafe_base64_encode (json_encode ($ data )); // $ signature = hash_hmac ('sha1', $ encoded, 'key', true); $ signature = hmac_sha1 ($ encoded, SecretKey ); $ encode_signed = urlsafe_base64_encode ($ signature); // $ UploadToken = $ encode_signed. ':'. $ encoded; $ UploadToken = AccessKey. ":". $ encode_signed. ":". $ encoded; echo "AccessToken: \ r \ n {$ UploadToken} \ r \ n"; echo "UploadURL: \ r \ nhttp: // iovip. qbox. me/fetch/{$ encodeURI}/to/{$ encodedEntryURI} \ r \ n ";
Script
sh download.sh encodeURI encodedEntryURI accessToken
Transfer Data, result... Tip:
{"error":"bad token"}
Download. sh
curl -i \ -o - \ -H 'Content-Type: application/x-www-form-urlencoded' \ -H "Authorization: QBox $3" \ -X POST \ "http://iovip.qbox.me/fetch/$1/to/$2"
The PHP part has been processed by myself (there are two errors ):
PS: I found that the last question I asked was handled by myself. I don't know if Daniel does not care about these low-tech problems, or ???
It is really incomparable with sg...
"; Var_dump ($ signingStr); $ sign = hmac_sha1 ($ signingStr, SecretKey); $ encodedSign = sign ($ sign); var_dump ($ sign); $ accessToken = AccessKey. ": {$ encodedSign}"; echo "AccessToken: \ r \ n {$ accessToken} \ r \ n"; echo "UploadURL: \ r \ nhttp: // iovip. qbox. me/fetch/{$ encodeURI}/to/{$ encodedEntryURI} \ r \ n ";
Reply content:
I want to use qiniu to implement the offline download function. Then, extract some Encryption Algorithm functions.
This is run by a shell script and prompts "bad token". I don't know where the following script is wrong?
Thank you ~
php download.php https://p.ssl.qhimg.com/t01d1f1a2ae31e3c3e4.png 111.png
Download. php, get encodeURI, encodedEntryURI, and accessToken;
?
\ N "$ signingStr =" {$ path }? {$ Query} \ n"; $ Sign = hmac_sha1 ($ signingStr, SecretKey); $ encodedSign = encrypt ($ sign); // $ encodeAccessKey = urlsafe_base64_encode (AccessKey ); // $ accessToken = "{$ encodeAccessKey }:{$ encodedSign}"; $ accessToken = AccessKey. ": {$ encodedSign}"; echo "AccessToken: \ r \ n {$ accessToken} \ r \ n ";
$ Data ['extension'] = BUCKET; $ data ['demoline'] = time () + 3600; // expiration time $ encoded = urlsafe_base64_encode (json_encode ($ data )); // $ signature = hash_hmac ('sha1', $ encoded, 'key', true); $ signature = hmac_sha1 ($ encoded, SecretKey ); $ encode_signed = urlsafe_base64_encode ($ signature); // $ UploadToken = $ encode_signed. ':'. $ encoded; $ UploadToken = AccessKey. ":". $ encode_signed. ":". $ encoded; echo "AccessToken: \ r \ n {$ UploadToken} \ r \ n"; echo "UploadURL: \ r \ nhttp: // iovip. qbox. me/fetch/{$ encodeURI}/to/{$ encodedEntryURI} \ r \ n ";
Script
sh download.sh encodeURI encodedEntryURI accessToken
Transfer Data, result... Tip:
{"error":"bad token"}
Download. sh
curl -i \ -o - \ -H 'Content-Type: application/x-www-form-urlencoded' \ -H "Authorization: QBox $3" \ -X POST \ "http://iovip.qbox.me/fetch/$1/to/$2"
The PHP part has been processed by myself (there are two errors ):
PS: I found that the last question I asked was handled by myself. I don't know if Daniel does not care about these low-tech problems, or ???
It is really incomparable with sg...
"; Var_dump ($ signingStr); $ sign = hmac_sha1 ($ signingStr, SecretKey); $ encodedSign = sign ($ sign); var_dump ($ sign); $ accessToken = AccessKey. ": {$ encodedSign}"; echo "AccessToken: \ r \ n {$ accessToken} \ r \ n"; echo "UploadURL: \ r \ nhttp: // iovip. qbox. me/fetch/{$ encodeURI}/to/{$ encodedEntryURI} \ r \ n ";
Previously written:AK,KEYAndscopeReplace with your
$ Data ['scope '] = 'your bucket'; $ data ['demoline'] = time () + 3600; // expiration time $ encoded = urlsafe_base64_encode (json_encode ($ data); $ signature = hash_hmac ('sha1', $ encoded, 'key', true ); $ encode_signed = urlsafe_base64_encode ($ signature); $ UploadToken = 'ak :'. $ encode_signed. ':'. $ encoded; echo $ UploadToken; function urlsafe_base64_encode ($ data) {$ data = base64_encode ($ data); $ data = str_replace (array ('+ ','/'), array ('-', '_'), $ data); return $ data ;}
Why not use the SDK?
Direct
$token = $auth->uploadToken($bucket);