You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
778 B
PHTML

2 years ago
<?php
namespace Org\Kudian;
class Sign
{
const SIGN_KEY = 'sign';
public static function generate($params, $secretKey)
{
2 years ago
Log::write('SIGN_PARAMS: ' . json_encode($params));
2 years ago
unset($params[self::SIGN_KEY]);
ksort($params);
$signStr = '';
foreach ($params as $key => $value) {
$signStr .= $key . "=" . $value . "&";
}
$signStr = rtrim($signStr, '&') . "&secret_key=" . $secretKey;
2 years ago
Log::write('SIGN_STR: ' . $signStr);
2 years ago
$sign = md5($signStr);
$sign = strtoupper($sign);
return $sign;
}
public static function verify($params, $secretKey)
{
$sign = $params[self::SIGN_KEY] ?: null;
return self::generate($params, $secretKey) == $sign;
}
}