phonedata

package module
v0.0.0-...-3598488 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2017 License: GPL-3.0 Imports: 9 Imported by: 0

README

手机号码归属地信息库、手机号归属地查询

这可能是github上能找到的最新最全的中国境内手机号归属地信息库

基于GO语言实现,使用二分查找法。

  • 归属地信息库文件大小:3,203,029 字节
  • 归属地信息库最后更新:2017年1月
  • 手机号记录条数:354522

phone.dat文件格式

    | 4 bytes |                     <- phone.dat 版本号(如:1701即17年1月份)
    ------------
    | 4 bytes |                     <-  第一个索引的偏移
    -----------------------
    |  offset - 8            |      <-  记录区
    -----------------------
    |  index                 |      <-  索引区
    -----------------------
  1. 头部为8个字节,版本号为4个字节,第一个索引的偏移为4个字节 ;
  2. 记录区 中每条记录的格式为"<省份>|<城市>|<邮编>|<长途区号>\0"。 每条记录以'\0'结束;
  3. 索引区 中每条记录的格式为"<手机号前七位><记录区的偏移><卡类型>",每个索引的长度为9个字节;

安装使用

package main

import (
	"fmt"

	"github.com/xluohome/phonedata"
)

func main() {
	pr, err := phonedata.Find("18957509123")
	if err != nil {
		panic(err)
	}
	fmt.Print(pr)
}



性能测试

Thinkpad s3 (Intel(R) Core(TM) i5-4200U CPU @ 1.60GHz)

go test -v --bench="."

BenchmarkFindPhone-4      200000              7320 ns/op

其他语言实现

python: https://github.com/lovedboy/phone

php : https://github.com/shitoudev/phone-location , https://github.com/iwantofun/php_phone

java: https://github.com/fengjiajie/phone-number-geo

感谢

@lovedboy https://github.com/lovedboy

@zhengji https://github.com/zheng-ji/gophone

Documentation

Index

Constants

View Source
const (
	CMCC               ISP = iota + 0x01 //中国移动
	CUCC                                 //中国联通
	CTCC                                 //中国电信
	CTCC_v                               //电信虚拟运营商
	CUCC_v                               //联通虚拟运营商
	CMCC_v                               //移动虚拟运营商
	INT_LEN            = 4
	CHAR_LEN           = 1
	HEAD_LENGTH        = 8
	PHONE_INDEX_LENGTH = 9
	PHONE_DAT          = "phone.dat"
)

Variables

This section is empty.

Functions

func Debug

func Debug()

Types

type ISP

type ISP uint8

func (ISP) MarshalJSON

func (this ISP) MarshalJSON() ([]byte, error)

func (ISP) String

func (this ISP) String() string

fmt.Stringer

type PhoneRecord

type PhoneRecord struct {
	PhoneNum string `json:"phone"`
	Province string `json:"province"`
	City     string `json:"city"`
	ZipCode  string `json:"postcode"`
	AreaCode string `json:"areacode"`
	CardType ISP    `json:"cardtype"`
}

func Find

func Find(phone_num string) (pr *PhoneRecord, err error)

二分法查询phone数据

func (PhoneRecord) String

func (pr PhoneRecord) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL