承接 dannyps/ccidadao 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

dannyps/ccidadao

Composer 安装命令:

composer require dannyps/ccidadao

包简介

A class for generating and validating Portuguese Citizen Card (CC aka Cartão de Cidadão) Numbers.

README 文档

README

CCidadao is a PHP Class used to validate and generate Citizen Card numbers.

How to use

Instalation

CCidadao is available on Packagist! You can install it via Composer, by typing:

$ composer require Dannyps/CCidadao

The class will be auto-loaded by composer. Thus, in order to use it, you need only require 'vendor/autoload.php'; in your PHP script.

Softening the curve

Portuguese Citizen Cards are a complicated subject. They have two check digits, and a weird version control system. Internal variables contain the following fields:

In the example number:

12345678 9 ZZ 0
┃        ┃ ┃  ┃
┃        ┃ ┃  ┗━━━> Versioned check digit ----> $vcd
┃        ┃ ┗━━━━━━> Version chars ------------> $vcc
┃        ┗━━━━━━━━> Constant check digit -----> $ccd
┗━━━━━━━━━━━━━━━━━> the number itself --------> $num
  • The version chars represent the version of the document in the following manner:
  • ZZ => v1
  • ZY => v2
  • ZX => v3
  • ...
  • ZA => v26
  • YZ => v27
  • etc... Both $ccd and $vcd can be determined, provided the $num and $ver/$vcc are available, respectively.

Moreover, the $ccd depends solely on the $num, whereas the $vcd depends on the $num and on the $vcc.

Code Examples

Test code is a good place to start. However, code examples are displayed below for your convenience.

Generating an array of valid CC numbers.

Note: The fact these numbers are valid does not mean they are being used by anyone.

<?php
require 'vendor/autoload.php';
use Dannyps\CCidadao\CCidadao;

$ver = [
    'min' => 1,
    'max' => 2,
];

$beg = 15000000;
$end = 15000100;

$arr = [];

for ($i = $beg; $i < $end; $i++) {
    for ($j = $ver['min']; $j <= $ver['max']; $j++) {
        array_push($arr, (new CCidadao($i . "_", $j))->__toString());
    }
}

// $arr now contains versions 1 and 2 of all CCs from 15000000 to 15000100. These are valid values.

Getting the next version of a CC number

As time goes by, people get new Citizen Cards. However, their numbers are already predestined. Because of the algorithm used, it is possible to foresee all possible numbers. Moreover, we know these numbers are sequential.

<?php
require 'vendor/autoload.php';
use Dannyps\CCidadao\CCidadao;

$cc = new CCidadao("15632563ZZ7");
$cc->next(); // advance current cc
echo ($cc);

// -- another method --

echo new CCidadao("15632563", 2);

Validating a CC number

<?php
require 'vendor/autoload.php';
use Dannyps\CCidadao\CCidadao;

try {
    new CCidadao("15632563ZZ7");
} catch(Exception $e){
    // invalid
}

Motivation

There was an interest in being able to quickly generate valid CC numbers for pentesting reasons. Thus, CCidadao was born. Its applications, however, are more abrangent than that.

Contributing

You are welcome to contribute to the code, as well as to the documentation. You should do so by means of a Pull Request. You may use xDebug to profile the execution and find the less effecient methods.

How does it work?

The algorithms to determine both control digits are available online, in some blogs and similar pages. Testing of this class began with real CC numbers, as this was the only way to make sure the code was developed according to reality.

dannyps/ccidadao 适用场景与选型建议

dannyps/ccidadao 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 10, 最近一次更新时间为 2024 年 12 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 dannyps/ccidadao 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-05