49 lines
1.1 KiB
PHP
49 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace app\util;
|
|
class StringUtil
|
|
{
|
|
/**
|
|
* 随机生成字符串
|
|
* @param int $length
|
|
* @return string
|
|
*/
|
|
public static function generateRandomString(int $length): string
|
|
{
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
$randomString = '';
|
|
|
|
for ($i = 0; $i < $length; $i++) {
|
|
$randomString .= $characters[rand(0, strlen($characters) - 1)];
|
|
}
|
|
|
|
return $randomString;
|
|
}
|
|
/**
|
|
* 生成订单号
|
|
* @return string
|
|
*/
|
|
public static function makeOrderNumber():string
|
|
{
|
|
return date_create()->format('ymdHisu');
|
|
}
|
|
|
|
/**
|
|
* 生成商户端协议号
|
|
* @return string
|
|
*/
|
|
public static function makeAgreementId()
|
|
{
|
|
return md5(date_create()->format('ymdHisu'));
|
|
}
|
|
|
|
/**
|
|
* 手机号加星
|
|
* @param $phone
|
|
* @return array|string|string[]|null
|
|
*/
|
|
public static function maskPhone($phone) {
|
|
return preg_replace("/(\d{3})\d{4}(\d{4})/", "$1****$2", $phone);
|
|
}
|
|
}
|