Mailinglisten-Archive |
Hallo liebe Liste,
hier ein Demoskript, das per cURL (http://curl.haxx.se) einen SSL-POST an
einen Zahlungsdienstleister macht. Sollte so bei allen denen klappen, die an
ein Poseidon IPS (von ATOS) posten wollen:
<?
include ("header.html");
function read_errortext($rc){
$errortextdatei="returncodedatei.txt";
$fd = fopen($errortextdatei, "r");
$errorcode = 0;
while (!feof($fd)) {
$zeile = fgets($fd, 123);
$line = explode("=", $zeile);
if ($line[0]==$rc) {
$errortext = $line[1];
$errorcode = 1;
}
if (!$errorcode) {
$errortext = "No Error description available. Please
contact ALLCASH.";
}
}
fclose($fd);
return $errortext;
}
# getmicrotime ist nur fuer Geschwindigkeitstests
function getmicrotime(){
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
return ($mtime);
}
# cURL wird lokal gestartet
$path_to_curl = "/usr/local/bin/";
$path_to_ips = "Pfad_zum_Zahlungsdienstleister";
$debug=1; #Debug-mode on
# We want the given Creditcard-no. to be Luhn-checked. Therefore we use the
ccval script.
# This script does two things: Firstly, it does a classic Luhn-check.
Secondly, it checks if the given
# card-no. matches with the card-type. This is a good method to check if the
"cardholder" has knowledge
# of the card-type....
include ("ccval.php");
# Here we set the CC-no for testing. The number will be forwarded to this
script in real life.
$creditc = "4111111111111111"; #Testnummer ACHTUNG: NUR zum testen erlaubt!
$expdat = "0202";
$cctype = "vis";
# do the check...
$result = CCVal($creditc, "vis");
if (!$result) {
echo ("<br>Kreditkarte ungültig");
exit();
}
#echo ("<br>Kreditkarte gültig");
$path_exists = file_exists ($path_to_curl);
if (!$path_exists) {
echo ("<br>Pfad zu cURL ungültig");
exit();
}
#echo ("<br>Pfad zu cURL OK");
$curl_exists = file_exists ($path_to_curl."curl");
if (!$curl_exists) {
echo ("<br>cURL an angegebenem Pfad nicht gefunden");
exit();
}
#echo ("<br>cURL ist da");
$timestamp=date("YmdHis");
#echo ("<br>Timestamp: $timestamp");
# Hier wird $request_string zusammengebaut. Da das ALLCASH IPS ein
Lizenzprodukt ist, dürfen genauere Parameter nur mit unterzeichneter
Vertraulichkeiterklärung herausgegeben werden
$request_string="...";
#echo ("<br>Anfragestring: $request_string<br>");
$anfangszeit= getmicrotime();
echo ("<br><br><b>");
# Die Option -3 erzwingt SSLv3, ohne diese Option versucht es cURL mit TLS,
was nicht bei jedem Webserver klappt (z.B. IBM HTTPD :-( )
$ssl_post=$path_to_curl."curl -3 -d \"".$request_string."\" ".$path_to_ips;
# Führe cURL aus und schreibe die Antwort in $antwort
$x = exec ("$ssl_post", $antwort);
$b = count($antwort);
# Erwartet wird eine Zeile als Antwort
if ($b > 1){
echo ("<h2>No valid answer received:</h2><br>");
for ($i=0; $i<=$b; $i++){
echo $antwort[$i];
}
}
# Separier den String nach dem Trennzeichen & und schreib ins Array
$eachline
$eachline = explode("&", $antwort[0]);
#$eachline = explode("&", $request_string);
for ($k=0; $k<count($eachline); $k++)
{
# Separier jetzt jede Zeile nach = und schreib die Werte in
$antwortarray
$eachvalueinline = explode("=", $eachline[$k]);
$antwortarray[$eachvalueinline[0]] = $eachvalueinline[1];
}
# OK, auch ohne Vertraulichkeitserklärung: Da von der
zurückgegebenen Variable rc so viel abbhängt, wird sie hier
verwendet:
$rc=$antwortarray["rc"];
switch ($rc) {
case "000":
echo ("<br><br>Transaktion autorisiert!!)";
break;
default:
echo ("<br><b>Sorry, your transaction was not
authorized. Error no. ". ."</b>");
echo ("Returncode no. ".$rc.":
".read_errortext($rc));
break;
}
# Zum Spass und zum Einschüchtern von
Möchtegern-Kreditkartenbetrügern
echo ("<br>Your IP: $REMOTE_ADDR");
$endzeit= getmicrotime();#
$difzeit = $endzeit-$anfangszeit ;
echo ("<br>Dauer: $difzeit s<br>");
if ($debug) {
echo ("<hr><br><br>Posted request:<br>");
$eachline2 = explode("&", $request_string);
for ($k=0; $k<count($eachline2); $k++)
{
# Separier jetzt jede Zeile nach = und schreib die Werte in
$antwortarray
$jedeanfragezeile = explode("=", $eachline2[$k]);
$antwortarray2[$jedeanfragezeile[0]] = $jedeanfragezeile[1];
}
#echo ("$request_string<br>");
reset ($antwortarray2);
while (list ($bez, $wert) = each ($antwortarray2)) {
echo "<font face=\"Courier,monospace\"> $bez =
$wert</font><br>";
}
echo "<br><br>Returned data:<br>";
reset ($antwortarray);
while (list ($bez, $wert) = each ($antwortarray)) {
echo "<font face=\"Courier,monospace\"> $bez =
$wert</font><br>";
}
}
include ("footer.html");
?>
---
Moritz Königsbüscher
Junior Project Manager
ALLCASH
Trust & Service International GmbH
Eurotec-Ring 10
D-47445 Moers
Tel. +49 (0)2841/1796-279
Fax +49 (0)2841/1796-521
E-Mail koenigsbuescher_(at)_allcash.de
Web www.allcash.de
php::bar PHP Wiki - Listenarchive