diff --git a/ufile-auth-server-php/Auth_Config.php b/ufile-auth-server-php/Auth_Config.php new file mode 100644 index 0000000..a5347df --- /dev/null +++ b/ufile-auth-server-php/Auth_Config.php @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/ufile-auth-server-php/FileAddressSign.php b/ufile-auth-server-php/FileAddressSign.php new file mode 100644 index 0000000..987c656 --- /dev/null +++ b/ufile-auth-server-php/FileAddressSign.php @@ -0,0 +1,23 @@ +method; + $bucket=$param_obj->bucket; + $key=$param_obj->key; + $expires=$param_obj->expires; + + $auth=new UCloud_Auth($UCLOUD_PUBLIC_KEY, $UCLOUD_PRIVATE_KEY); + echo $auth->signFileAddressRequest($method, $bucket, $key, $expires); +} + +?> \ No newline at end of file diff --git a/ufile-auth-server-php/FileOperateSign.php b/ufile-auth-server-php/FileOperateSign.php new file mode 100644 index 0000000..3e56f7f --- /dev/null +++ b/ufile-auth-server-php/FileOperateSign.php @@ -0,0 +1,27 @@ +method; + $bucket=$param_obj->bucket; + $key=$param_obj->key; + $content_md5=$param_obj->content_md5; + $content_type=$param_obj->content_type; + $date=$param_obj->date; + $put_policy=$param_obj->put_policy; + + $auth=new UCloud_Auth($UCLOUD_PUBLIC_KEY, $UCLOUD_PRIVATE_KEY); + echo $auth->signFileOperateRequest($method, $bucket, $key, $content_md5, $content_type, $date, $put_policy); +} + +?> \ No newline at end of file diff --git a/ufile-auth-server-php/UCloud_Auth.php b/ufile-auth-server-php/UCloud_Auth.php new file mode 100644 index 0000000..0ff8c28 --- /dev/null +++ b/ufile-auth-server-php/UCloud_Auth.php @@ -0,0 +1,86 @@ +publicToken = $publicToken; + $this->privateToken = $privateToken; + } + + public function signFileOpeate($data,$put_policy) + { + $sign = base64_encode(hash_hmac('sha1', $data, $this->privateToken, true)); + $singStr = "UCloud " . $this->publicToken . ":" . $sign; + + // 上传回调put_policy + if ($put_policy) { + $policystr = base64_encode(str_replace('"','\\"',json_encode($put_policy))); + $singStr = $singStr . ":" . $policystr; + } + + return $singStr; + } + + /* 文件操作签名 */ + public function signFileOperateRequest($method, $bucket, $key, $content_md5, $content_type, $date, $put_policy) + { + $data = ''; + $data .= strtoupper($method) . "\n"; + $data .= $content_md5 . "\n"; + $data .= $content_type . "\n"; + $data .= $date . "\n"; + $data .= CanonicalizedResource($bucket, $key); + error_log($data, 3, "/tmp/php.log"); + return $this->signFileOpeate($data, $put_policy); + } + + /* 获取私有‘bucket’下文件的 URL 签名 */ + public function signFileAddressRequest($method,$bucket,$key,$expires) + { + $data = ''; + $data .= strtoupper($method) . "\n"; + $data .= "\n"; + $data .= "\n"; + $data .= $expires . "\n"; + $data .= CanonicalizedResource($bucket, $key); + + $sign = base64_encode(hash_hmac('sha1', $data, $this->privateToken, true)); + return $sign; + } + +} + +?> \ No newline at end of file