Curl kodları ;


class Api
{
public $api_url = ''; // API URL
public $api_key = ''; // Your API key

public function order($data) { // add order
$post = array_merge(array('key' => $this->api_key, 'action' => 'add'), $data);
return json_decode($this->connect($post));
}

public function status($order_id) { // get order status
return json_decode($this->connect(array(
'key' => $this->api_key,
'action' => 'status',
'order' => $order_id
)));
}

public function multiStatus($order_ids) { // get order status
return json_decode($this->connect(array(
'key' => $this->api_key,
'action' => 'status',
'orders' => implode(",", (array)$order_ids)
)));
}

public function services() { // get services
return json_decode($this->connect(array(
'key' => $this->api_key,
'action' => 'services',
)));
}

public function balance() { // get balance
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;
}
}



Bu Api class'ını kullanarak diğer sitelere post gönderiyorsunuz. Sitenin belli API adresleri oluyor. Sipariş için order fonksiyonu, durum sorgulama için status fonksiyonu vs kullanılıyor. Smm apilerinin %95'i bu api tarzında kodlanmış şekilde.
Yukarıda siz başka siteye curl ile sipariş verebildiğiniz gibi sizinde bir api yolu belirleyim curl ile gelen veriler ile sipariş alabilmeniz lazım..




header('Content-Type: application/json');
include "api.php";
require_once '../sys/BasicDB.php';
require_once '../sys/function.php';

@@$apiKey = addslashes(strip_tags($_POST['key']));
@@$ApiYontemi = addslashes(strip_tags($_POST['action']));
@@$servisId = addslashes(strip_tags($_POST['service']));
@@$siparisUrl = addslashes(strip_tags($_POST['link']));
@@$yayinciId = addslashes(strip_tags($_POST['yayinci']));
@@$miktar = (intval($_POST['quantity']) > 0) ? addslashes(intval($_POST['quantity'])) : 0;
@@$siparisId = (intval($_POST['order']) > 0) ? addslashes(intval($_POST['order'])) : 0;

$json['error'] = 'yanlis yontem adi';

