输出openssl_random_pseudo_bytes
php函数不可读字符。
我使用这个函数来生成一个唯一的字符串。
<?php
header('content-type:text/plain ; charset=utf-8');
$uniqid=openssl_random_pseudo_bytes(30 );
echo $uniqid ;
?>
输出这样的东西:
#~�p�x�6�;g�ic�-z"���:i�
我必须使用bin2hex()函数。
<?php
$uniqid=bin2hex(openssl_random_pseudo_bytes(30 ));
echo $uniqid ;
?>
而且这个函数肯定不会产生uniqid。
private function generateSaltSecretKey($num): string
{
return bin2hex(openssl_random_pseudo_bytes($num));
}
PHP 中有类似uniqid的函数
你可以试试这个:
<?php
printf("uniqid(): %s'r'n", uniqid());echo '<br>';
printf("uniqid('php_'): %s'r'n", uniqid('php_'));echo '<br>';
printf("uniqid('', true): %s'r'n", uniqid('', true));echo '<br>';
?>
参考:http://php.net/manual/en/function.uniqid.php