55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?
|
|
|
|
namespace integration;
|
|
|
|
class PhotonCMS {
|
|
protected $api_url;
|
|
protected $login;
|
|
protected $password;
|
|
|
|
public function __construct($full_api_url,$login,$password) {
|
|
$this->api_url = $full_api_url;
|
|
$this->login = $login;
|
|
$this->password = $password;
|
|
}
|
|
|
|
function login(){
|
|
$r = $this->request('auth/login',[
|
|
'email'=>$this->login,
|
|
'password'=>$this->password,
|
|
],'POST');
|
|
}
|
|
|
|
function menus(){
|
|
$r = $this->request('menus');
|
|
}
|
|
|
|
|
|
public function request($url,$data = [],$type = 'GET'){
|
|
$res = null;
|
|
$url = $this->api_url.$url;
|
|
$isPost = $type=='POST';
|
|
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_HEADER,array(
|
|
'Content-type: application/json',
|
|
'Authorization: Basic '.base64_encode($this->login.':'.$this->password),
|
|
));
|
|
if($isPost){
|
|
curl_setopt($curl, CURLOPT_POST,0);
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS,http_build_query($data));
|
|
}
|
|
$out = curl_exec($curl);
|
|
echo h($out);
|
|
curl_close($curl);
|
|
$res = json_decode($out);
|
|
}
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
} |