reasonableframework/helper/coupang.api.php

37 lines
1.4 KiB
PHP
Raw Normal View History

2021-05-21 20:28:08 +00:00
<?php
2021-05-21 20:29:23 +00:00
// Coupang Products Search API
2021-05-21 20:31:12 +00:00
// https://coupa.ng/bZ3Kba
2021-05-21 20:29:23 +00:00
2021-05-21 20:28:08 +00:00
loadHelper("webpagetool");
if(!is_fn("coupang_get_signature")) {
function coupang_get_signature($method = "GET", $path, $ACCESS_KEY, $SECRET_KEY) {
$datetime = date("ymd") . 'T' . date("His") . 'Z';
$message = $datetime . $method . str_replace("?", "", $path);
$algorithm = "HmacSHA256";
$signature = hmacsha256_sign_message($message, $SECRET_KEY);
2021-05-21 20:31:40 +00:00
return "CEA algorithm=HmacSHA256, access-key=" . $ACCESS_KEY . ", signed-date=" . $datetime . ", signature=" . $signature;
2021-05-21 20:28:08 +00:00
}
}
if(!is_fn("coupang_search_items")) {
function coupang_search_items($keyword, $ACCESS_KEY, $SECRET_KEY) {
$URL_PARTS = array("https://api-gateway.coupang.com", "/v2/providers/affiliate_open_api/apis/openapi/v1", "/products/search");
$BASE_URL = $URL_PARTS[0] . '/' . $URL_PARTS[1];
2021-05-21 20:30:39 +00:00
2021-05-21 20:28:08 +00:00
$path = $URL_PARTS[1] . '/' . $URL_PARTS[2];
return get_web_json($BASE_URL . "/products/search". "get", array(
"headers" => array(
"Authorization" => coupang_get_signature("GET", $path, $ACCESS_KEY, $SECRET_KEY),
"data" => array(
"keyword" => $keyword,
2021-05-21 20:29:55 +00:00
//"limit" => 20, // default is 20
//"subId" => "" // default is null
2021-05-21 20:28:08 +00:00
)
)
));
}
}