add clear

This commit is contained in:
2021-04-06 16:33:49 +08:00
parent 10f3d5b99f
commit f5b14a4565
+8 -10
View File
@@ -162,20 +162,18 @@ class Help extends Miniprogarampage
*/ */
public static function sign(array $array, $key, $type) public static function sign(array $array, $key, $type)
{ {
ksort($array, SORT_ASC); ksort($array);
$string = []; $buff = "";
foreach ($array as $hashKey => $val) { foreach ($array as $k => $v) {
if (empty($val)) { if ($k != "sign" && $v != "" && !is_array($v)) {
continue; $buff .= $k . "=" . $v . "&";
} }
$string[] = $hashKey . '=' . $val;
} }
$string[] = 'key=' . $key; $string = trim($buff, "&") . '&key=' . $key;
$string = implode('&', $string); if (strtoupper($type) == 'MD5') {
if ($type == 'MD5') {
return strtoupper(md5($string)); return strtoupper(md5($string));
} else { } else {
return hash('sha256', $string); return hash_hmac('sha256', $string, $key);
} }
} }