Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #60 from panxl6/v2024-01
Browse files Browse the repository at this point in the history
feat: support 2024-01 version.
  • Loading branch information
panxl6 authored Jan 30, 2024
2 parents 8f76a01 + ec318d8 commit 0f673fd
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Request implements Requestable
/**
* @var string
*/
const API_VERSION = 'v4';
const API_VERSION = 'tracking/2024-01';
/**
* @var string
*/
Expand Down Expand Up @@ -201,31 +201,31 @@ private function handleHttpStatusError($response, $curl, $code)
function getCanonicalizedHeaders($headers)
{
$filtered_headers = [];

foreach ($headers as $key => $value) {
// Check if the header key starts with "as-"
if (strpos($key, 'as-') === 0) {
// Convert header key to lowercase and trim leading/trailing spaces
$key = strtolower(trim($key));

// Trim leading/trailing spaces from header value
$value = trim($value);

// Concatenate header key and value
$filtered_headers[] = "{$key}:{$value}";
}
}

// Sort headers in ASCII code order
sort($filtered_headers, SORT_STRING);

// Concatenate header pairs with new line character
$header_string = implode("\n", $filtered_headers);

return $header_string;
}

function getCanonicalizedResource($url)
function getCanonicalizedResource($url)
{
$path = "";
$query = "";
Expand All @@ -244,19 +244,19 @@ function getCanonicalizedResource($url)
sort($params);
$queryStr = implode("&", $params);
$path .= "?" . $queryStr;

return $path;
}

function getSignString($method, $url, $data, $headers)
function getSignString($method, $url, $data, $headers)
{
$contentMD5 = "";
$contentType = "";
if (!empty($data) && $method != "GET") {
$contentMD5 = strtoupper(md5($this->safeJsonEncode($data)));
$contentType = "application/json";
}

$canonicalizedHeaders = $this->getCanonicalizedHeaders($headers);
$canonicalizedResource = $this->getCanonicalizedResource($url);
return mb_convert_encoding($method."\n".$contentMD5."\n".$contentType."\n".$headers['date']."\n".$canonicalizedHeaders."\n".$canonicalizedResource, 'UTF-8');
Expand All @@ -270,7 +270,7 @@ private function getHeaders($method, $url, $data)
// if not RSA or AES encryption, just return the legacy headers
if (!$isRSAEncryptionMethod && !$isAESEncryptionMethod) {
return [
'aftership-api-key' => $this->apiKey,
'as-api-key' => $this->apiKey,
'content-type' => 'application/json'
];
}
Expand All @@ -292,11 +292,11 @@ private function getHeaders($method, $url, $data)
'content-type' => $contentType,
];
$signString = $this->getSignString($method, $url, $data, $headers);

if ($isRSAEncryptionMethod) {
$rsa = $encryption->rsaPSSSha256Encrypt($signString);
$headers['as-signature-rsa-sha256'] = $rsa;

return $headers;
}
if ($isAESEncryptionMethod) {
Expand Down

0 comments on commit 0f673fd

Please sign in to comment.