From f85cf163829eb2162cb44edff4e64defa7336e51 Mon Sep 17 00:00:00 2001 From: zhaoxiang Date: Thu, 23 Aug 2018 13:33:39 +0800 Subject: [PATCH] =?UTF-8?q?modified=20=E5=AE=8C=E5=96=84mock=E9=9A=8F?= =?UTF-8?q?=E6=9C=BA=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/controller/Miss.php | 2 +- application/util/StrRandom.php | 51 ++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/application/api/controller/Miss.php b/application/api/controller/Miss.php index 0e2c877..180bb87 100644 --- a/application/api/controller/Miss.php +++ b/application/api/controller/Miss.php @@ -9,7 +9,7 @@ class Miss extends Base { public function index() { $this->debug([ 'TpVersion' => THINK_VERSION, - 'Float' => StrRandom::randomIp() + 'Float' => StrRandom::randomDate() ]); return $this->buildSuccess([ diff --git a/application/util/StrRandom.php b/application/util/StrRandom.php index 5735ee1..519761c 100644 --- a/application/util/StrRandom.php +++ b/application/util/StrRandom.php @@ -35,6 +35,18 @@ class StrRandom { return floatval($intNum . '.' . $rand . $floatEnd); } + /** + * 获取随机的时间 + * @param string $format PHP的时间日期格式化字符 + * @return false|string + * @author zhaoxiang + */ + public static function randomDate($format = 'Y-m-d H:i:s') { + $timestamp = time() - mt_rand(0, 86400 * 3650); + + return date($format, $timestamp); + } + /** * 构建随机IP地址 * @return string @@ -85,7 +97,7 @@ class StrRandom { } /** - * + * 随机生成一个顶级域名 * @author zhaoxiang */ public static function randomTld() { @@ -104,4 +116,41 @@ class StrRandom { return $tldArr[0]; } + /** + * 获取一个随机的域名 + * @return string + * @author zhaoxiang + */ + public static function randomDomain() { + $len = mt_rand(6, 16); + + return strtolower(Strs::randString($len)) . '.' . self::randomTld(); + } + + /** + * 随机生成一个URL + * @param string $protocol 协议名称,可以不用指定 + * @return string + * @author zhaoxiang + */ + public static function randomUrl($protocol = '') { + $protocol = $protocol ? $protocol : self::randomProtocol(); + + return $protocol . '://' . self::randomDomain(); + } + + /** + * 随机生成一个邮箱地址 + * @param string $domain 可以指定邮箱域名 + * @return string + * @author zhaoxiang + */ + public static function randomEmail($domain = '') { + $len = mt_rand(6, 16); + $domain = $domain ? $domain : self::randomDomain(); + + return Strs::randString($len) . '@' . $domain; + + } + }