feat: add zyt medicine bootstrap
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\service\pharmacy;
|
||||
|
||||
final class EjPharmacySignature
|
||||
{
|
||||
public static function canonical(string $method, string $path, string $timestamp, string $nonce, string $body): string
|
||||
{
|
||||
return implode("\n", [
|
||||
strtoupper(trim($method)),
|
||||
$path,
|
||||
trim($timestamp),
|
||||
trim($nonce),
|
||||
hash('sha256', $body),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function sign(string $secret, string $canonical): string
|
||||
{
|
||||
return hash_hmac('sha256', $canonical, $secret);
|
||||
}
|
||||
|
||||
public static function verify(string $secret, string $canonical, string $signature): bool
|
||||
{
|
||||
return $secret !== '' && $signature !== '' && hash_equals(self::sign($secret, $canonical), strtolower(trim($signature)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user