20 lines
499 B
PHP
20 lines
499 B
PHP
<?php
|
||
/** 空值不参与,字典序,MD5 小写 */
|
||
function build_sign(array $params, string $secretKey): string {
|
||
unset($params['Sign']);
|
||
ksort($params, SORT_STRING);
|
||
$parts = [];
|
||
foreach ($params as $k => $v) {
|
||
if ($v === null) {
|
||
continue;
|
||
}
|
||
$s = (string)$v;
|
||
if ($s === '') {
|
||
continue;
|
||
}
|
||
$parts[] = $k . '=' . $s;
|
||
}
|
||
$raw = implode('&', $parts) . '&SecretKey=' . $secretKey;
|
||
return md5($raw);
|
||
}
|