altwebdesign/sameday-php-sdk 问题修复 & 功能扩展

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

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

altwebdesign/sameday-php-sdk

Composer 安装命令:

composer require altwebdesign/sameday-php-sdk

包简介

Sameday Courier SDK for PHP — fork with countryCode support for counties and cities geolocation

README 文档

README

Build Status Latest Stable Version

This repository contains the open source PHP SDK that allows you to access the Sameday Courier Platform from your PHP app. It was inspired by Facebook PHP-SDK.

This fork adds countryCode support to SamedayGetCountiesRequest and SamedayGetCitiesRequest, and increases the default $countPerPage from 50 to 500. This allows users with a Romanian Sameday account to query geolocation data for other countries (e.g. Hungary) without switching API hosts. Maintained by AltWeb.

Installation

Install this fork with Composer:

composer require altwebdesign/sameday-php-sdk

This is a fork of sameday-courier/php-sdk with added countryCode support. All original features are preserved.

Usage

Note: This version of the Sameday SDK for PHP requires PHP 5.4 or greater.

Simple example to get available pickup points and services for a client, request a new AWB and download the PDF for it.

require_once __DIR__ . '/vendor/autoload.php'; // Change path as needed.

// Initialization. Change user and password as needed for your account. For testing purposes (also implies different user/password) set a third parameter to 'https://sameday-api.demo.zitec.com'.
$samedayClient = new \Sameday\SamedayClient('user', 'password');
$sameday = new \Sameday\Sameday($samedayClient);

// Get list of available pickup points for client.
$pickupPoints = $sameday->getPickupPoints(new \Sameday\Requests\SamedayGetPickupPointsRequest());
// Use first found pickup point id. These ids are different for DEMO and PROD environments. This id can be cached on your application.
$pickupPointId = $pickupPoints->getPickupPoints()[0]->getId();

// Get list of available services for client.
$services = $sameday->getServices(new \Sameday\Requests\SamedayGetServicesRequest());
// Use first service id. These ids are different for DEMO and PROD environments. This id can be cached on your application.
// This is just for example purpose. Choose the right service for your app.
// For instance if requesting with 2H service (delivery in 2 hours) and cities are different (pickup point city and recipient city) then the validation will fail.
$serviceId = $services->getServices()[0]->getId();

try {
    $awb = $sameday->postAwb(new \Sameday\Requests\SamedayPostAwbRequest(
        $pickupPointId,
        null, // Contact person id can be left to NULL and default will be used.
        new \Sameday\Objects\Types\PackageType(\Sameday\Objects\Types\PackageType::PARCEL),
        [
            // This will generate an AWB expedition with 2 parcels (packages). Only the $weight is mandatory.
            new \Sameday\Objects\ParcelDimensionsObject(0.5),
            new \Sameday\Objects\ParcelDimensionsObject(3, 15, 28, 67)
        ],
        $serviceId,
        new \Sameday\Objects\Types\AwbPaymentType(\Sameday\Objects\Types\AwbPaymentType::CLIENT), // Who pays for the AWB. CLIENT is the only allowed value.
        new \Sameday\Objects\PostAwb\Request\AwbRecipientEntityObject('Huedin', 'Cluj', 'str. Otesani', 'Nume Destinatar', '0700111111', 'destinatar.colet@gmail.com', new \Sameday\Objects\PostAwb\Request\CompanyEntityObject('nume companie SRL')), // AWB recipient. Please note that CompanyEntityObject is optional if the recipient is not company.
        0, // Insured value.
        100 // Cash on delivery value. Can be 0 if the payment was made online.
        // Other parameters may follow, see https://github.com/sameday-courier/php-sdk/blob/master/docs/reference/SamedayPostAwbRequest.md
    ));
} catch (\Sameday\Exceptions\SamedayBadRequestException $e) {
    // When request fails validation. Show the list of validation errors.
    var_dump($e->getErrors());
    exit;
} // Other exceptions may be thrown, see https://github.com/sameday-courier/php-sdk/blob/master/docs/reference.md#core-exceptions

