PHP ucloud biz API 호출

항생물질 (토론 | 기여)님의 2022년 4월 2일 (토) 09:48 판 (→‎개요)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

PHP ucloud biz API 호출
function call_ucloud_biz_api($args)
{
    $endpoint = 'https://api.ucloudbiz.olleh.com/server/v2/client/api';
    $apikey = '';
    $secret = '';

    $args['apikey'] = $apikey;
    $args['response'] = 'json';

    $params = [];
    $keys = array_keys($args);
    sort($keys);

    foreach ($keys as $k) $params[] = $k . '=' . rawurlencode($args[$k]);
    $query = implode('&', $params);

    $signature = rawurlencode(base64_encode(hash_hmac('sha1', strtolower($query), $secret, true)));
    $query .= "&signature={$signature}";
    $url = $endpoint . '?' . $query;

    if (!filter_var($url, FILTER_VALIDATE_URL)) {
        return false;
    }
    //return $url;
    //return file_get_contents($url);
    //return json_decode(shell_exec("curl --globoff '$url'"), true);
    return json_decode(file_get_contents($url), true);
}

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}