sarkhanrasimoghlu/laravel-asanimza
Composer 安装命令:
composer require sarkhanrasimoghlu/laravel-asanimza
包简介
Laravel package for Asan İmza mobile authentication and digital signing via JSON-RPC 2.0 proxy API
README 文档
README
Laravel package for Asan İmza — Azerbaijan's mobile authentication and digital signing system. Communicates with the Asan İmza proxy server via JSON-RPC 2.0 protocol.
Requirements
- PHP ^8.3
- Laravel ^12.0
- Asan İmza proxy server running (default:
http://localhost:8090)
Installation
composer require sarkhanrasimoghlu/laravel-asanimza
Publish the configuration file:
php artisan vendor:publish --tag=asanimza-config
Configuration
Add the following to your .env file:
ASANIMZA_BASE_URL=http://localhost:8090 ASANIMZA_SERVICE_NAME=AsanDoc ASANIMZA_LANGUAGE=aze ASANIMZA_TIMEOUT=30 ASANIMZA_LOG_ENABLED=true ASANIMZA_LOG_CHANNEL=stack
| Variable | Default | Description |
|---|---|---|
ASANIMZA_BASE_URL |
http://localhost:8090 |
Asan İmza proxy server URL |
ASANIMZA_SERVICE_NAME |
AsanDoc |
Registered service name |
ASANIMZA_LANGUAGE |
aze |
Default language (aze, rus, eng) |
ASANIMZA_TIMEOUT |
30 |
HTTP request timeout (seconds) |
ASANIMZA_LOG_ENABLED |
true |
Enable/disable request logging |
ASANIMZA_LOG_CHANNEL |
stack |
Laravel log channel |
Usage
Inject AsanImzaInterface via constructor or method injection:
use Sarkhanrasimoghlu\AsanImza\Contracts\AsanImzaInterface;
Authentication
Step 1: Start authentication
public function login(AsanImzaInterface $asanImza) { $result = $asanImza->authenticate('+994501234567', 'userId123'); // Show verification code to the user // $result->verificationCode — user must confirm this on their phone // $result->transactionId — needed for status check // $result->certificate — needed for status check // $result->challenge — needed for status check return response()->json([ 'transactionId' => $result->transactionId, 'verificationCode' => $result->verificationCode, 'certificate' => $result->certificate, 'challenge' => $result->challenge, ]); }
Step 2: Check authentication status (polling)
public function checkAuth(AsanImzaInterface $asanImza, Request $request) { $status = $asanImza->getAuthStatus( transactionId: $request->input('transactionId'), certificate: $request->input('certificate'), challenge: $request->input('challenge'), ); if ($status->status === \Sarkhanrasimoghlu\AsanImza\Enums\AuthStatus::USER_AUTHENTICATED) { // Authentication successful // $status->signature contains the base64-encoded signature } return response()->json([ 'status' => $status->status->value, ]); }
Get Certificate Data
Extract user information from a certificate:
$certData = $asanImza->getCertificateData($certificate); $certData->firstName; // "John" $certData->surname; // "Doe" $certData->personalCode; // "1234567" $certData->organizationName; // nullable $certData->certType; // CertType enum (AUTHENTICATION, CITIZEN_SIGNING, etc.)
Digital Signing
Step 1: Get signing certificates
$certs = $asanImza->getSigningCertificates('+994501234567', 'userId123'); // Returns: ['certId1' => 'base64cert1', 'certId2' => 'base64cert2']
Step 2: Sign files
use Sarkhanrasimoghlu\AsanImza\DTOs\DataFile; $dataFiles = [ new DataFile( content: base64_encode(file_get_contents('/path/to/document.pdf')), fileName: 'document.pdf', mimeType: 'application/pdf', ), ]; $result = $asanImza->signFiles( dataFiles: $dataFiles, phoneNumber: '+994501234567', userId: 'userId123', certIdentifier: 'certId1', certificate: $certs['certId1'], ); // $result->transactionId // $result->verificationCode — show to user // $result->hash — needed for status check // $result->container — needed for status check
Step 3: Check signing status (polling)
$status = $asanImza->getSignFileStatus( transactionId: $result->transactionId, hash: $result->hash, container: $result->container, certificate: $certs['certId1'], ); if ($status->status === \Sarkhanrasimoghlu\AsanImza\Enums\SignStatus::SIGNATURE_CREATED) { // $status->container — signed container (base64) $signedContent = base64_decode($status->container); }
Error Handling
All exceptions extend AsanImzaException:
use Sarkhanrasimoghlu\AsanImza\Exceptions\AsanImzaException; use Sarkhanrasimoghlu\AsanImza\Exceptions\JsonRpcException; try { $result = $asanImza->authenticate('+994501234567', 'userId123'); } catch (JsonRpcException $e) { // JSON-RPC error from Asan İmza proxy $e->getErrorCode(); // e.g., 2004 $e->getErrorMessage(); // e.g., "Unknown phone number" $e->getContext(); // ['error_code' => 2004, 'error_message' => '...'] } catch (AsanImzaException $e) { // HTTP or parsing error $e->getMessage(); $e->getContext(); }
Common Error Codes
| Code | Description |
|---|---|
| 1002 | Service overloaded |
| 2004 | Unknown phone number |
| 2013 | No authentication certificate |
| 2017 | Phone number and user ID are not related |
| 2018 | Authentication certificate is not valid |
| 2020 | No signing certificate |
| 2021 | Signing certificate is not valid |
| 2022 | Forbidden service name |
| -32700 | JSON-RPC parse error |
| -32600 | Invalid request |
| -32601 | Method not found |
Enums
AuthStatus
| Value | Description |
|---|---|
USER_AUTHENTICATED |
Authentication successful |
OUTSTANDING_TRANSACTION |
Waiting for user confirmation |
NOT_VALID |
Transaction not valid |
EXPIRED_TRANSACTION |
Transaction expired |
USER_CANCEL |
User cancelled on phone |
MID_NOT_READY |
Mobile ID not ready |
SENDING_ERROR |
Error sending to phone |
SIM_ERROR |
SIM card error |
INTERNAL_ERROR |
Internal system error |
SignStatus
Same values as AuthStatus, except USER_AUTHENTICATED is replaced by SIGNATURE_CREATED.
CertType
| Value | Description |
|---|---|
| 0 | Authentication |
| 1 | Citizen signing |
| 2 | Business signing |
| 3 | Governmental signing |
| 4 | Youth personal |
| 5 | Digital stamp |
License
MIT
sarkhanrasimoghlu/laravel-asanimza 适用场景与选型建议
sarkhanrasimoghlu/laravel-asanimza 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 2, 最近一次更新时间为 2026 年 03 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Authentication」 「laravel」 「e-signature」 「azerbaijan」 「digital-signature」 「asan-imza」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sarkhanrasimoghlu/laravel-asanimza 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sarkhanrasimoghlu/laravel-asanimza 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sarkhanrasimoghlu/laravel-asanimza 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Automatically logs-in users if they are already authenticated by a remote source. (e.g. environment variable REMOTE_USER)
GraphQL authentication for your headless Craft CMS applications.
Laravel middleware to restrict a site or specific routes using HTTP basic authentication
Email Toolkit Plugin for CakePHP
A list of dangerous usernames
Alfabank REST API integration
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 34
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-16