PHP code example of jekka / shopee-php

1. Go to this page and download the library: Download jekka/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/ */

    

jekka / shopee-php example snippets


use EcomPHP\Shopee\Client;

$partner_id = 'your partner id';
$partner_key = 'your partner key';

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

$auth = $client->auth();

$redirect_uri = 'http://your-redirect-url.com';
$auth->createAuthRequest($redirect_uri);

$authUrl = $auth->createAuthRequest($redirect_uri, true);

// redirect user to auth url
header('Location: '.$authUrl);

$authorization_code = $_GET['code'];
$shop_id = $_GET['shop_id'];
$token = $auth->getToken($authorization_code, $shop_id);

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

// save your access_token & refresh_token & shop_id for later use

$access_token = 'your access token';
$shop_id = 'your 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'];

$client = new Client($partner_id, $partner_key);
$client->setAccessToken($shop_id, $access_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