mohamedhabibwork/laravel-wasl 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

mohamedhabibwork/laravel-wasl

Composer 安装命令:

composer require mohamedhabibwork/laravel-wasl

包简介

Laravel package for integrating with Wasl API (Saudi Arabia's Transportation General Authority dispatching platform)

README 文档

README

Latest Version on Packagist

GitHub Code Style Action Status Total Downloads

A Laravel package for integrating with the Wasl API (Saudi Arabia's Transportation General Authority dispatching platform). This package provides a clean, type-safe interface for all Wasl API endpoints including driver registration, eligibility checks, trip management, and location tracking.

Features

  • ✅ Complete Wasl API integration
  • ✅ Type-safe DTOs with strict typing (PHP 8.3+)
  • ✅ Comprehensive error handling with custom exceptions
  • ✅ Built-in validation rules (plate letters, identity numbers, etc.)
  • ✅ Error message helper with all Wasl API error codes and descriptions
  • ✅ Support for bulk operations (arrays)
  • ✅ Clean, modern code following Laravel best practices
  • ✅ Full support for all 6 Wasl API endpoints

Requirements

  • PHP 8.3 or higher
  • Laravel 11.x or 12.x

Installation

You can install the package via composer:

composer require mohamedhabibwork/laravel-wasl

Configuration

Publish the config file:

php artisan vendor:publish --tag="laravel-wasl-config"

Add your Wasl API credentials to your .env file:

Environment-based configuration (Recommended):

# Set environment: 'live' or 'dev' (default: 'live')
WASL_ENV=live

# Live environment credentials
LIVE_WASL_BASE_URL=https://wasl.api.elm.sa/api/dispatching/v2
LIVE_WASL_CLIENT_ID=your_live_client_id
LIVE_WASL_APP_ID=your_live_app_id
LIVE_WASL_APP_KEY=your_live_app_key
LIVE_WASL_TIMEOUT=30

# Dev environment credentials
DEV_WASL_BASE_URL=https://wasl.api.elm.sa/api/dispatching/v2
DEV_WASL_CLIENT_ID=your_dev_client_id
DEV_WASL_APP_ID=your_dev_app_id
DEV_WASL_APP_KEY=your_dev_app_key
DEV_WASL_TIMEOUT=30

Environment Configuration

The package supports two environments:

  • live - Production environment (default)
  • dev - Development/Testing environment

Set WASL_ENV=dev in your .env file to use the development environment. The package will automatically use the corresponding prefixed environment variables (DEV_WASL_* or LIVE_WASL_*).

Usage

Driver Registration

Register a driver and vehicle with Wasl:

use Habib\LaravelWasl\Facades\LaravelWasl;
use Habib\LaravelWasl\DTOs\DriverRegistrationRequest;
use Habib\LaravelWasl\DTOs\DriverData;
use Habib\LaravelWasl\DTOs\VehicleData;

// For Saudi driver (Hijri date)
$driver = new DriverData(
    identityNumber: '1234567890',
    emailAddress: 'driver@example.com',
    mobileNumber: '+966512345678',
    dateOfBirthHijri: '1420/01/01'
);

// For Non-Saudi driver (Gregorian date)
$driver = new DriverData(
    identityNumber: '2234567890',
    emailAddress: 'driver@example.com',
    mobileNumber: '+966512345678',
    dateOfBirthGregorian: '1990-01-01'
);

$vehicle = new VehicleData(
    sequenceNumber: '123456879',
    plateLetterRight: 'ا',
    plateLetterMiddle: 'ا',
    plateLetterLeft: 'ا',
    plateNumber: '1234',
    plateType: '1'
);

$request = new DriverRegistrationRequest(
    driver: $driver,
    vehicle: $vehicle
);

$response = LaravelWasl::registerDriver($request);

// Check eligibility status
if ($response->eligibility === \Habib\LaravelWasl\Enums\EligibilityStatus::VALID) {
    echo "Driver is eligible until: " . $response->eligibilityExpiryDate;
}

Check Driver Eligibility (Single)

use Habib\LaravelWasl\Facades\LaravelWasl;

$response = LaravelWasl::checkEligibility('1234567890');

echo "Eligibility: " . $response->driverEligibility->value;
echo "Expiry Date: " . $response->eligibilityExpiryDate;

foreach ($response->vehicles as $vehicle) {
    echo "Vehicle: " . $vehicle->sequenceNumber;
    echo "Vehicle Eligibility: " . $vehicle->vehicleEligibility->value;
}

Check Driver Eligibility (Bulk)

Check eligibility for multiple drivers at once (max 10,000):

use Habib\LaravelWasl\Facades\LaravelWasl;
use Habib\LaravelWasl\DTOs\DriverEligibilityBulkRequest;

$request = new DriverEligibilityBulkRequest([
    '1000000001',
    '1000000002',
    '1000000003'
]);

$response = LaravelWasl::checkEligibilityBulk($request);

foreach ($response->responses as $driverResponse) {
    echo "Driver: " . $driverResponse->identityNumber;
    echo "Eligibility: " . $driverResponse->driverEligibility->value;
}

Register a Trip

use Habib\LaravelWasl\Facades\LaravelWasl;
use Habib\LaravelWasl\DTOs\TripRegistrationRequest;

$request = new TripRegistrationRequest(
    sequenceNumber: '123456789',
    driverId: '1234567890',
    tripId: 'TRIP_2025_001234',
    distanceInMeters: 5420,
    durationInSeconds: 1245,
    customerRating: 4.5,
    customerWaitingTimeInSeconds: 180,
    originCityNameInArabic: 'الرياض',
    destinationCityNameInArabic: 'الرياض',
    originLatitude: 24.723437,
    originLongitude: 46.117452,
    destinationLatitude: 24.763437,
    destinationLongitude: 46.547452,
    pickupTimestamp: '2025-12-07T14:30:00.000',
    dropoffTimestamp: '2025-12-07T14:50:45.000',
    startedWhen: '2025-12-07T14:25:00.000',
    tripCost: 35.50,
    driverArrivalTime: '2025-12-07T14:28:00.000',
    driverAssignTime: '2025-12-07T14:25:30.000'
);

$response = LaravelWasl::registerTrip($request);

if ($response->success) {
    echo "Trip registered successfully!";
}

Update Trip(s)

Update a single trip or multiple trips (max 1000):

use Habib\LaravelWasl\Facades\LaravelWasl;
use Habib\LaravelWasl\DTOs\TripUpdateRequest;

// Single trip update
$trip = new TripUpdateRequest(
    tripId: 'TRIP_2025_001234',
    customerRating: 5.0,
    tripCost: 35.50
);

$response = LaravelWasl::updateTrips($trip);

// Multiple trips update
$trips = [
    new TripUpdateRequest(
        tripId: 'TRIP_2025_001234',
        customerRating: 5.0,
        tripCost: 35.50
    ),
    new TripUpdateRequest(
        tripId: 'TRIP_2025_001235',
        customerRating: 4.0,
        tripCost: 28.00
    ),
];

$response = LaravelWasl::updateTrips($trips);

// Check for rejected trips
foreach ($response->rejectedTrips as $rejectedTrip) {
    echo "Trip {$rejectedTrip->tripId} rejected: {$rejectedTrip->rejectionReason}";
}

Update Vehicle Location(s)

Update location for a single vehicle or multiple vehicles (max 1000):

use Habib\LaravelWasl\Facades\LaravelWasl;
use Habib\LaravelWasl\DTOs\LocationUpdateRequest;

// Single location update
$location = new LocationUpdateRequest(
    driverIdentityNumber: '1234567890',
    vehicleSequenceNumber: '123456789',
    latitude: 24.723437,
    longitude: 46.117452,
    hasCustomer: true,
    updatedWhen: '2025-12-07T15:30:00.000'
);

$response = LaravelWasl::updateLocations($location);

// Multiple locations update
$locations = [
    new LocationUpdateRequest(
        driverIdentityNumber: '1234567890',
        vehicleSequenceNumber: '123456789',
        latitude: 24.723437,
        longitude: 46.117452,
        hasCustomer: true,
        updatedWhen: '2025-12-07T15:30:00.000'
    ),
    new LocationUpdateRequest(
        driverIdentityNumber: '1234567891',
        vehicleSequenceNumber: '123456780',
        latitude: 25.723437,
        longitude: 47.117452,
        hasCustomer: false,
        updatedWhen: '2025-12-07T15:30:00.000'
    ),
];

$response = LaravelWasl::updateLocations($locations);

// Check for failed vehicles
foreach ($response->failedVehicles as $failedVehicle) {
    echo "Failed: {$failedVehicle}";
}

Error Handling

The package provides custom exceptions for different error scenarios:

use Habib\LaravelWasl\Exceptions\WaslException;
use Habib\LaravelWasl\Exceptions\WaslNotFoundException;
use Habib\LaravelWasl\Exceptions\WaslBadRequestException;
use Habib\LaravelWasl\Exceptions\WaslUnauthorizedException;
use Habib\LaravelWasl\Exceptions\WaslServerException;

try {
    $response = LaravelWasl::registerDriver($request);
} catch (WaslNotFoundException $e) {
    // Driver or vehicle not found
    echo "Error: " . $e->getMessage();
    echo "Result Code: " . $e->resultCode;
} catch (WaslBadRequestException $e) {
    // Validation error or bad request
    echo "Error: " . $e->getMessage();
    echo "Result Message: " . $e->resultMsg;
} catch (WaslUnauthorizedException $e) {
    // Authentication failed
    echo "Authentication error: " . $e->getMessage();
} catch (WaslServerException $e) {
    // Server error
    echo "Server error: " . $e->getMessage();
} catch (WaslException $e) {
    // Other Wasl API errors
    echo "Error: " . $e->getMessage();
}

Validation

The package includes built-in validation for all Wasl API fields:

Plate Letter Validation

use Habib\LaravelWasl\Rules\WaslPlateLetter;

// Use in Laravel form requests
$rules = [
    'plate_letter' => ['required', new WaslPlateLetter()],
];

// Or access allowed letters directly
$allowedLetters = WaslPlateLetter::ALLOWED_LETTERS;
// ['ا', 'ب', 'ح', 'د', 'ر', 'س', 'ص', 'ط', 'ع', 'ق', 'ك', 'ل', 'م', 'ن', 'هـ', 'و', 'ى']

DTO Validation

All DTOs automatically validate their data when instantiated:

use Habib\LaravelWasl\DTOs\DriverData;

try {
    $driver = new DriverData(
        identityNumber: '1234567890', // Must be exactly 10 digits
        emailAddress: 'driver@example.com', // Must be valid email
        mobileNumber: '+966512345678', // Must match +966XXXXXXXXX format
        dateOfBirthHijri: '1420/01/01' // Must be YYYY-MM-DD or YYYY/MM/DD
    );
} catch (\InvalidArgumentException $e) {
    echo "Validation error: " . $e->getMessage();
}

Error Message Helper

Get human-readable descriptions for Wasl API error codes:

use Habib\LaravelWasl\Helpers\WaslErrorMessageHelper;

// Get result code description
$description = WaslErrorMessageHelper::getResultCodeDescription('DRIVER_NOT_FOUND');
// Returns: "Driver information is not correct"

// Get rejection reason description
$reason = WaslErrorMessageHelper::getRejectionReasonDescription('DRIVER_LICENSE_EXPIRED');
// Returns: "Driver license is expired"

// Get criminal record status description
$status = WaslErrorMessageHelper::getCriminalRecordStatusDescription('PENDING_DRIVER_APPROVAL');
// Returns: "SMS sent to driver, waiting for approval on Absher"

// Get trip rejection reason (with Arabic support)
$englishReason = WaslErrorMessageHelper::getTripRejectionReason('duplicate trip id');
// Returns: "Trip ID is already registered"

$arabicReason = WaslErrorMessageHelper::getTripRejectionReason('duplicate trip id', arabic: true);
// Returns: "رقم الرحلة مسجل مسبقا"

Enums

The package includes enums for type safety:

use Habib\LaravelWasl\Enums\EligibilityStatus;
use Habib\LaravelWasl\Enums\Gender;
use Habib\LaravelWasl\Enums\PlateType;
use Habib\LaravelWasl\Enums\CriminalRecordStatus;

// EligibilityStatus: VALID, INVALID, PENDING
// Gender: MALE, FEMALE
// PlateType: PRIVATE_CAR, TAXI, TRUCK, BUS, MOTORCYCLE
// CriminalRecordStatus: WAITING, PENDING_DRIVER_APPROVAL, DRIVER_APPROVED, etc.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

mohamedhabibwork/laravel-wasl 适用场景与选型建议

mohamedhabibwork/laravel-wasl 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 12 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 mohamedhabibwork/laravel-wasl 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-06