"PHP ucloud biz API 호출"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
잔글 (→‎개요)
 
2번째 줄: 2번째 줄:
;PHP ucloud biz API 호출
;PHP ucloud biz API 호출
<syntaxhighlight lang='php'>
<syntaxhighlight lang='php'>
function call_ucloud_biz_api($args) {
function call_ucloud_biz_api($args)
$endpoint = 'https://api.ucloudbiz.olleh.com/server/v2/client/api';
{
$apikey = '';
    $endpoint = 'https://api.ucloudbiz.olleh.com/server/v2/client/api';
$secret = '';
    $apikey = '';
    $secret = '';
$args['apikey'] = $apikey;
$args['response'] = 'json';


$params = [];
    $args['apikey'] = $apikey;
$keys = array_keys( $args );
    $args['response'] = 'json';
sort( $keys );
 
    $params = [];
foreach( $keys as $k ) $params[] = $k . '=' . rawurlencode( $args[$k] );
    $keys = array_keys($args);
$query = implode( '&', $params );
    sort($keys);
 
$signature = rawurlencode( base64_encode( hash_hmac( 'sha1', strtolower($query), $secret, true ) ) );
    foreach ($keys as $k) $params[] = $k . '=' . rawurlencode($args[$k]);
$query .= "&signature=$signature";
    $query = implode('&', $params);
$url = $endpoint . '?' . $query;
 
    $signature = rawurlencode(base64_encode(hash_hmac('sha1', strtolower($query), $secret, true)));
if ( !filter_var($url, FILTER_VALIDATE_URL) ) {
    $query .= "&signature={$signature}";
return false;
    $url = $endpoint . '?' . $query;
}
 
//return $url;
    if (!filter_var($url, FILTER_VALIDATE_URL)) {
//return file_get_contents($url);
        return false;
//return json_decode(shell_exec("curl --globoff '$url'"), true);
    }
return json_decode(file_get_contents($url), true);
    //return $url;
    //return file_get_contents($url);
    //return json_decode(shell_exec("curl --globoff '$url'"), true);
    return json_decode(file_get_contents($url), true);
}
}
</syntaxhighlight>
</syntaxhighlight>

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 }}