+++ /dev/null
-<?php
-/**
- * PrimeraApi
- * -------------------------------------------
- * Mit dieser Klasse ist ein einfacher Primeratransfer von Ihrem Account
- * zu dem Account eines bei Primusportal.de registrierten Mitglieds m�glich.
- *
- * ----------------- Aenderungen durch Roland Haeder 09.08.2008 ---------------
- * Klasse umbenannt nach PrimeraApi, damit sie in das Framework besser passt.
- * Zudem sind alle oeffentlichen Attribute nun privat, der Konstruktor hat den
- * neuen "magischen" Namen __construct() und "normale" Konstanten sind nach
- * Klassenkonstanten umbenannt. Unsinnige else-Bloecke sind noch umgewandelt.
- * Methodennamen fangen nun immer mit einem kleinen Buchstaben an. Zudem sind
- * die Methoden Pay,Query und Parse umbenannt.
- * ----------------- Aenderungen durch Roland Haeder 09.08.2008 ---------------
- *
- * ----------------- Aenderungen durch Roland Haeder 19.04.2011 ---------------
- * Es ist nun bei allen Methoden- und Feldnamen der erste Buchstabe
- * kleingeschrieben, damit es besser in meine Namenskonvention passt. Noch mehr
- * doppelte Anfuehrungszeichen in einfache umgewandelt, damit die Klasse
- * performanter (wegen sonst doppeltes Parsen) wird.
- * ----------------- Aenderungen durch Roland Haeder 19.04.2011 ---------------
- *
- * ------------ Achtung! Bitte zuerst lesen, bevor Sie weiterlesen: -----------
- * Das meiste aus der unteren Anleitung sollte auf die hier verwendeten Namen
- * portiert sein. Falls Sie Fragen haben, bitte melden Sie sich bei Roland
- * Haeder. Funktionell wurde hier aber nichts geaendert.
- * ------------ Achtung! Bitte zuerst lesen, bevor Sie weiterlesen: -----------
- *
- * Die Einbindung des Interfaces geschieht folgenderma�en:
- * 1. Einbindung der Klasse in Ihr PHP-Auszahlungsskript:
- * CODE:
- * $primusUsername = 'username'; // Ihr Username bei Primusportal
- * $primusPassword = 'passwort'; // Ihr Passwort bei Primusportal
- *
- * $apiInstance = ObjectFactory::createObjectByName('PrimeraApi', array($primusUsername, $primusPassword));
- * 2. Durchf�hren einer Auszahlung:
- * CODE:
- * $Status = $apiInstance->payPrimera($PayReceiver, $PayAmount, $PayDescription);
- *
- * Wobei $PayReicer der Username des Empf�ngers bei
- * Primusportal.de ist. $PayAmount ist der gerundete( !! ) Betrag an Primera,
- * die der Empf�nger erhalten soll. $PayDescription ist eine von Ihnen
- * festgelegte kurze Beschreibung. Die L�nge dieses Textes darf 100 Zeichen
- * nicht �berschreiten. Beispiel:
- * $status = $apiInstance->payPrimera('garbage', 10000, 'Auszahlung IhreSeite.de - ID: 12345');
- * 3. �berpr�fung des Status (R�ckgabecode):
- * CODE:
- * if ($status === FALSE) {
- * // Ein Fehler ist aufgetreten
- * // Fehlerbehandlung hier einf�gen...
- * } else {
- * // Auszahlung erfolgreich durchgef�hrt
- * // F�hren Sie hier Ihre Datenbankabfragen durch, um die Auszahlung zu
- * // best�tigen...
- * }
- *
- * Die komplette R�ckgabe des Interfaces wird als assoziatives Array in der Klassen-
- * variable $data gespeichert:
- * $data = array(
- * 'status' => R�ckgabecode (PI_DONE, PI_SENDER_ERROR, ...),
- * 'statustext' => Status in Worten (z.B.: 'Transaktion erfolgreich durchgef�hrt'),
- * );
- *
- *
- * @author Andreas Schmidt <xxgarbagexx@web.de>
- * @author Roland Haeder <webmaster.shipsimu.org>
- * @version 1.0 - beta
- * @copyright (c) 2007 by Primusportal.de
- * @copyright (c) 2008, 2011 by Roland Haeder
- */
-class PrimeraApi extends BaseFrameworkSystem {
- /**
- * Fehler - Interfacebenutzer
- */
- const PI_ERROR = -1;
-
- /**
- * Statuscode f�r erfolgreich ausgef�hrte Transaktion
- */
- const PI_DONE = 200;
-
- /**
- * Fehler - User existiert nicht oder ist gesperrt
- */
- const PI_RECEIVER_ERROR = 301;
-
- /**
- * Sender-Account Fehler (User nicht existent, gesperrt, ...)
- */
- const PI_SENDER_ERROR = 401;
-
- /**
- * Betrag fehler
- */
- const PI_AMOUNT_ERROR = 501;
-
- /**
- * Zu wenig Primera
- */
- const PI_TOO_LESS_PRIMERA = 502;
-
- /**
- * User nicht aktiv oder existiert nicht
- */
- const PI_USER_CHECK_ERROR = 601;
-
- /**
- * User aktiv
- */
- const PI_USER_CHECK_OK = 602;
-
- /**
- * Primerastand erfolgreich geholt
- */
- const PI_GET_PRIMERA_DONE = 701;
-
- /**
- * HTTP-EOL
- */
- const HTTP_EOL = "\r\n";
-
- /**
- * URL f�r das Interface auf dem Primusserver:
- */
- private $host = 'www.primusportal.de';
- private $path = '/transfer.interface.2.0.php';
-
- private $errno = 0;
- private $err = '';
-
- private $separator = ':';
-
- private $username = '';
- private $password = '';
-
- private $data = array();
-
- /**
- * Konstruktor
- */
- public function __construct ($primusUsername, $primusPassword) {
- // Call parent constructor
- parent::__construct();
-
- // Set data
- $this->username = $primusUsername;
- $this->password = $primusPassword;
- }
-
- /**
- * Anfrage senden und Rueckgabecode in Variable speichern
- */
- private function queryApi ( $data = array() ) {
- $fp = fsockopen($this->host, 80, $this->errno, $this->_err);
- if (!$fp) return false;
-
- $data['PrimusInterface_Username'] = base64_encode($this->username);
- $data['PrimusInterface_Password'] = base64_encode(md5($this->password));
-
- // POST-Daten uebermitteln:
- $queryData = http_build_query($data, '', '&');
-
- $request .= 'POST ' . $this->path . 'HTTP/1.1' . self::HTTP_EOL;
- $request .= 'Host: ' . $this->host . self::HTTP_EOL;
- $request .= 'Content-type: application/x-www-form-urlencoded' . self::HTTP_EOL;
- $request .= 'Content-length: '. strlen($queryData) . self::HTTP_EOL;
- $request .= 'Connection: close' . self::HTTP_EOL;
- $request .= self::HTTP_EOL;
- $request .= $queryData;
-
- fputs($fp, $request);
-
- $return = '';
- while (!feof($fp)) {
- $return .= fgets($fp, 128);
- } // END - while
-
- $content = explode('<!-- return-start -->', $return);
- return $content[1];
- }
-
- /**
- * Funktion parst die R�ckgabe vom Transferskript:
- */
- private function parseContent ( $content ) {
- $x = explode("\n", $content);
- $return = array();
- foreach($x as $currentLine) {
- $line_exploded = explode($this->separator, $currentLine,2);
- if (count($line_exploded) > 1) {
- $return[$line_exploded[0]] = $line_exploded[1];
- } // END - if
- } // END - foreach
- return $return;
- }
-
- /**
- * @param int/string $Receiver UserID / Username des Empf�ngers
- * @param int$Amount Betrag in ganzzahligen Primera
- * @param string $Description Beschreibung (Sichtbar in Einzelauflistung)
- */
- public function payPrimera ($Receiver, $Amount, $Description = '') {
- $valid = FALSE;
- $postData = array(
- 'PrimusInterface_Action' => 'Pay',
- 'PrimusInterface_Receiver' => base64_encode($Receiver),
- 'PrimusInterface_Amount' => base64_encode($Amount),
- 'PrimusInterface_Description' => base64_encode($Description)
- );
-
- $postReturn = $this->parseContent( $this->queryApi($postData) );
-
- $this->data = $postReturn;
- if ($postReturn['status'] == '200') {
- $valid = TRUE;
- } // END - if
- return $valid;
- }
-
- /**
- * �berpr�ft den Status eines Primus-Users
- * - existiert der User
- * - ist er aktiv
- * @param string/int $User Userid / Username
- */
- public function checkPrimusUser ($userName) {
- $valid = FALSE;
- $postData = array(
- 'PrimusInterface_Action' => 'CheckPrimusUser',
- 'PrimusInterface_CheckPrimusUser' => $userName
- );
-
- $postReturn = $this->parseContent( $this->queryApi($postData) );
-
- $this->data = $postReturn;
-
- if ($postReturn['status'] == self::PI_USER_CHECK_OK) {
- $valid = TRUE;
- } // END - if
- return $valid;
- }
-
- /**
- * Die Funktion liefer den aktuellen Primerastand
- */
- public function getPrimera() {
- $primera = FALSE;
- $postData = array(
- 'PrimusInterface_Action' => 'GetPrimera'
- );
- $postReturn = $this->parseContent( $this->queryApi($postData) );
-
- $this->data = $postReturn;
- if ($postReturn['status'] == self::PI_GET_PRIMERA_DONE) {
- $primera = $postReturn['primera'];
- } // END - if
- return $primera;
- }
-}
-
-// [EOF]
-?>