承接 laraditz/shopee 相关项目开发

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

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

laraditz/shopee

Composer 安装命令:

composer require laraditz/shopee

包简介

A simple laravel package for Shopee

README 文档

README

Latest Version on Packagist Total Downloads License GitHub Tests Action Status

A comprehensive Laravel package for seamlessly integrating with the Shopee Open Platform API. This package provides an elegant, fluent interface for managing shops, products, orders, and payments on Shopee's marketplace.

Buy Me A Coffee

Installation

You can install the package via composer:

composer require laraditz/shopee

Before Starting

Configure your Shopee API credentials in your .env file (recommended) or publish and modify the config file.

SHOPEE_SANDBOX_MODE=true # Set to false for production
SHOPEE_PARTNER_ID=<your_shopee_partner_id>
SHOPEE_PARTNER_KEY=<your_shopee_partner_key>
SHOPEE_SHOP_ID=<your_shopee_shop_id>
SHOPEE_REDIRECT_URL=<your_redirect_url> # Optional — see Authorization Flow

(Optional) You can publish the config file via this command:

php artisan vendor:publish --provider="Laraditz\Shopee\ShopeeServiceProvider" --tag="config"

Publish and run the migrations to create the necessary database tables for storing shop data, access tokens, and API request logs.

php artisan vendor:publish --provider="Laraditz\Shopee\ShopeeServiceProvider" --tag="migrations"
php artisan migrate

Authorization Flow

To authorize a Shopee shop with your app:

  1. Visit Shopee Open Platform Console.
  2. On your App List, click Authorize link next to the Test/Live Partner_id. Alternatively, you can generate the authorization URL using the generateAuthorizationURL() method.
  3. Make sure the domain for authorized redirect URL already been whitelisted beforehand.
  4. Enter https://your-app-url/shopee/shops/authorized as the Redirect URL and click Next.
  5. Proceed to login using the seller account that you want to authorized to be use for the app.
  6. Shopee redirects back to https://your-app-url/shopee/shops/authorized.
  7. Package automatically handles the authorization code exchange and token storage.
  8. Shop is now ready for API calls.

Custom Redirect After Authorization

By default, the package renders a built-in success page after authorization. To redirect to your own URL instead, set SHOPEE_REDIRECT_URL in your .env:

SHOPEE_REDIRECT_URL=https://your-app-url/shopee/callback

On success, the package redirects to your URL with the following query parameters:

Parameter Description
shop_id Shopee shop ID
shop_name Shop display name
region Shop region (e.g. MY, SG)
access_token OAuth access token
refresh_token OAuth refresh token
expires_at Token expiry (ISO 8601)

On failure (e.g. token exchange error), the redirect includes:

Parameter Value
error token_failed
shop_id Shopee shop ID

Security: SHOPEE_REDIRECT_URL must be an exact absolute URL without query strings. Only requests carrying this exact value are honoured — any other value is silently discarded, preventing open redirect attacks. Use HTTPS in production as tokens are passed in the URL.

Available Services & Methods

Below is a list of all available methods in this SDK. For detailed usage, please refer to the Developer’s Guide and the API Reference. This package organizes Shopee API endpoints into logical services. Each method name corresponds to its respective API endpoint (converted from snake_casecamelCase), and all parameters follow the exact definitions provided in the API reference.

Note: All method parameters must be passed as named arguments, not positional arguments.

🔐 Authorization and Authentication Service auth()

Handles OAuth 2.0 authentication flow and token management.

Method Description Parameters
accessToken() Generate access token from authorization code entity_id, EntityType entity_type
refreshToken() Refresh access token before expiration (4 hours) ShopeeAccessToken shopeeAccessToken

🏪 Shop Service shop()

Manages shop information and authorization processes.

Method Description
generateAuthorizationURL() Generate authorization URL for shop authorization
getShopInfo() Retrieve comprehensive shop information and status

📦 Product Service product()

Comprehensive product and inventory management capabilities.

Method Description Parameters
getItemList() Retrieve paginated list of shop items with filters offset, page_size, item_status, update_time_from, update_time_to
getItemBaseInfo() Get basic product information including pricing and status item_id_list, need_tax_info, need_complaint_policy
getItemExtraInfo() Get extended product details like dimensions and attributes item_id_list
getModelList() Retrieve all variants/models for a specific product item_id
searchItem() Search products by name, SKU, or status with pagination item_name, item_sku, item_status, offset, page_size and more
updateStock() Update inventory levels for product variants in bulk item_id, stock_list
addItem() Create a new product listing on Shopee Refer to Shopee API Reference
updateItem() Update an existing product listing item_id and any fields to update - refer to Shopee API Reference
deleteItem() Delete a product listing item_id

🛒 Order Service order()

Handles order management and retrieval with detailed tracking information.

