php

PHP ASCII 排序方法

2020-04-08  本文已影响0人  bianruifeng
/**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&timestamp=1544765945
//$sign
//33653131216EEE86637C11723D772A28
上一篇下一篇

猜你喜欢

热点阅读