open-pay-demo/php/sign.php
echo 653a5e4a23 init: multi-language OpenAPI demos (java/php/nodejs/python)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-20 13:40:28 +08:00

20 lines
499 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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);
}