PHP正则按照从大到小的SIGN签名算法
阅读原文时间:2023年08月19日阅读:3
'1.00','out\_trade\_no'=>'2018123645787452'); \* @return string \* @ [https://www.bang4.cn](https://www.bang4.cn) 作者 \*/ function sign ($key\_id, $array) { $data = md5(sprintf("%.2f", $array\['amount'\]) . $array\['out\_trade\_no'\]); $key\[\] =""; $box\[\] =""; $pwd\_length = strlen($key\_id); $data\_length = strlen($data); for ($i = 0; $i < 256; $i++) { $key\[$i\] = ord($key\_id\[$i % $pwd\_length\]); $box\[$i\] = $i; } for ($j = $i = 0; $i < 256; $i++) { $j = ($j + $box\[$i\] + $key\[$i\]) % 256; $tmp = $box\[$i\]; $box\[$i\] = $box\[$j\]; $box\[$j\] = $tmp; } for ($a = $j = $i = 0; $i < $data\_length; $i++) { $a = ($a + 1) % 256; $j = ($j + $box\[$a\]) % 256; $tmp = $box\[$a\]; $box\[$a\] = $box\[$j\]; $box\[$j\] = $tmp; $k = $box\[(($box\[$a\] + $box\[$j\]) % 256)\]; $cipher .= chr(ord($data\[$i\]) ^ $k); } return md5($cipher); } ?>