2014-01-06 5 views
1

블리자드의 API를 사용하여 JSON 서비스 (인증 문서 - http://blizzard.github.io/api-wow-docs/#features/authentication)에서 데이터를 검색하려고합니다. 현재 내 cURL 요청을 처리하는 다음 기능을 가지고 있습니다.PHP에서 cURL 요청 인증

function get_json($url) { 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    $data = curl_exec($ch); 
    curl_close($ch); 
    return $data; 
} 

나는 인증 요구 사항을 조사하고 공개 및 개인 키를 획득했습니다. 그들은이 과정을 설명하기 위해 제공 :

UrlPath = <HTTP-Request-URI, from the port to the query string> 
    StringToSign = HTTP-Verb + "\n" + Date + "\n" + UrlPath + "\n"; 
    Signature = Base64(HMAC-SHA1(UTF-8-Encoding-Of(PrivateKey), StringToSign)); 
    Header = "Authorization: BNET" + " " + PublicKey + ":" + Signature; 

나는 컬 인증을 처리하는 PHP 연구를 시도했지만 그냥 나를 더 혼란. 내 질문은 get_json 함수에 인증을 포함시키는 방법이다.

+0

에서 사람에 의해이 코드 발견 - 그것은에 맞는 곳을 작업을 시도하고 curl_setopt ($ ch를, CURLOPT_HTTPHEADER, "인증 : 기본".. base64_encode을 ($ username. ":". $ password))); – SystemX17

답변

2

내가 이걸 발견 http://sourceforge.net/projects/wowarmoryapi/

private function getByKeys($url,$region){ 
    $pubkey = $GLOBALS['wowarmory']['keys']['public']; 
    $privkey = $GLOBALS['wowarmory']['keys']['private']; 
    $url = preg_replace('/^http/', 'https', $url); 
    $date = date('D, d M Y G:i:s T',time()); 
    $stringtosign = "GET\n".$date."\n".$url."\n"; 
    $signature = base64_encode(hash_hmac('sha1', $stringtosign, $privkey,true)); 
    $header = array("Host: ".$this->regions[$region],"Date: ". $date,"\nAuthorization: BNET ". $pubkey.":". base64_encode(hash_hmac('sha1', "GET\n".$date."\n".$url."\n", $privkey, true))."\n"); 

    $ch = curl_init($url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
    curl_setopt($ch, CURLOPT_VERBOSE, true); 

    curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
    $response = curl_exec($ch); 
    $headers = curl_getinfo($ch); 
    return $response; 
}