/**ascii码从小到大排序
* @param array $params
* @return bool|string
*/
function asc_sort($params = array())
{
if (!empty($params)) {
$p = ksort($params);
if ($p) {
$str = '';
foreach ($params as $k => $val) {
$str .= $k . '=' . $val . '&';
}
$strs = rtrim($str, '&');
return $strs;
}
}
return false;
}
$data = [
'appid' => 'sp5c1314095ed15',
'sn' => '111111111',
'timestamp' => '1544765945',
'pkey' => '22222222',
'name' => 'test'
];
$s_data = asc_sort($data);
echo $s_data;
$sign=strtoupper(md5($s_data));
echo $sign;
//输出:
//$s_data
//appid=sp5c1314095ed15&name=test&pkey=22222222&sn=111111111×tamp=1544765945
//$sign
//33653131216EEE86637C11723D772A28
网友评论