七牛云根据AK,SK,BUCKET,生成上传凭证

使用语言PHP

$bucket='XX';

$AK='XXXXXXXXXXXXXXXXXXXXXXXXXXXX';

$SK='XXXXXXXXXXXXXXXXXXXXXXXXXXXX';

functionbase64_urlSafeEncode($data)

{

        $find= array('+','/');

         $replace= array('-','_');

          returnstr_replace($find,$replace,base64_encode($data));

}

$putPolicy=[

                'insertOnly'=>1,//已新增模式增加

                 'scope'=>$bucket,//空间名称

                 'deadline'=>time()+3600,//token有效期

];

$jsonData=json_encode($putPolicy);

$encodedPutPolicy=base64_urlSafeEncode($jsonData);

$sign=hash_hmac('sha1',$encodedPutPolicy,$SK, true);

$encodedSign=base64_urlSafeEncode($sign);

$uploadToken=$AK.':'.$encodedSign.':'.$encodedPutPolicy;

var_dump($uploadToken);

你可能感兴趣的:(七牛云根据AK,SK,BUCKET,生成上传凭证)