Method Description Parameters
getOrderList() Retrieve paginated orders within specified date range time_range_field, time_from, time_to, page_size, cursor and more
getOrderDetail() Get comprehensive order details by order serial number order_sn_list, request_order_status_pending, response_optional_fields

💰 Payment Service payment()

Manages payment and financial transaction details.

Method Description Parameters
getEscrowDetail() Retrieve detailed escrow and payment information for orders order_sn

Usage Examples

The package provides a fluent, chainable API interface. Access services by chaining the service name before calling the method.

Basic Usage

use Laraditz\Shopee\Facades\Shopee;

// Get order details
$orderDetails = Shopee::order()->getOrderDetail(
    order_sn_list: '211020BNFYMXXX,211020BNFYXXX2'
);

// Get shop information
$shopInfo = Shopee::shop()->getShopInfo();

// Search products
$products = Shopee::product()->searchItem(
    item_name: 'smartphone',
    page_size: 20,
    offset: 0
);

// Add a new product
$newProduct = Shopee::product()->addItem(
    item_name: 'My Product',
    description: 'Product description',
    original_price: 29.90,
    normal_stock: 100,
    weight: 0.5,
    item_sku: 'SKU-001',
    category_id: 100001,
    // ... refer to Shopee API Reference for full parameter list
);

// Update an existing product
Shopee::product()->updateItem(
    item_id: 123456789,
    item_name: 'Updated Product Name',
    original_price: 24.90,
);

// Delete a product
Shopee::product()->deleteItem(item_id: 123456789);

// Alternative: using service container
$orders = app('shopee')->order()->getOrderList(
    time_range_field: 'create_time',
    time_from: strtotime('-30 days'),
    time_to: time(),
    page_size: 50
);

Multi-Shop Support

By default, the package uses SHOPEE_SHOP_ID from your .env file. For multi-shop applications, specify the shop ID per request:

use Laraditz\Shopee\Facades\Shopee;

// Method 1: Using make() with shop_id
$products = Shopee::make(shop_id: '2257XXXXX')
    ->product()
    ->getItemList(
        offset: 0,
        page_size: 10,
        item_status: 'NORMAL'
    );

// Method 2: Using shopId() method
$orders = Shopee::shopId('2257XXXXX')
    ->order()
    ->getOrderList(
        time_range_field: 'create_time',
        time_from: strtotime('-7 days'),
        time_to: time()
    );

Error Handling

use Laraditz\Shopee\Facades\Shopee;
use Illuminate\Http\Client\RequestException;

try {
    $result = Shopee::product()->updateStock(
        item_id: 123456789,
        stock_list: [
            [
                'model_id' => 123123123,
                'seller_stock' => [
                    [
                        'location_id' => 'MYZ',
                        'stock' => 100,
                    ]
                ],
            ]
        ]
    );
} catch (RequestException $e) {
    // Handle HTTP/network errors
    logger()->error('Request failed: ' . $e->getMessage());
}

Webhook Integration

This package provides comprehensive webhook support for real-time notifications from Shopee. Refer to Push Mecahnism documentation for more details.

Event Handling

Create listeners for webhook events to automatically process updates from Shopee:

Event Description
Laraditz\Shopee\Events\WebhookReceived Triggered when receiving push notifications from Shopee

Setting Up Webhooks

Configure Webhook URL: In your Shopee Open Platform dashboard, set the webhook URL to:

https://your-app-url/shopee/webhooks

Create Event Listeners to Handle Webhook Data: Create a listener to process incoming data:

<?php

namespace App\Listeners;

use Laraditz\Shopee\Events\WebhookReceived;

class YourWebhookListener
{
    public function handle(WebhookReceived $event)
    {
        $webhookData = $event->data;

        // Process order updates, product changes, etc.
        if ($webhookData['event'] === 'order_status_update') {
            // Handle order status changes
        }
    }
}

Register Event Listeners: Register listeners in your EventServiceProvider (Laravel 10 and below):

use Laraditz\Shopee\Events\WebhookReceived;

protected $listen = [
    WebhookReceived::class => [
        YourWebhookListener::class,
    ],
];

Artisan Commands

The package provides convenient Artisan commands for token management:

# Remove expired access tokens from database
php artisan shopee:flush-expired-token

# Refresh existing access tokens before expiration
php artisan shopee:refresh-token

Automated Token Refresh

Since Shopee access tokens expire every 4 hours, it's recommended to schedule the refresh command to run automatically. Add this to your app/Console/Kernel.php:

protected function schedule(Schedule $schedule)
{
    // Refresh tokens every 3 hours to prevent expiration
    $schedule->command('shopee:refresh-token')
             ->everyThreeHours()
             ->withoutOverlapping();

    // Clean up expired tokens daily
    $schedule->command('shopee:flush-expired-token')
             ->daily();
}

Important: Without automatic refresh, expired tokens will require shop reauthorization and manual token generation.

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

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

Credits

License

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

laraditz/shopee 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-10-27