Test API

[insert_php] $token = ’76CV3gAGZNqDLDHaowd69t6fFTag849t’;
$url = ‘https://api.accesstrade.vn/v1/top_products’;
$opts = array (
‘http’ => array (
‘method’ => ‘GET’,
‘header’ => “Content-Type: application/json\r\n” . “Authorization: Token ” . $token . “\r\n”
)
);

$context = stream_context_create ( $opts );
$result = json_decode ( file_get_contents ( $url, false, $context ), true );

$total = $result [‘total’];
if ($total > 0) {
$data = $result [‘data’];
echo ‘ Tổng số có ‘ . $total . ‘ khuyến mãi ‘;
for ($i = 0; $i < $total; $i++) { $value = $data [$i]; $name = $value ['name']; $short_desc = $value ['short_desc']; $aff_link = $value ['aff_link']; $price = $value ['price']; $discount = $value ['discount']; $brand = $value ['brand']; $category_name = $value ['category_name']; $desc = $value ['desc']; $image = $value ['image']; $link = $value ['link']; echo '

‘;
echo ‘

‘;
echo ‘

‘;
echo ‘

‘;
echo ‘

‘;
echo ‘

‘;
echo ‘

‘;
echo ‘

‘;
echo ‘‘ . ($i + 1) . ‘. ‘ . $name . ‘‘;
echo ‘
‘;
echo ‘‘ . $short_desc . ‘‘;
echo ‘

Thương hiệu : ‘ . $brand . ‘

‘;
echo ‘

Nhóm hàng : ‘ . $category_name . ‘

‘;
echo ‘

Giá gốc : ‘ . $price . ‘ đ

‘;
echo ‘

Giảm giá : ‘ . $discount . ‘ đ

‘;
echo ‘

' . $name . '

‘;
echo ‘

‘ . $desc . ‘

‘;
echo ‘

Xem Thông Tin Chi Tiết

‘;
echo ‘

‘;
echo ‘
‘;
}
} else {
echo ‘Không có khuyên mãi’;
}
[/insert_php]