<?
class odk
{
private $app_id = "";
private $app_key = "";
private $app_secret_key = "";
private $income_api_server = "";
private $income_app_key = "";
private $income_vid = "";
private $income_session_secret_key = "";
private $income_session_key = "";
private $income_method = "";
private $income_call_id = "";
private $income_sig = "";
private $income_currency = "";
public $income_amount = "";
private $income_transaction_time = "";
private $income_product_code = "";
public $income_transaction_id = "";
private $signature = "";
private $params = "";
public $userData = "";
public $valute = array();
public function __construct()
{
$this->app_id = "1245415680";
$this->app_key = "CBAKIMDLEBABABABA";
$this->app_secret_key = "0308E89B7F80F278F030C7B7";
}
public function prepareIncomingVars($type)
{
switch($type)
{
case 'login':
{
if(!isset($_GET['api_server']) || !isset($_GET['application_key']) || !isset($_GET['logged_user_id']) || !isset($_GET['session_secret_key']) || !isset($_GET['session_key']))
{
exit;
}
$this->income_api_server = urldecode($_GET['api_server']);
$this->income_app_key = $_GET['application_key'];
$this->income_vid = $_GET['logged_user_id'];
$this->income_session_secret_key = $_GET['session_secret_key'];
$this->income_session_key = $_GET['session_key'];
return true;
}
break;
case 'payment':
{
$this->income_method = $_GET["method"];
$this->income_app_key = $_GET["application_key"];
$this->income_call_id = $_GET["call_id"];
$this->income_sig = $_GET["sig"];
$this->income_vid = $_GET["uid"];
$this->income_currency = $_GET["currency"];
$this->income_amount = $_GET["amount"];
$this->income_transaction_time = $_GET["transaction_time"];
$this->income_product_code = $_GET["product_code"];
$this->income_transaction_id = $_GET["transaction_id"];
if($this->income_amount == 0) exit;
return true;
}
break;
default:
{
echo 'Ошибка метода';
exit;
}
}
}
public function getBanners() {
$api_server = 'http://api.odnoklassniki.ru/';
$application_key = $this->app_key;
$params = array(
"application_key=$application_key",
'session_key='.User::a()->user['odk_session'],
'wids=mobile-header-small,mobile-footer'
);
sort($params);
$sig = md5(join('', $params) . User::a()->user['odk_session_secret_key']);
$req = $api_server."/api/widget/getWidgets?sig=".$sig."&" . join('&', $params);
$dt = file_get_contents($req);
return $dt;
}
public function prepareSIGforLogin($fields = 'first_name,name,last_name,pic_1,url_profile,gender',$format = 'JSON')
{
$params = array(
'application_key='.$this->income_app_key.'',
'format='.$format.'',
'fields='.$fields.'',
"uids=".$this->income_vid."",
);
sort($params);
$this->signature = md5(join('', $params) . $this->app_secret_key);
$this->params = $params;
return true;
}
public function prepareSIGforPayment()
{
$i = 0;
$params = array();
foreach ($_GET as $key => $value)
{
if($key != "sig")
{
$params[$i] = "$key=$value";
$i++;
}
}
sort($params);
$params = join('', $params);
$this->signature = md5($params . $this->app_secret_key);
return true;
}
public function prepareProductionCode($code = false)
{
switch((isset($code) && $code == true ? $code : $this->income_product_code))
{
case 1: { $credits = 5; $pay = 4; } break;
case 2: { $credits = 20; $pay = 15; } break;
case 3: { $credits = 50; $pay = 35; } break;
case 4: { $credits = 100; $pay = 65; } break;
case 5: { $credits = 250; $pay = 150; } break;
case 6: { $credits = 500; $pay = 300; } break;
default: {echo 'Ошибка кода'; exit;} break;
}
$this->valute['ok'] = $pay;
$this->valute['valuta'] = $credits;
if(!isset($code)) {
if($pay != $_GET["amount"])die();
}
return true;
}
public function addHeader()
{
header('Content-Type: application/xml; charset=utf-8');
}
public function addUserInfo()
{
$this->prepareSIGforLogin();
$request = "".$this->income_api_server."api/users/getInfo?sig=".$this->signature."&" . join('&', $this->params)."";
$page = file_get_contents($request);
$data = json_decode($page,true);
if($data['error_code'] != false)
{
echo 'Номер ошибки: '.$data['error_code']." <br />";
echo 'Описание ошибки: <strong>'.$data['error_msg'].'</strong>';
exit;
}
$this->userData = $data;
return true;
}
public function checkMethod ($correctMethod)
{
if($this->income_method != $correctMethod)
{
file_put_contents("./log.txt","<?xml version=\"1.0\" encoding=\"UTF-8\"?>');<ns2:error_response xmlns:ns2='http://api.forticom.com/1.0/'><error_code>101</error_code><error_msg>Parameter application_key not specified or invalid</error_msg></ns2:error_response>");
header('invocation-error: 3');
print("<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns2:error_response xmlns:ns2='http://api.forticom.com/1.0/'><error_code>3</error_code><error_msg>Method does not exist.</error_msg></ns2:error_response>");
exit;
}
return true;
}
public function checkAppKey()
{
if($this->income_app_key != $this->app_key)
{
header('invocation-error: 101');
file_put_contents("./log.txt" , "<?xml version=\"1.0\" encoding=\"UTF-8\"?>');<ns2:error_response xmlns:ns2='http://api.forticom.com/1.0/'><error_code>101</error_code><error_msg>Parameter application_key not specified or invalid</error_msg></ns2:error_response>");
print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>');<ns2:error_response xmlns:ns2='http://api.forticom.com/1.0/'><error_code>101</error_code><error_msg>Parameter application_key not specified or invalid</error_msg></ns2:error_response>");
exit;
}
return true;
}
public function checkSig()
{
if($this->signature == false)
{
echo 'Не сформированна сигнатура';
exit;
}
if($this->income_sig != $this->signature)
{
header('invocation-error: 104');
file_put_contents("./log.txt" , '<?xml version="1.0" encoding="UTF-8"?><callbacks_payment_response xmlns="http://api.forticom.com/1.0/">true</callbacks_payment_response>');
print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>');<ns2:error_response xmlns:ns2='http://api.forticom.com/1.0/'><error_code>104</error_code><error_msg>Invalid signature.</error_msg></ns2:error_response>");
exit;
}
return true;
}
public function showTrueAnswerOfPayment()
{
file_put_contents("./log.txt" , '<?xml version="1.0" encoding="UTF-8"?><callbacks_payment_response xmlns="http://api.forticom.com/1.0/">true</callbacks_payment_response>');
return '<?xml version="1.0" encoding="UTF-8"?><callbacks_payment_response xmlns="http://api.forticom.com/1.0/">true</callbacks_payment_response>';
}
public function showSecretKey()
{
return $this->income_session_secret_key;
}
public function showSessionKey()
{
return $this->income_session_key;
}
public function showUID()
{
return $this->income_vid;
}
public function showPaymentList()
{
$api_server = "http://m.odnoklassniki.ru/";
for($i = 1; $i<=6; $i++)
{
$this->prepareProductionCode($i);
$params = array("application_key=".$this->app_key,'session_key='.User::a()->user['odk_session'],'name=Покупка '.$this->valute['valuta'].' баксов','price='.$this->valute['ok'].'','code='.$i.'');
sort($params);
$sig = md5(join('', $params) . User::a()->user['odk_session_secret_key']);
$url = $api_server."api/show_payment?" . join('&', $params)."&sig=".$sig."";
$list .= "<div><a class='pay' style='text-align:left' href='".$url."'><img src='/img/icons/ok.png' style='margin-right:2px;width:16px'>Купить <img src='/img/icons/donate.png'> ".$this->valute['valuta']." (".$this->valute['ok']." ОК)</a></div>";
}
return $list;
}
public function myUrlEncode($string) {
$entities = array('%21', '%2A', '%27', '%28', '%29', '%3B', '%3A', '%40', '%26', '%3D', '%2B', '%24', '%2C', '%2F', '%3F', '%25', '%23', '%5B', '%5D');
$replacements = array('!', '*', "'", "(", ")", ";", ":", "@", "&", "=", "+", "$", ",", "/", "?", "%", "#", "[", "]");
return str_replace($entities, $replacements, urlencode($string));
}
public function message($uid){
$api_server = "https://api.ok.ru/fb.do?";
$message = 'Обновление в игре!';
$params = array(
'application_key='.$this->app_key.'',
'format=json',
'method=notifications.sendSimple',
'uid='.$uid.'',
'text='.$message.'',
);
sort($params);
$sig = md5(join('', $params). $this->app_secret_key);
$url= $this->myUrlEncode($api_server.join('&', $params).'&sig='.$sig);
$dt = file_get_contents($url);
var_dump($dt);
}
}
?>