From b80f928efd6b3ab47dea2c5d8b172d9b1994d2d2 Mon Sep 17 00:00:00 2001 From: xu Date: Wed, 13 Nov 2019 16:34:10 +0800 Subject: [PATCH] app-ht 1. F Mac地址匹配校验规则调整 common 1. F Mac地址匹配校验规则调整 --- app-ht/modules/device/controllers/DeviceController.php | 19 ++++++++++--------- common/helpers/Utils.php | 64 +++++++++++++--------------------------------------------------- 2 files changed, 23 insertions(+), 60 deletions(-) diff --git a/app-ht/modules/device/controllers/DeviceController.php b/app-ht/modules/device/controllers/DeviceController.php index 6e43b80..4757ed4 100644 --- a/app-ht/modules/device/controllers/DeviceController.php +++ b/app-ht/modules/device/controllers/DeviceController.php @@ -232,7 +232,7 @@ class DeviceController extends BaseController $importMacs = $this->getMacAddress($uploadPath); if (empty($importMacs)) { - $e->message = '上传文件不合格'; + $e->message = '上传文件中MAC地址格式不合格'; return $this->renderJson($e); } $num = count($importMacs); @@ -1106,7 +1106,7 @@ class DeviceController extends BaseController $importMacs = $this->getMacAddress($uploadPath); if (empty($importMacs)) { - $e->message = '上传文件不合格'; + $e->message = '上传文件中MAC地址格式不合格'; return $this->renderJson($e); } $appendNum = count($importMacs); @@ -1252,15 +1252,16 @@ class DeviceController extends BaseController fclose($fileHandle); $returnMac = []; foreach ($macList as $k => $v) { - $v = trim($v); - if (preg_match('/^[0-9a-fA-F:]{12,18}$/', $v)) { - if (false !== strpos($v, ":")) { - $returnMac[] = strtoupper($v); - } else { - $returnMac[] = strtoupper(Utils::coverToMacAddress($v)); - } + $v = trim($v); + if (Utils::isMacAddress($v)) { + $v = str_replace('-', '',$v); + $v = str_replace(':','', $v); + $returnMac[] = strtoupper(Utils::coverToMacAddress($v)); } } + if ($returnMac) { + $returnMac = array_unique($returnMac); + } return $returnMac; } diff --git a/common/helpers/Utils.php b/common/helpers/Utils.php index 1897c1a..0487e50 100644 --- a/common/helpers/Utils.php +++ b/common/helpers/Utils.php @@ -169,7 +169,6 @@ class Utils return round($number ,2); } - /** 经纬度检测是否合格 * @param $latitude * @param $longitude @@ -314,19 +313,6 @@ class Utils $str); } - /** 简单税号检测,税号前面6位是行政区号,后面的9位是组织号。税号有15位,18位,20位三种长度 - * @param $txtId - * @return bool - */ - public static function isCompanyTaxId($txtId) - { - if (preg_match("/^[0-9]{6}([0-9A-Z]{9}|[0-9A-Z]{12}|[0-9A-Z]{14})$/", $txtId)) { - return true; - } else { - return false; - } - } - /** 邮箱验证 * @param $email * @return bool @@ -378,43 +364,6 @@ class Utils } } - /** 分成中英数字,其他的特殊字符都算中文,不能出现-,空格,换行 - * @param $str - * @return array - */ - public static function splitWord($str) - { - $str = trim($str); - $str = str_replace("\r",'',$str); - $str = str_replace("\n",'',$str); - $str = str_replace('-','',$str); - $str = str_replace('\'','',$str); - - $arr = preg_split("/([0-9]+)/", $str, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); - $resultArr = []; - foreach($arr as $k=>$v) { - $dArray = preg_split("/([a-zA-Z]+)/", $v, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); - foreach($dArray as $kk=>$vv){ - $resultArr[] = $vv; - } - } - return $resultArr; - } - - public static function hidePhoneNumber($phone, $hideLen = 6) - { - if (empty($phone)) { - return ''; - } - $startStr = substr($phone, 0, 2); - $endStr = substr($phone, -3); - $hideStr = ''; - for ($i = 0; $i< $hideLen; $i++) { - $hideStr = $hideStr .'*'; - } - return $startStr.$hideStr.$endStr; - } - /** java 带T和带Z的时间格式换成PHP * @param $str * @return bool|null|string @@ -544,4 +493,17 @@ class Utils return $returnStr; } + + /** + * @param $mac + * @return bool + */ + static function isMacAddress($mac) + { + if(preg_match('/^([0-9a-fA-F]{2})(([:|-]{0,1}[0-9a-fA-F]{2}){5})$/', $mac)) { + return true; + } else { + return false; + } + } } \ No newline at end of file -- libgit2 0.21.0