41 lines
1.3 KiB
PHP
41 lines
1.3 KiB
PHP
<?
|
|
|
|
namespace integration;
|
|
|
|
class Yandex{
|
|
|
|
static function urlOAuth($app_id,$type='code',$options = []){
|
|
return 'https://oauth.yandex.ru/authorize?response_type='.$type.'&client_id='.$app_id;
|
|
}
|
|
static function getTokenByCode($code,$app_id,$app_secret,$options = []){
|
|
$res = null;
|
|
$url = 'https://oauth.yandex.ru/token';
|
|
$data = [
|
|
'grant_type' =>'authorization_code',
|
|
'code' =>$code,
|
|
'client_id' =>$app_id,
|
|
'client_secret' =>$app_secret,
|
|
];
|
|
|
|
if ($curl = curl_init()){
|
|
curl_setopt($curl, CURLOPT_URL, $url);
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
|
|
curl_setopt($curl, CURLOPT_POST,1);
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS,http_build_query($data));
|
|
/*
|
|
curl_setopt($curl, CURLOPT_HEADER,array(
|
|
'Content-type: application/x-www-form-urlencoded',
|
|
'Authorization: Basic '.base64_encode($app_id.':'.$app_secret),
|
|
));
|
|
/**/
|
|
$out = curl_exec($curl);
|
|
curl_close($curl);
|
|
$res = json_decode($out,true);
|
|
}
|
|
|
|
return $res;
|
|
}
|
|
|
|
|
|
} |