carllee1983/newebpay-logistics 问题修复 & 功能扩展

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

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

carllee1983/newebpay-logistics

Composer 安装命令:

composer require carllee1983/newebpay-logistics

包简介

NewebPay Logistics Integration PHP SDK. Supports various logistics methods including CVS pickup, home delivery, and more.

README 文档

README

繁體中文 | English

Latest Version on Packagist Run Tests Software License PHP Version

A PHP SDK for integrating with the NewebPay Logistics API (藍新金流物流 API). This package simplifies the process of creating transactions, selecting stores (CVS), querying orders, and printing shipping labels.

Features

  • Easy Integration: Simple and intuitive API for common logistics operations.
  • Framework Agnostic: Works with any PHP project (bundled with Laravel support).
  • Type Safety: Utilizes PHP encapsulation to ensure data validity.
  • Frontend Friendly: Built-in support for generating HTML forms for frontend frameworks (Vue, React, etc.).

Requirements

  • PHP ^8.1
  • ext-json extension
  • ext-openssl extension

Installation

Install via Composer:

composer require carllee1983/newebpay-logistics

Configuration

Initialize the library with your NewebPay Logistics credentials.

use CarlLee\NewebPayLogistics\NewebPayLogistics;

$merchantId = 'YOUR_MERCHANT_ID';
$hashKey = 'YOUR_HASH_KEY';
$hashIV = 'YOUR_HASH_IV';

// The last argument is optional for server URL override (defaults to testing env)
$logistics = NewebPayLogistics::create($merchantId, $hashKey, $hashIV);

Parameters

Parameter Application Description
$merchantId Required Your Shop ID (商店代號) provided by NewebPay.
$hashKey Required Hash Key (HashKey) for encryption.
$hashIV Required Hash IV (HashIV) for encryption.
$serverUrl Optional API Base URL. Default is testing env: https://ccore.newebpay.com/API/Logistic.

Laravel Integration

This package includes a Service Provider and Facade for seamless Laravel integration.

1. Installation

Publish the configuration file:

php artisan vendor:publish --tag=newebpay-logistics-config

2. Configuration

Add the following variables to your .env file:

NEWEBPAY_LOGISTICS_MERCHANT_ID=your_merchant_id
NEWEBPAY_LOGISTICS_HASH_KEY=your_hash_key
NEWEBPAY_LOGISTICS_HASH_IV=your_hash_iv
# Optional: Override server URL (default is testing environment)
# NEWEBPAY_LOGISTICS_SERVER_URL=https://core.newebpay.com/API/Logistic

3. Usage via Facade

You can use the NewebPayLogistics facade anywhere in your Laravel application.

use NewebPayLogistics;
use CarlLee\NewebPayLogistics\Parameter\ShipType;

public function map()
{
    $map = NewebPayLogistics::map();
    $map->setShipType(ShipType::SEVEN_ELEVEN);
    // ...
    
    return NewebPayLogistics::generateForm($map);
}

Usage

1. Map Interface (電子地圖)

Redirect the user to the logistics provider's map interface to select a store (7-11, FamilyMart, etc.).

use CarlLee\NewebPayLogistics\Parameter\LgsType;
use CarlLee\NewebPayLogistics\Parameter\ShipType;

$map = $logistics->map();
$map->setMerchantTradeNo('TRADE' . time());
$map->setLgsType(LgsType::B2C);
$map->setShipType(ShipType::SEVEN_ELEVEN);
$map->setIsCollection('N'); // N: No collection, Y: Collection
$map->setServerReplyURL('https://example.com/reply');

// Generate auto-submit HTML form
echo $logistics->generateForm($map);

1-1. Frontend Integration (Vue/React)

If you are using a decoupled architecture, return the form data as JSON.

$formBuilder = $logistics->getFormBuilder();
$data = $formBuilder->getFormData($map);

echo json_encode($data);
// Output: {"url": "...", "method": "post", "params": { ... }}

2. Create Order (建立物流訂單)

Create a logistics order for B2C or C2C transactions.

use CarlLee\NewebPayLogistics\Parameter\LgsType;
use CarlLee\NewebPayLogistics\Parameter\ShipType;
use CarlLee\NewebPayLogistics\Parameter\TradeType;

$create = $logistics->createOrder();
$create->setMerchantTradeNo('TRADE' . time());
$create->setLgsType(LgsType::B2C);
$create->setShipType(ShipType::SEVEN_ELEVEN);
$create->setTradeType(TradeType::PAYMENT);
$create->setReceiverName('John Doe');
$create->setReceiverCellPhone('0912345678');
// ... more parameters

// This API usually responds with a redirect or direct result depending on the content
// But strictly speaking, Create Order in some NewebPay flows is also a form post redirect.
// Check official docs for specific flow.

3. Query Order (查詢物流訂單)

Query the status of an existing order.

$query = $logistics->query();
$query->setLogisticsID('LOGISTICS_ID');
$query->setMerchantTradeNo('TRADE_NO');

// This is a direct API call
$response = $logistics->send($query);

if ($response->isSuccess()) {
    echo "Status: " . $response->getMessage();
}

Examples

Check the examples/ directory for complete vanilla PHP scripts:

API Reference

For detailed API documentation, please refer to the files in the doc/ directory:

FAQ

Q: How do I change the environment to Production? A: By default, NewebPayLogistics::create() uses the testing URL. Pass the production URL as the 4th argument, or set NEWEBPAY_LOGISTICS_SERVER_URL in Laravel .env.

Q: Can I use this without Laravel? A: Yes! The package is framework-agnostic. See the Configuration section.

Q: I get a "Validation Validation" error. A: Ensure all required fields are set. The SDK validates the request parameters before generating the payload.

Q: I get a "Check Value Error" or Decryption failure. A: This usually means your Merchant ID, Hash Key, or Hash IV are incorrect. Please double check them. Also ensure there are no extra spaces in your keys. In some cases, ensure your input data doesn't contain encoded characters that might mess up the length calculation.

Development

# Run tests
composer test

# Check code style
composer check

# Fix code style
composer format

Contributing

Please see CONTRIBUTING.md for details.

Security

If you discover any security related issues, please email carllee1983@gmail.com instead of using the issue tracker.

License

MIT

carllee1983/newebpay-logistics 适用场景与选型建议

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

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

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

围绕 carllee1983/newebpay-logistics 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-28