The specific situation is:
One page I need to request three certificate picture resources from seven kn private space, in the local database I stored the names of these certificates, in the background code I based on the file name to generate these certificates can access the private link address, the front-end with the ANGULARJS framework, the background code is as follows:
$coach _cert = new Coach_cert (); $results = $coach _cert->listcerts ($this->coach_id); Seven bull space key $accessKey = '; $secretKey = "; Private space name $bucket = '; Timestamp generation $now = time (); $date = $now + 60; Download voucher generation foreach ($results as & $result) {$download _url = "http://". $bucket. ". 7xnhmh.com2.z0.glb.qiniucdn.com/". $result [' filename ']. "? e=". $date; $sign = Hash_hmac ("SHA1", $download _url, $secretKey, true); $encodedSign = Base64_encode ($sign); $token = $accessKey. ":" . $encodedSign; $realdownloadurl = $download _url. "&token=". $token; $result [' filename '] = $realdownloadurl; } return [' certs ' = ' $results];
Now the problem is: Click to view three certificates, sometimes three certificates can all be loaded out, sometimes can only load parts, can not load in the console report 401 authorization failure Error: Error: "Download token auth failed"
Reply content:
The specific situation is:
One page I need to request three certificate picture resources from seven kn private space, in the local database I stored the names of these certificates, in the background code I based on the file name to generate these certificates can access the private link address, the front-end with the ANGULARJS framework, the background code is as follows:
$coach _cert = new Coach_cert (); $results = $coach _cert->listcerts ($this->coach_id); Seven bull space key $accessKey = '; $secretKey = "; Private space name $bucket = '; Timestamp generation $now = time (); $date = $now + 60; Download voucher generation foreach ($results as & $result) {$download _url = "http://". $bucket. ". 7xnhmh.com2.z0.glb.qiniucdn.com/". $result [' filename ']. "? e=". $date; $sign = Hash_hmac ("SHA1", $download _url, $secretKey, true); $encodedSign = Base64_encode ($sign); $token = $accessKey. ":" . $encodedSign; $realdownloadurl = $download _url. "&token=". $token; $result [' filename '] = $realdownloadurl; } return [' certs ' = ' $results];
Now the problem is: Click to view three certificates, sometimes three certificates can all be loaded out, sometimes can only load parts, can not load in the console report 401 authorization failure Error: Error: "Download token auth failed"
Your signature has a problem, we are using safebase64 code, you can refer to our source code
https://github.com/qiniu/php-sdk/blob/a864511adb2e50b2b0f080440e6f11d6989905ec/src/Qiniu/functions.php
URL-Safe Base64 encoding is suitable for scenarios in which BASE64 encoding results are delivered in a URL manner. The basic procedure for this encoding is to encode the content in Base64 format as a string, then examine the result string, replace the Plus + + in the string with an underscore-and slash/change to underscore _, while the tail remains filled with equals =.
/**
Urlsafe the base64 encoding of the supplied data.
*
@param string $data the data to be encoded, typically a string
*
@return string-encoded strings
@link http://developer.qiniu.com/docs/v6/api/overview/appendix.html#urlsafe-base64
*/
Base64_urlsafeencode ($data)
{
$find = array('+', '/'); $replace = array('-', '_'); return str_replace($find, $replace, base64_encode($data));
}
/**