定制 anglemx/mexico-postal-codes 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

anglemx/mexico-postal-codes

Composer 安装命令:

composer require anglemx/mexico-postal-codes

包简介

PHP utility and database to lookup Mexico Postal Code information

README 文档

README

PHP utility and database to lookup Mexico Postal Code information

How to Use

$postalCode = PostalCode::fastLookup('64630');

printf('Postal Code:    %s' . PHP_EOL, $postalCode->getPostalCode());
printf('State:          %d %s %s' . PHP_EOL, $postalCode->getState(), $postalCode->getStateIso(), $postalCode->getStateName());

printf('Settlements:' . PHP_EOL);

foreach ($postalCode->getSettlements() as $settlement) {
    printf('> %s %s' . PHP_EOL, $settlement->getId(), $settlement->getName());
    printf('  Type:   %s - %s' . PHP_EOL, $settlement->getType(), $settlement->getTypeName());
    printf('  City:   %s' . PHP_EOL, $settlement->getCity());
    printf('  County: %s' . PHP_EOL, $settlement->getCounty());
    printf('  Zone:   %s - %s' . PHP_EOL, $settlement->getZone(), $settlement->getZoneName());
}
Postal Code:    64630
State:          19 NLE Nuevo León
Settlements:
> 330 Colinas de San Jerónimo
  Type:   9 - Colonia
  City:   Monterrey
  County: Monterrey
  Zone:   U - Urbano
> 331 San Jemo
  Type:   9 - Colonia
  City:   Monterrey
  County: Monterrey
  Zone:   U - Urbano

Database Source

The database is downloaded from the official Correos de México website at: https://www.correosdemexico.gob.mx/SSLServicios/ConsultaCP/CodigoPostal_Exportar.aspx and it is then parsed and processed to optimize the filesize a bit.

Last database update: January 2, 2022

The database is published by SEPOMEX (SErvicio POstal MEXicano) and includes a Disclaimer Notice that allows personal use of the data but no commercial use at all. This must be honored by anybody using this PHP library:

El Catálogo Nacional de Códigos Postales, es elaborado por Correos de México y se proporciona en forma gratuita para uso particular, no estando permitida su comercialización, total o parcial, ni su distribución a terceros bajo ningún concepto.

Database Processing

To update and autogenerate, place the CPdescarga.txt file inside the resources/ directory, then execute the ProcessSepomexPostalCodeDatabase.php script.

  • CPdescargatxt.zip -> 2MB compressed file
  • CPdescarga.txt -> 14.6MB pipe-separated file
  • mx-postal-codes.csv -> 6.94MB nested pipe-separated file

The column definitions can be found in this link: https://www.correosdemexico.gob.mx/SSLServicios/ConsultaCP/imagenes/Descrip.pdf

Database Analytics

We've included a very basic and barebones analytics script in AnalyticsSepomexPostalCodeDatabase.php that parses the raw database and generates a few insights into the data.

Interesting facts from the Jan 2nd, 2022 database:

  • There are 31,827 unique PostalCodes in Mexico
  • PostalCode 85203 in Cajeme, Sonora, has 310 settlements registered in the same PostalCode.

Testing

php vendor/bin/phpunit tests/PostalCodeLookupTest.php

TO-DO

  • Implement "database expand" for PostalCodes to minimize the library install size. The current PostalCode database file weights 6.94MB, if we zip it we could reduce it to 1.6MB.
  • The "SingleLookup" method for PostalCodes scans the file very quickly before parsing. This could be further optimized if the database file was ordered by "popularity", or at least by "cities first, rural second".

References

Some interesting tidbits from https://www.correosdemexico.gob.mx/DatosAbiertos/Normateca/SUS/LOG/LO7.pdf

  1. Los dos primeros dígitos identifican una entidad federativa y en el caso de la Ciudad de México una alcaldía.
  2. El tercer dígito identifica en las entidades federativas un conjunto de municipios, un municipio o parte de un municipio y en la Ciudad de México parte de una alcaldía
  3. El cuarto dígito identifica en las entidades federativas y en la Ciudad de México un conjunto de asentamientos humanos urbanos y rurales.
  4. El quinto dígito identifica en las entidades federativas y en la Ciudad de México un conjunto de asentamientos humanos urbanos y rurales o un asentamiento humano urbano rural o una oficina postal.

anglemx/mexico-postal-codes 适用场景与选型建议

anglemx/mexico-postal-codes 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13.29k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 01 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「postalcode」 「zipcode」 「mexico」 「angle」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 anglemx/mexico-postal-codes 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 anglemx/mexico-postal-codes 我们能提供哪些服务?
定制开发 / 二次开发

基于 anglemx/mexico-postal-codes 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 13.29k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 33
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-01-08