$pdf = $sameday->getAwbPdf(new \Sameday\Requests\SamedayGetAwbPdfRequest($awb->getAwbNumber(), new \Sameday\Objects\Types\AwbPdfType(\Sameday\Objects\Types\AwbPdfType::A6)));
echo $pdf->getPdf();

Complete documentation, installation instructions, and examples are available here.

Geolocation — Counties & Cities with countryCode Support

This feature is available in this fork: altwebdesign/sameday-php-sdk

By default the Sameday API returns Romanian counties and cities. This fork adds an optional countryCode parameter to both SamedayGetCountiesRequest and SamedayGetCitiesRequest, allowing you to fetch geolocation data for other supported countries (e.g. 'HU' for Hungary) using your existing Romanian account credentials, without needing to switch to a different API host.

Get Counties (PHP)

require_once __DIR__ . '/vendor/autoload.php';

$samedayClient = new \Sameday\SamedayClient('user', 'password');
$sameday = new \Sameday\Sameday($samedayClient);

// Get Romanian counties (default behaviour — countryCode omitted)
$roCounties = $sameday->getCounties(new \Sameday\Requests\SamedayGetCountiesRequest(''));

// Get Hungarian counties
$huCounties = $sameday->getCounties(new \Sameday\Requests\SamedayGetCountiesRequest('', 'HU'));

foreach ($huCounties->getCounties() as $county) {
    echo $county->getId() . '' . $county->getName() . PHP_EOL;
}

Get Cities by County (PHP)

// Get cities for a Romanian county (default)
$roCities = $sameday->getCities(new \Sameday\Requests\SamedayGetCitiesRequest($countyId));

// Get cities for a Hungarian county
// Constructor: ($countyId, $name, $postalCode, $countryCode)
$huCities = $sameday->getCities(new \Sameday\Requests\SamedayGetCitiesRequest($countyId, '', null, 'HU'));

foreach ($huCities->getCities() as $city) {
    echo $city->getId() . '' . $city->getName() . PHP_EOL;
}

Using Setters

You can also set the country code after instantiation:

$request = new \Sameday\Requests\SamedayGetCountiesRequest('');
$request->setCountryCode('HU');

$counties = $sameday->getCounties($request);

Laravel Examples

Setup

use Sameday\Sameday;
use Sameday\SamedayClient;
use Sameday\Requests\SamedayGetCountiesRequest;
use Sameday\Requests\SamedayGetCitiesRequest;

$sameday = new Sameday(
    new SamedayClient(
        env('SAMEDAY_USER'),
        env('SAMEDAY_PASSWORD')
    )
);

Get Hungarian Counties (with Cache)

public function getCounties()
{
    $data = \Cache::rememberForever('sameday_counties_hu', function () use ($sameday) {
        $counties = $sameday->getCounties(new SamedayGetCountiesRequest('', 'HU'));
        return json_decode($counties->getRawResponse()->getBody())->data;
    });

    return response()->json([
        'success' => 1,
        'counties' => $data,
    ]);
}

Get Hungarian Cities by County (with Cache)

public function getCities($countyId)
{
    $data = \Cache::rememberForever('sameday_hu_cities_' . $countyId, function () use ($sameday, $countyId) {
        $cities = $sameday->getCities(new SamedayGetCitiesRequest($countyId, '', null, 'HU'));
        return json_decode($cities->getRawResponse()->getBody())->data;
    });

    return response()->json([
        'success' => 1,
        'cities' => $data,
    ]);
}

Tip: Results are cached forever (rememberForever) since county and city data rarely changes. Use a versioned cache key (e.g. sameday_counties_hu_v2) if you ever need to bust the cache manually.

Pagination Note

This fork increases the default $countPerPage from 50 to 500 in SamedayRequestPaginationTrait. This ensures all cities in a county are returned in a single API call, which is important for countries like Hungary where some counties have more than 50 cities.

Tests

  1. Composer is a prerequisite for running the tests. Install composer globally, then run composer install to install required files.
  2. The tests can be executed by running this command from the root directory:
$ ./vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

License

Please see the license file for more information.

altwebdesign/sameday-php-sdk 适用场景与选型建议

altwebdesign/sameday-php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 altwebdesign/sameday-php-sdk 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-03