if ( $ApiYontemi == 'add' ) # Sipariş Ekleme
{
$kullaniciKontrol = $db->from('kullanicilar')
->where('ApiKey', $apiKey)
->all();
if (count($kullaniciKontrol) > 0)
{
$servisDetay = $db->from('servisler')
->where('Id', $servisId)
->all();

if ( count($servisDetay) > 0 ) {
$apiDetay = $db->from('api')
->where('Id', $servisDetay[0]['ApiId'])
->all();

$ozelFiyat = $db->from('ozelfiyat')
->where('KullaniciId', $kullaniciKontrol[0]['Id'])
->where('ServisId', $servisDetay[0]['Id'])
->all();
if (count($ozelFiyat) > 0) {
$fiyat = $ozelFiyat[0]['Fiyat'];
} else {
$fiyat = $servisDetay[0]['Fiyat'];
}

$tutar = (($miktar * $fiyat) / 1000);

if (($miktar <= 0) OR ($kullaniciKontrol[0]['Bakiye'] < $tutar)) {
$json['error'] = 'Bakiyeniz yeterli değil.';
} elseif ($miktar < $servisDetay[0]['Minimum']) {
$json['error'] = 'Siparişiniz minimum miktarının altında.';
} elseif ($miktar > $servisDetay[0]['Maximum']) {
$json['error'] = 'Siparişiniz maximum miktardan fazla.';
} else {

$api = new Api();
$api->api_url = $apiDetay[0]['ApiUrl'];
$api->api_key = $apiDetay[0]['ApiKey'];
if ($servisDetay[0]['ServisYontemi'] == "Paket"){
$siparis = $api->order(array("service" => $servisDetay[0]['ApiNo'], 'link' => $siparisUrl));
}elseif ($servisDetay[0]['ServisYontemi'] == "Servis"){
$siparis = $api->order(array("service" => $servisDetay[0]['ApiNo'], 'link' => $siparisUrl, 'quantity' => $miktar));
}

$siparis_id = $siparis->order;
if (count($siparis_id) > 0) {
$query = $db->insert('siparisler')
->set(array(
"SiparisId" => $siparis_id,
"ApiId" => $servisDetay[0]['ApiId'],
"ApiNo" => $servisDetay[0]['ApiNo'],
"ServisAdi" => $servisDetay[0]['ServisAdi'],
"Kalan" => $miktar,
"BaslangicSayisi" => 0,
"Yorum" => $yorum,
"Fiyat" => $tutar,
"ServisId" => $servisDetay[0]['Id'],
"Miktar" => $miktar,
"Link" => $siparisUrl,
"Durum" => 'Pending',
"Kullanici" => $kullaniciKontrol[0]['KullaniciAdi'],
"Yayinci" => $yayinciId,
"YayinciOdemesi" => 0,
));
}

$kullaniciBakiyesi = $kullaniciKontrol[0]['Bakiye'] - $tutar;
if ($query) {
$json['order']= $db->lastId();
unset($json['error']);
$update = $db->update('kullanicilar')
->where('Id', $kullaniciKontrol[0]['Id'])
->set([
'Bakiye' => $kullaniciBakiyesi
]);
}else{
$update = $db->update('servisler')
->where('Id', $servisDetay[0]['Id'])
->set([
'Durum' => "Pasif"
]);
}
}
}else{
$json['error'] = 'Servis Bulunamadi!';
}
}else{
$json['error'] = 'Kullanici Bulunamadi!';
}
}else if ( $ApiYontemi == 'status' ) # Sipariş Durumu
{
$kullaniciKontrol = $db->from('kullanicilar')
->where('ApiKey', $apiKey)
->all();
if (count($kullaniciKontrol) > 0)
{
$siparisKontrol = $db->from('siparisler')
->where('Id', $siparisId)
->where('Kullanici', $kullaniciKontrol[0]['KullaniciAdi'])
->all();
if ( count($siparisKontrol) > 0 )
{
$durum = $siparisKontrol[0]['Durum'];
$kalan = $siparisKontrol[0]['Kalan'];
$baslangicSayisi = $siparisKontrol[0]['BaslangicSayisi'];
$fiyat = $siparisKontrol[0]['Fiyat'];

if ($durum == 'Bekliyor'){
$durum = 'Pending';
} else if ($durum == 'İşlemde') {
$durum = 'Processing';
}else if ($durum == 'Devam Etmekte'){
$durum = 'In Processing';
}else if ($durum == 'Tamamlandı') {
$durum = 'Completed';
}else if ($durum == 'Kısmi Tamamlandı') {
$durum = 'Partial';
}else if ($durum == 'iptal edildi') {
$durum = 'Canceled';
}else if ($durum == 'Error') {
$durum = 'Hata';
}

$json['status'] = $durum;
$json['start_count'] = $baslangicSayisi;
$json['charge'] = $fiyat;
$json['remains'] = $kalan;
unset($json['error']);
} else {
$json['error'] = 'yanlış sipariş numarası';
}
} else {
$json['error'] = 'yanlış API anahtarı';
}
}else if ( $ApiYontemi == 'balance' ) # Sipariş Durumu
{
$kullaniciKontrol = $db->from('kullanicilar')
->where('ApiKey', $apiKey)
->all();

if (count($kullaniciKontrol) > 0)
{
$json['balance'] = $kullaniciKontrol[0]['Bakiye'];
unset($json['error']);
}else {
$json['error'] = 'yanlış API anahtarı';
}
}else if ( $ApiYontemi == 'services' ) # Servisler
{
$servisKontrol = $db->from('servisler')
->all();

if (count($servisKontrol) > 0)
{
foreach ($servisKontrol as $service) {
if ($service['ServisYontemi']) {
if ($service['ServisYontemi'] == "Servis") {
$service['ServisYontemi'] = "Default";
}elseif($service['ServisYontemi'] == "Paket"){
$service['ServisYontemi'] = "Package";
}elseif ($service['ServisYontemi'] == "Yorum" ) {
$service['ServisYontemi'] = "Custom Comments ";
}
}

$array[] = array(
'service' => $service['Id'],
'name' => $service['ServisAdi'],
'type' => $service['ServisYontemi'],
'rate' => $service['Fiyat'],
'min' => $service['Minimum'],
'max' => $service['Maximum'],
'category' => $service['KategoriAdi']
);
}
$json = $array;

unset($json['error']);
}else {
$json['error'] = 'Servis bulunamadı';
}
}else{
$json['error'] = 'yanlis yontem tipi';
}


$result = $json;
print_r(json_encode($result));
?>



gelen key ile kullanıcıyı ve servis id ile servisi buluyorsunuz. Servis bilgileri (Min,max,adet) ile fiyatı hesaplatıp kullanıcının bakiyesi ile kontrolleri sağlıyorsunuz.
Eğer sipariş girilmeye uygunsa siparişi girip dışarıya json ile dönüyorsunuz. Aynı şekilde gelen isteğe göre sipariş verme, sorgulama vs işlemleri yaptırmanız lazım..

Api kodunu çök önceden yazmışım temiz değil kendinize göre düzenlemeniz gerekir sadece mantığını anlayın diye bırakıyorum. Kolay gelsin.