class_PrimeraApi.php

Go to the documentation of this file.
00001 <?php
00059 class PrimeraApi {
00063         const PI_ERROR = -1;
00064 
00068         const PI_DONE = 200;
00069 
00073         const PI_RECEIVER_ERROR = 301;
00074 
00078         const PI_SENDER_ERROR = 401;
00079 
00083         const PI_AMOUNT_ERROR = 501;
00084 
00088         const PI_TOO_LESS_PRIMERA = 502;
00089 
00093         const PI_USER_CHECK_ERROR = 601;
00094 
00098         const PI_USER_CHECK_OK = 602;
00099 
00103         const PI_GET_PRIMERA_DONE = 701;
00104 
00108         private $host = "www.primusportal.de";
00109         private $path = "/transfer.interface.2.0.php";
00110 
00111         private $errno = 0;
00112         private $err = "";
00113 
00114         private $seperator = ":";
00115 
00116         private $username = "";
00117         private $password = "";
00118 
00119         private $data = array();
00120 
00124         public function __construct ($PPUsername, $PPPassword) {
00125                 // Call parent constructor
00126                 parent::__construct();
00127 
00128                 // Clean up a little
00129                 $this->removeSystemArray();
00130                 $this->removeNumberFormaters();
00131 
00132                 // Set data (DEPRECATED!)
00133                 $this->username = $PPUsername;
00134                 $this->password = $PPPassword;
00135         }
00136 
00140         function queryApi ( $data = array() ) {
00141                 $fp = fsockopen($this->host, 80, $this->errno, $this->_err);
00142                 if (!$fp) return false;
00143 
00144                 $data["PrimusInterface_Username"] = base64_encode($this->username);
00145                 $data["PrimusInterface_Password"] = base64_encode(md5($this->password));
00146 
00147                 // POST-Daten übermitteln:
00148                 $data = http_build_query($data, '', '&');
00149 
00150                 fputs($fp, "POST {$this->path}HTTP/1.1\r\n");
00151                 fputs($fp, "Host: {$this->host}\r\n");
00152                 fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
00153                 fputs($fp, "Content-length: ". strlen($data) ."\r\n");
00154                 fputs($fp, "Connection: close\r\n\r\n");
00155                 fputs($fp, $data);
00156 
00157                 $return = "";
00158                 while (!feof($fp)) {
00159                         $return.=fgets($fp,128);
00160                 }
00161 
00162                 $content = explode("<!-- return-start -->", $return);
00163                 return $content[1];
00164         }
00165 
00169         function parseContent ( $content ) {
00170                 $x = explode("\n", $content);
00171                 $return = array();
00172                 foreach($x as $currentLine) {
00173                         $line_exploded = explode(":", $currentLine,2);
00174                         if (count($line_exploded) > 1) {
00175                                 $return[$line_exploded[0]] = $line_exploded[1];
00176                         }
00177                 }
00178                 return $return;
00179         }
00180 
00186         public function payPrimera ($Receiver, $Amount, $Description = "") {
00187                 $valid = false;
00188                 $PostData = array("PrimusInterface_Action" => "Pay",
00189                         "PrimusInterface_Receiver" => base64_encode($Receiver),
00190                         "PrimusInterface_Amount" => base64_encode($Amount),
00191                         "PrimusInterface_Description" => base64_encode($Description) );
00192 
00193                 $PostReturn = $this->parseContent( $this->queryApi($PostData) );
00194 
00195                 $this->data = $PostReturn;
00196                 if ($PostReturn["status"] == "200") {
00197                         $valid = true;
00198                 }
00199                 return $valid;
00200         }
00201 
00208         function CheckPrimusUser($User) {
00209                 $valid = false;
00210                 $PostData = array("PrimusInterface_Action"=> "CheckPrimusUser",
00211                         "PrimusInterface_CheckPrimusUser" => $User);
00212 
00213                 $PostReturn = $this->parseContent( $this->queryApi($PostData) );
00214 
00215                 $this->data = $PostReturn;
00216 
00217                 if ($PostReturn["status"] == self::PI_USER_CHECK_OK) {
00218                         $valid = true;
00219                 }
00220                 return $valid;
00221         }
00222 
00226         function getPrimera() {
00227                 $primera = false;
00228                 $PostData = array( "PrimusInterface_Action" => "GetPrimera" );
00229                 $PostReturn = $this->parseContent( $this->queryApi($PostData) );
00230 
00231                 $this->data = $PostReturn;
00232                 if ($PostReturn["status"] == self::PI_GET_PRIMERA_DONE) {
00233                         $primera = $PostReturn["primera"];
00234                 }
00235                 return $primera;
00236         }
00237 }
00238 
00239 // [EOF]
00240 ?>

Generated on Mon Dec 8 01:06:46 2008 for Ship-Simulator by  doxygen 1.5.6