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

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
1번째 줄: 1번째 줄:
==개요==
==개요==
;PHP ucloud biz API 호출
;PHP ucloud biz API 호출
<source 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';
$endpoint = 'https://api.ucloudbiz.olleh.com/server/v2/client/api';
29번째 줄: 29번째 줄:
return json_decode(file_get_contents($url), true);
return json_decode(file_get_contents($url), true);
}
}
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2020년 11월 2일 (월) 02:35 판

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