gabeta / gsm-detector

检测手机号码的GSM网络

v1.1.0 2024-03-24 13:42 UTC

This package is auto-updated.

Last update: 2024-09-24 14:53:04 UTC


README

Build Status

关于

Gsm Detector 是一个PHP包,允许您知道给定手机号码的GSM网络名称。

安装

兼容PHP >= 5.4

composer require gabeta/gsm-detector

工作原理

您必须使用包含GSM网络名称及其不同前缀的数组初始化 GsmDetector 类。

示例代码

use Gabeta\GsmDetector\GsmDetector;

$gsmDetector = new GsmDetector([
    'orange' => [
        'fix' => ['22', '35'],
        'mobile' => ['09', '88']
    ],
    'mtn' => [
        'fix' => ['23', '24'],
        'mobile' => ['04', '05']
    ],
]);

在此,我们使用GSM mtn和orange 网络及其不同前缀实例化我们的类。我们表中定义的每个GSM网络都必须有“fix”和/或“mobile”键来定义我们的各种前缀。

use Gabeta\GsmDetector\GsmDetector;

$gsmDetector = new GsmDetector([
    'orange' => [
        'fix' => ['22', '35'],
        'mobile' => ['09', '88']
    ],
    'mtn' => [
        'fix' => ['23', '24'],
        'mobile' => ['04', '05']
    ],
]);

$gsmDetector->isMtn('04000000') // true

$gsmDetector->isMtn('24000000') // true
        
$gsmDetector->isMtn('35000000') // false
        
$gsmDetector->isMtn('08000000') // false

$gsmDetector->isMtn('23000000') // true

$gsmDetector->isOrange('88000000') // true

$gsmDetector->isOrange('09000000') // true

$gsmDetector->isOrange('22000000') // true

$gsmDetector->isMtnFix('23000000') // true

$gsmDetector->isMtnFix('24000000') // true

$gsmDetector->isMtnFix('04000000') // false

$gsmDetector->isMtnMobile('04000000') // true

$gsmDetector->isOrangeFix('22000000') // true

$gsmDetector->isOrangeFix('35000000') // true

$gsmDetector->isOrangeMobile('35000000') // false

/**
* OTHERS METHODS
**/

$gsmDetector->getGsmName('04000000'); // mtn

$gsmDetector->isMobile('04000000'); // true

$gsmDetector->isFix('04000000'); // false

对于每个新定义的GSM名称,将创建三个方法

  • is{Gsm}
  • is{Gsm}Fix
  • is{Gsm}Mobile

例如,对于moov,我们将有

  • isMoov
  • isMoovFix
  • isMoovMobile