Update coupang.api.php

This commit is contained in:
Namhyeon Go 2021-05-22 06:00:14 +09:00 committed by GitHub
parent 4fef129951
commit 1a5a22eb88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,13 +1,14 @@
<?php
// Coupang Products Search API
// https://coupa.ng/bZ3Kba
// https://developers.coupangcorp.com/hc/ko/articles/360033461914-HMAC-Signature-%EC%83%9D%EC%84%B1
loadHelper("webpagetool");
if(!is_fn("coupang_get_signature")) {
function coupang_get_signature($method = "GET", $path, $ACCESS_KEY, $SECRET_KEY) {
function coupang_get_signature($method, $path, $query, $ACCESS_KEY, $SECRET_KEY) {
$datetime = date("ymd") . 'T' . date("His") . 'Z';
$message = $datetime . $method . str_replace("?", "", $path);
$message = $datetime . strtoupper($method) . str_replace("?", "", $path) . http_build_query($query);
$algorithm = "HmacSHA256";
$signature = hmacsha256_sign_message($message, $SECRET_KEY);
@ -20,17 +21,21 @@ if(!is_fn("coupang_search_items")) {
$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];
$method = "get";
$path = $URL_PARTS[1] . $URL_PARTS[2];
$query = array(
"keyword" => $keyword,
"limit" => 20, // default is 20
//"subId" => "" // default is null
);
return get_web_json($BASE_URL . $URL_PARTS[2], "get", array(
$response = get_web_page($BASE_URL . $URL_PARTS[2], $method, array(
"headers" => array(
"Authorization" => coupang_get_signature("GET", $path, $ACCESS_KEY, $SECRET_KEY)
)
"data" => array(
"keyword" => $keyword,
//"limit" => 20, // default is 20
//"subId" => "" // default is null
)
"Authorization" => coupang_get_signature($method, $path, $query, $ACCESS_KEY, $SECRET_KEY)
),
"data" => $query
));
var_dump($response);
}
}