<?php class Api
{
public $api_url = "APİ URL";
public $api_key = "APİ KEY";
public function order($data) { // yeni sipariş
$post = array_merge(array('key' => $this->api_key, 'action' => 'add'), $data);
return json_decode($this->connect($post));
}
public function status($order_id) { // sipariş durumu
return json_decode($this->connect(array(
'key' => $this->api_key,
'action' => 'status',
'order' => $order_id
)));
}
public function services() { // servis listesi
return json_decode($this->connect(array(
'key' => $this->api_key,
'action' => 'services'
)));
}
public function balance() { // bakiye sorgulama
return json_decode($this->connect(array(
'key' => $this->api_key,
'action' => 'balance'
)));
}
private function connect($post) {
$_post = Array();
if (is_array($post)) {
foreach ($post as $name => $value) {
$_post[] = $name.'='.urlencode($value);
}
}
$ch = curl_init($this->api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
if (is_array($post)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, join('&', $_post));
}
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
$result = curl_exec($ch);
if (curl_errno($ch) != 0 && empty($result)) {
$result = false;
}
curl_close($ch);
return $result;
}
}
// Örnekler
$api = new Api();
$services = $api->services(); # Servis Listesi
$balance = $api->balance(); # Bakiye Sorgulama
// Yeni Sipariş
$order = $api->order(array('service' => $ayarcek["api_numara"], 'link' => $_POST["url"], 'quantity' => $_POST["adet"]));
?> Php Ufak Bir Yardım Lazım
3
●109
- 19-04-2020, 16:50:31Öncelikle sınıfınız içinde construct method tanımlayın. 2 adet parametre alsın (api_url, api_key). Bu method içinde $this->api_url ve $this->api_key yazarak sınıf içindeki değişkenlere method'un aldığı parametre değerlerini eşitleyin. Daha sonra sınıfınızı çağırırken
$api = new Api($ayarcek['api_url'],$ayarcek['api_key']);
Şeklinde çağırdığınız zaman database'den gelen api_url ve api_key değerlerini sınıf içinde kolaylıkla kullanmış olursunuz. Kolay gelsin ^^ - 19-04-2020, 17:13:38Hocam anlattıklarınızı denedim ama dahaca yeni olduğum için pek anlamadımalperhan adlı üyeden alıntı: mesajı görüntüle
- 19-04-2020, 17:16:24PM ile numaranızı atarsanız yardımcı olurum.Luwexigo adlı üyeden alıntı: mesajı görüntüle