You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.5 KiB
PHP
65 lines
1.5 KiB
PHP
<?php
|
|
class VirtualNumberTool {
|
|
|
|
private static $regexStr = "/\\$(1[0-9]{10})\\$#([0-9]{4})#|\\$(95[0-9]{5})\\$#([0-9]{8})#/isU";
|
|
private static $frontRegexStr = "/(1[0-9]{10})#([0-9]{4})|(95[0-9]{5})#([0-9]{8})/isU";
|
|
|
|
/**
|
|
* 判断是否为虚拟号码
|
|
* @param $numberStr
|
|
* @return false|int
|
|
*/
|
|
public static function isVirtualNumber($numberStr) {
|
|
return preg_match(self::$regexStr, $numberStr);
|
|
}
|
|
|
|
/**
|
|
* 获取虚拟号码
|
|
* @param $numberStr
|
|
* @return mixed
|
|
*/
|
|
public static function getVirtualNumber($numberStr) {
|
|
preg_match(self::$regexStr, $numberStr, $matches);
|
|
return $matches[1];
|
|
}
|
|
|
|
/**
|
|
* 获取分机号
|
|
* @param $numberStr
|
|
* @return string|null
|
|
*/
|
|
public static function getExtNumber($numberStr) {
|
|
preg_match(self::$regexStr, $numberStr, $matches);
|
|
return $matches[2];
|
|
}
|
|
|
|
/**
|
|
* 判断是否为前端虚拟号码
|
|
* @param $numberStr
|
|
* @return false|int
|
|
*/
|
|
public static function isFrontVirtualNumber($numberStr) {
|
|
return preg_match(self::$frontRegexStr, $numberStr);
|
|
}
|
|
|
|
/**
|
|
* 获取虚拟号码
|
|
* @param $numberStr
|
|
* @return mixed
|
|
*/
|
|
public static function getFrontVirtualNumber($numberStr) {
|
|
preg_match(self::$frontRegexStr, $numberStr, $matches);
|
|
return $matches[1];
|
|
}
|
|
|
|
/**
|
|
* 获取分机号
|
|
* @param $numberStr
|
|
* @return string|null
|
|
*/
|
|
public static function getFrontExtNumber($numberStr) {
|
|
preg_match(self::$frontRegexStr, $numberStr, $matches);
|
|
return $matches[2];
|
|
}
|
|
|
|
} |