Commit b80f928efd6b3ab47dea2c5d8b172d9b1994d2d2
1 parent
51a896c1
Exists in
master
app-ht
1. F Mac地址匹配校验规则调整 common 1. F Mac地址匹配校验规则调整
Showing
2 changed files
with
23 additions
and
60 deletions
Show diff stats
app-ht/modules/device/controllers/DeviceController.php
... | ... | @@ -232,7 +232,7 @@ class DeviceController extends BaseController |
232 | 232 | |
233 | 233 | $importMacs = $this->getMacAddress($uploadPath); |
234 | 234 | if (empty($importMacs)) { |
235 | - $e->message = '上传文件不合格'; | |
235 | + $e->message = '上传文件中MAC地址格式不合格'; | |
236 | 236 | return $this->renderJson($e); |
237 | 237 | } |
238 | 238 | $num = count($importMacs); |
... | ... | @@ -1106,7 +1106,7 @@ class DeviceController extends BaseController |
1106 | 1106 | |
1107 | 1107 | $importMacs = $this->getMacAddress($uploadPath); |
1108 | 1108 | if (empty($importMacs)) { |
1109 | - $e->message = '上传文件不合格'; | |
1109 | + $e->message = '上传文件中MAC地址格式不合格'; | |
1110 | 1110 | return $this->renderJson($e); |
1111 | 1111 | } |
1112 | 1112 | $appendNum = count($importMacs); |
... | ... | @@ -1252,15 +1252,16 @@ class DeviceController extends BaseController |
1252 | 1252 | fclose($fileHandle); |
1253 | 1253 | $returnMac = []; |
1254 | 1254 | foreach ($macList as $k => $v) { |
1255 | - $v = trim($v); | |
1256 | - if (preg_match('/^[0-9a-fA-F:]{12,18}$/', $v)) { | |
1257 | - if (false !== strpos($v, ":")) { | |
1258 | - $returnMac[] = strtoupper($v); | |
1259 | - } else { | |
1260 | - $returnMac[] = strtoupper(Utils::coverToMacAddress($v)); | |
1261 | - } | |
1255 | + $v = trim($v); | |
1256 | + if (Utils::isMacAddress($v)) { | |
1257 | + $v = str_replace('-', '',$v); | |
1258 | + $v = str_replace(':','', $v); | |
1259 | + $returnMac[] = strtoupper(Utils::coverToMacAddress($v)); | |
1262 | 1260 | } |
1263 | 1261 | } |
1262 | + if ($returnMac) { | |
1263 | + $returnMac = array_unique($returnMac); | |
1264 | + } | |
1264 | 1265 | |
1265 | 1266 | return $returnMac; |
1266 | 1267 | } | ... | ... |
common/helpers/Utils.php
... | ... | @@ -169,7 +169,6 @@ class Utils |
169 | 169 | return round($number ,2); |
170 | 170 | } |
171 | 171 | |
172 | - | |
173 | 172 | /** 经纬度检测是否合格 |
174 | 173 | * @param $latitude |
175 | 174 | * @param $longitude |
... | ... | @@ -314,19 +313,6 @@ class Utils |
314 | 313 | $str); |
315 | 314 | } |
316 | 315 | |
317 | - /** 简单税号检测,税号前面6位是行政区号,后面的9位是组织号。税号有15位,18位,20位三种长度 | |
318 | - * @param $txtId | |
319 | - * @return bool | |
320 | - */ | |
321 | - public static function isCompanyTaxId($txtId) | |
322 | - { | |
323 | - if (preg_match("/^[0-9]{6}([0-9A-Z]{9}|[0-9A-Z]{12}|[0-9A-Z]{14})$/", $txtId)) { | |
324 | - return true; | |
325 | - } else { | |
326 | - return false; | |
327 | - } | |
328 | - } | |
329 | - | |
330 | 316 | /** 邮箱验证 |
331 | 317 | * @param $email |
332 | 318 | * @return bool |
... | ... | @@ -378,43 +364,6 @@ class Utils |
378 | 364 | } |
379 | 365 | } |
380 | 366 | |
381 | - /** 分成中英数字,其他的特殊字符都算中文,不能出现-,空格,换行 | |
382 | - * @param $str | |
383 | - * @return array | |
384 | - */ | |
385 | - public static function splitWord($str) | |
386 | - { | |
387 | - $str = trim($str); | |
388 | - $str = str_replace("\r",'',$str); | |
389 | - $str = str_replace("\n",'',$str); | |
390 | - $str = str_replace('-','',$str); | |
391 | - $str = str_replace('\'','',$str); | |
392 | - | |
393 | - $arr = preg_split("/([0-9]+)/", $str, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); | |
394 | - $resultArr = []; | |
395 | - foreach($arr as $k=>$v) { | |
396 | - $dArray = preg_split("/([a-zA-Z]+)/", $v, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); | |
397 | - foreach($dArray as $kk=>$vv){ | |
398 | - $resultArr[] = $vv; | |
399 | - } | |
400 | - } | |
401 | - return $resultArr; | |
402 | - } | |
403 | - | |
404 | - public static function hidePhoneNumber($phone, $hideLen = 6) | |
405 | - { | |
406 | - if (empty($phone)) { | |
407 | - return ''; | |
408 | - } | |
409 | - $startStr = substr($phone, 0, 2); | |
410 | - $endStr = substr($phone, -3); | |
411 | - $hideStr = ''; | |
412 | - for ($i = 0; $i< $hideLen; $i++) { | |
413 | - $hideStr = $hideStr .'*'; | |
414 | - } | |
415 | - return $startStr.$hideStr.$endStr; | |
416 | - } | |
417 | - | |
418 | 367 | /** java 带T和带Z的时间格式换成PHP |
419 | 368 | * @param $str |
420 | 369 | * @return bool|null|string |
... | ... | @@ -544,4 +493,17 @@ class Utils |
544 | 493 | |
545 | 494 | return $returnStr; |
546 | 495 | } |
496 | + | |
497 | + /** | |
498 | + * @param $mac | |
499 | + * @return bool | |
500 | + */ | |
501 | + static function isMacAddress($mac) | |
502 | + { | |
503 | + if(preg_match('/^([0-9a-fA-F]{2})(([:|-]{0,1}[0-9a-fA-F]{2}){5})$/', $mac)) { | |
504 | + return true; | |
505 | + } else { | |
506 | + return false; | |
507 | + } | |
508 | + } | |
547 | 509 | } |
548 | 510 | \ No newline at end of file | ... | ... |