diff --git a/wchat/common/Help.php b/wchat/common/Help.php index 4528ead..2d8799a 100644 --- a/wchat/common/Help.php +++ b/wchat/common/Help.php @@ -162,20 +162,18 @@ class Help extends Miniprogarampage */ public static function sign(array $array, $key, $type) { - ksort($array, SORT_ASC); - $string = []; - foreach ($array as $hashKey => $val) { - if (empty($val)) { - continue; + ksort($array); + $buff = ""; + foreach ($array as $k => $v) { + if ($k != "sign" && $v != "" && !is_array($v)) { + $buff .= $k . "=" . $v . "&"; } - $string[] = $hashKey . '=' . $val; } - $string[] = 'key=' . $key; - $string = implode('&', $string); - if ($type == 'MD5') { + $string = trim($buff, "&") . '&key=' . $key; + if (strtoupper($type) == 'MD5') { return strtoupper(md5($string)); } else { - return hash('sha256', $string); + return hash_hmac('sha256', $string, $key); } }