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
PHP

<?php
namespace Org\Kudian;
class Sign
{
const SIGN_KEY = 'sign';
public static function generate($params, $secretKey)
{
Log::write('SIGN_PARAMS: ' . json_encode($params));
unset($params[self::SIGN_KEY]);
ksort($params);
$signStr = '';
foreach ($params as $key => $value) {
$signStr .= $key . "=" . $value . "&";
}
$signStr = rtrim($signStr, '&') . "&secret_key=" . $secretKey;
Log::write('SIGN_STR: ' . $signStr);
$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;
}
}