-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetshop_example.php
More file actions
72 lines (59 loc) · 2.09 KB
/
getshop_example.php
File metadata and controls
72 lines (59 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
// shopee_get_shopinfo.php
require_once 'shopeeAPI.php';
// Configuration
$config = array(
'partner_id' => 'partner_id',
'secret_key' => 'secret_key',
'shop_id' => 'shop_id',
'is_sandbox' => false
);
// Your access token obtained from authorization flow
$accessToken = 'your_access_token_here';
try {
// Initialize client
$shopee = new ShopeeApiClient($config, $accessToken, false);
// Optionally update timestamp (auto-updated in request)
$shopee->updateTimestamp();
// Get shop information
$shopInfo = $shopee->getShopInfo();
// Check if response is valid
if (isset($shopInfo['error'])) {
throw new Exception("API Error: " . $shopInfo['message']);
}
// Display shop information
echo "<h1>Shop Information</h1>";
echo "<table border='1'>";
echo "<tr><th>Field</th><th>Value</th></tr>";
$fieldsToShow = array(
'shop_name',
'region',
'status',
'auth_time',
'expire_time',
'shop_logo'
);
foreach ($fieldsToShow as $field) {
if (isset($shopInfo[$field])) {
$value = is_array($shopInfo[$field]) ?
json_encode($shopInfo[$field]) :
htmlspecialchars($shopInfo[$field]);
echo "<tr><td>{$field}</td><td>{$value}</td></tr>";
}
}
echo "</table>";
// Show raw response for debugging
echo "<h2>Raw Response</h2>";
echo "<pre>" . htmlspecialchars(json_encode($shopInfo, JSON_PRETTY_PRINT)) . "</pre>";
} catch (Exception $e) {
echo "<h2>Error</h2>";
echo "<p style='color:red'>" . htmlspecialchars($e->getMessage()) . "</p>";
// Handle specific error cases
if (strpos($e->getMessage(), 'access_token') !== false) {
echo "<p>Your access token may be expired. Please re-authenticate.</p>";
// Generate new auth URL
$authUrl = (new ShopeeApiClient($config))->getAuthUrl('https://yourdomain.com/shopee_callback.php');
echo "<a href='".htmlspecialchars($authUrl)."'>Re-authorize with Shopee</a>";
}
}
?>