PHP code example of ecomphp / shopee-php

1. Go to this page and download the library: Download ecomphp/shopee-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ecomphp / shopee-php example snippets


use EcomPHP\Shopee\Client;

$partner_id = 'your_partner_id_here';
$partner_key = 'your_partner_key_here';

$client = new Client($partner_id, $partner_key);

$auth = $client->auth();

$redirect_uri = 'http://your-redirect-url.com';

// Returns the Shopee authentication URL instead of auto-redirecting
$authUrl = $auth->createAuthRequest($redirect_uri, true);

// Redirect user to Shopee Authorization page
header('Location: ' . $authUrl);
exit;

$authorization_code = $_GET['code'];
$shop_id = $_GET['shop_id'];

// Exchange code for Access Token & Refresh Token
$token = $auth->getToken($authorization_code, $shop_id);

$access_token = $token['access_token'];
$refresh_token = $token['refresh_token'];

// IMPORTANT: Save your access_token, refresh_token & shop_id to your database for later use

$access_token = 'your_stored_access_token';
$shop_id = 'your_stored_shop_id';

$client->setAccessToken($shop_id, $access_token);

$new_token = $auth->refreshNewToken($refresh_token, $shop_id);

$new_access_token = $new_token['access_token'];
$new_refresh_token = $new_token['refresh_token'];

$products = $client->Product->getItemList([
    'offset' => 0,
    'page_size' => 50,
    'item_status' => 'NORMAL',
]);

$orders = $client->Order->getOrderList([
    'order_status' => 'READY_TO_SHIP',
    'page_size' => 50,
]);
shell
composer