public function sign()

in src/OSS/Signer/SignerV1.php [11:35]


    public function sign(RequestCore $request, Credentials $credentials, array &$options)
    {
        // Date
        if (!isset($request->request_headers['Date'])) {
            $request->add_header('Date', gmdate('D, d M Y H:i:s \G\M\T'));
        }
        // Credentials information
        if (!empty($credentials->getSecurityToken())) {
            $request->add_header("x-oss-security-token", $credentials->getSecurityToken());
        }
        $headers = $request->request_headers;
        $method = strtoupper($request->method);
        $date = $headers['Date'];
        $resourcePath = $this->getResourcePath($options);
        $queryString = parse_url($request->request_url, PHP_URL_QUERY);
        $query = array();
        if ($queryString !== null) {
            parse_str($queryString, $query);
        }
        $stringToSign = $this->calcStringToSign($method, $date, $headers, $resourcePath, $query);
//        printf("sign str:%s" . PHP_EOL, $stringToSign);
        $options['string_to_sign'] = $stringToSign;
        $signature = base64_encode(hash_hmac('sha1', $stringToSign, $credentials->getAccessKeySecret(), true));
        $request->add_header('Authorization', 'OSS ' . $credentials->getAccessKeyId() . ':' . $signature);
    }