Coder Social home page Coder Social logo

chengcanmm77 / phone-number-geo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eeemt/phone-number-geo

0.0 2.0 0.0 1.05 MB

lookup geographical information of phone number by dat format data; 手机归属地查询

License: MIT License

Java 100.00%

phone-number-geo's Introduction

手机归属地查询

Maven Central Build Status javadoc Coverage Status GitHub

简介

根据手机号确定手机号运营商即归属地, 支持包括虚拟运营商的**大陆手机号查询.

数据源

数据源dat文件来自xluohome/phonedata提供的数据库, 会不定时同步更新数据库

当前数据源版本: 201911

maven

<dependency>
    <groupId>me.ihxq.projects</groupId>
    <artifactId>phone-number-geo</artifactId>
    <version>x.x.x-xxxxxx</version>
</dependency>

这里获取最新版号.

版本号解释:

示例

class Demo1{
    public static void main(String[] args){
        PhoneNumberLookup phoneNumberLookup = new PhoneNumberLookup();
        PhoneNumberInfo found = phoneNumberLookup.lookup("18798896741").orElseThrow(RuntimeException::new);
    }
}
class Demo2{
    public static void main(String[] args){
        PhoneNumberLookup phoneNumberLookup = new PhoneNumberLookup();
        String province = phoneNumberLookup.lookup("130898976761")
                        .map(PhoneNumberInfo::getAttribution)
                        .map(Attribution::getProvince)
                        .orElse("未知");
    }
}
class Demo3{
    public static void main(String[] args){
        PhoneNumberLookup phoneNumberLookup = new PhoneNumberLookup();
        PhoneNumberInfo found = phoneNumberLookup.lookup("18798896741").orElseThrow(RuntimeException::new);
        found.getNumber(); // 18798896741
        found.getAttribution().getProvince(); // 贵州
        found.getAttribution().getCity(); // 贵阳
        found.getAttribution().getZipCode(); // 550000
        found.getAttribution().getAreaCode(); // 0851
        found.getIsp(); // ISP.CHINA_MOBILE
    }
}

对比libphonenumber

对比libphonenumber, libphonenumber有更多功能, 包括验证号码格式, 格式化, 时区等, 但基于xluohome/phonedata提供的dat数据库能囊括包含虚拟运营商号段的更多号段.

至于速度, 未做比较, 但本仓库实现已足够快, 选择时建议更多权衡易用性, 功能和数据覆盖范围.

Benchmark

工程里已内置四种算法, 跑分情况如下:

Benchmark                                   Mode  Cnt        Score       Error  Units
BenchmarkRunner.anotherBinarySearchLookup   avgt    5      390.483 ±     3.544  ns/op
BenchmarkRunner.binarySearchLookup          avgt    5      386.357 ±     3.739  ns/op
BenchmarkRunner.prospectBinarySearchLookup  avgt    5      304.622 ±     1.899  ns/op
BenchmarkRunner.sequenceLookup              avgt    5  1555265.227 ± 48814.379  ns/op

性能测试源码位于me.ihxq.projects.pna.benchmark.BenchmarkRunner, 基于JMH

测试样本在每次启动时生成, 供所有算子测试使用, 所以每次测试结果有差异, 结果可用于横向比较, 不适用于纵向比较.

默认使用的是me.ihxq.projects.pna.algorithm.BinarySearchAlgorithmImpl, 可以通过new PhoneNumberLookup(new AlgorithmYouLike());使用其他算法;

也可自行实现算法, 实现me.ihxq.projects.pna.algorithm.LookupAlgorithm即可.

感谢

Todo

  • 发布到maven**仓库

phone-number-geo's People

Contributors

eeemt avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.