You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.1 KiB
35 lines
1.1 KiB
|
4 months ago
|
<?php
|
||
|
|
|
||
|
|
namespace App\Support;
|
||
|
|
|
||
|
|
class ChannelEntrySignature
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* @param array{channel_code?: mixed, timestamp?: mixed, name?: mixed, mobile?: mixed, company_name?: mixed, state?: mixed} $parameters
|
||
|
|
*/
|
||
|
|
public static function make(array $parameters, string $sharedSecret): string
|
||
|
|
{
|
||
|
|
$values = [
|
||
|
|
'channel_code' => self::trimmed($parameters['channel_code'] ?? ''),
|
||
|
|
'timestamp' => self::trimmed($parameters['timestamp'] ?? ''),
|
||
|
|
'name' => self::trimmed($parameters['name'] ?? ''),
|
||
|
|
'mobile' => self::trimmed($parameters['mobile'] ?? ''),
|
||
|
|
'company_name' => self::trimmed($parameters['company_name'] ?? ''),
|
||
|
|
'state' => self::trimmed($parameters['state'] ?? ''),
|
||
|
|
'secret' => trim($sharedSecret),
|
||
|
|
];
|
||
|
|
|
||
|
|
$joined = [];
|
||
|
|
foreach ($values as $key => $value) {
|
||
|
|
$joined[] = $key.'='.$value;
|
||
|
|
}
|
||
|
|
|
||
|
|
return hash('sha256', implode('&', $joined));
|
||
|
|
}
|
||
|
|
|
||
|
|
private static function trimmed(mixed $value): string
|
||
|
|
{
|
||
|
|
return is_scalar($value) ? trim((string) $value) : '';
|
||
|
|
}
|
||
|
|
}
|