"failed_general", 'message' => WERNIS_API_REQUEST_DATA_INVALID ); } // Is the API id and MD5 hash there? if ((empty($CONFIG['wernis_api_id'])) || (empty($CONFIG['wernis_api_md5']))) { // Abort here... return array( 'status' => "failed_general", 'message' => WERNIS_API_REQUEST_DATA_MISSING ); } // Construct the request string $requestString = $CONFIG['wernis_api_url'] . $scriptName."?api_id=".$CONFIG['wernis_api_id']."&api_key=".$CONFIG['wernis_api_md5']; foreach ($requestData as $key=>$value) { $requestString .= "&".$key."=".$value; } // Get the raw response from the lower function $response = MXCHANGE_OPEN($requestString); // Check the response header if all is fine if (strpos($response[0], "200") === false) { // Something bad happend... :( return array( 'status' => "request_eror", 'message' => sprintf(WERNIS_API_REQUEST_ERROR, $response[0]) ); } // All (maybe) fine so remove the response header from server $response = $response[(count($response) - 1)]; // Prepare the returning result for higher functions if (substr($response, 0, 1) == "&") { // Remove the leading & (which can be used in Flash) $response = substr($response, 1); } // Bring back the response $data = explode("=", $response); // Default return array (should not stay empty) $return = array(); // We use only the first two entries (which shall be fine) if ($data[0] == "error") { // The request has failed... :( switch ($data[1]) { case "AUTH": // Authorization has failed $return = array( 'status' => "auth_failed", 'message' => WERNIS_API_REQUEST_FAILED_AUTH ); break; default: // Unknown error (maybe new?) $return = array( 'status' => "request_failed", 'message' => sprintf(WERNIS_API_REQUEST_FAILED, $data[1]) ); break; } } else { // All fine here $return = array( 'status' => "OK", 'response' => $response ); } // Return the result return $return; } // Tests the function by calling balance.php on the API function WERNIS_TEST_API () { // Get config first global $CONFIG; // Prepare the request to the API $return = WERNIS_SEND_REQUEST("balance.php"); die("
".print_r($return, true)."
"); } // ?>