我最近建立了一个Amazon AWS免费套餐帐户。我有一个实例运行,apache,php5,cURL等安装,一切似乎工作正常,直到这一点。我在服务器上运行了一个Paypal IPJ脚本,如下所示:
<?php
error_reporting(E_ALL);
class PaypalIPN {
private $_url;
/**
* @param $mode String
* Set to live when applicable
*/
public function __construct($mode = 'sandbox'){
if($mode == 'live')
$this->_url = 'https://paypal.com/cgi-bin/webscr';
else
$this->_url = "https://sandbox.paypal.com/cgi-bin/webscr";
}
/**
* @param
* cURL function that will get info from paypal
*/
public function run(){
# Post fields
$fields = 'cmd=_notify-validate';
foreach($_POST as $key => $value){
$fields .= "&$key=" . urlencode($value);
}
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $this->_url,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $fields
));
$result = curl_exec($ch);
echo $result;
echo '<br>';
echo 'Result^';
curl_close($ch);
$a = strcmp($result, "VERIFIED") == 0;
# Write to file here, so we can analyze
$fh = fopen('result.txt', 'w');
fwrite($fh, $result . ' --' . $fields . ' --' . $a);
fclose($fh);
if (strcmp ($result, "VERIFIED") == 0){
# If the transaction has been verfied
# Continue...
// payment info
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
// product info
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
// buyer info
$payer_email = $_POST['payer_email'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$address_city = $_POST['address_city'];
$address_state = $_POST['address_state'];
$address_country = $_POST['address_country'];
// receiver_email, that's our email address
$receiver_email = $_POST['receiver_email'];
// put your actual email address here
$our_email = 'email@email.com';
if (($payment_status == 'Completed') &&
($receiver_email == $our_email) &&
($payment_amount == "20.00" ) &&
($payment_currency == "USD"))
{
foreach ($_POST as $key => $value)
{
$emailtext .= $key . " = " .$value ."\n\n";
}
# If all is good, mail our customer, and create a tmp/.dat file
# to be created for our license
mail($payer_email, "Live-VERIFIED IPN", $emailtext . "\n\n" . $req);
$dat_filename = $first_name . '-' . $last_name . '-' . $address_city . '.dat';
$fc = fopen($dat_filename, 'w');
fwrite($fc,
"first_name = " . $first_name . "\n\n" .
"last_name = " . $last_name . "\n\n" .
"email = " . $receiver_email . "\n\n" .
"city = " . $address_city . "\n\n" .
"state = " . $address_state . "\n\n" .
"country = " . $address_country
);
fclose($fc);
$filename = explode('.', $dat_filename);
# Execute shell through PHP
$wat = "/var/www/license/";
$argc[0] = $filename[0];
$out = exec('sudo java -jar license2.jar '.$wat. ' '.$filename[0]);
$fd = fopen('log.txt', 'w');
fwrite($fd, $out);
fclose($fd);
}
} else if (strcmp ($result, "INVALID") == 0) {
{
// If 'INVALID', send an email. TODO: Log for manual investigation.
foreach ($_POST as $key => $value)
{
$emailtext .= $key . " = " .$value ."\n\n";
}
mail($payer_email, "Live-INVALID IPN", $emailtext . "\n\n" . $req);
}
}
# Functionality needs to be added beyond this point to execute
# and wait for the result returned by what will be our shell script
}
}
?>
现在奇怪的是我可以记录我的帖子字段,但脚本不会返回VALID
或INVALID
字段。我必须指出,这个脚本在我拥有的共享主机帐户上运行得非常好。我认为最初它可能与权限有关,但据我所知,一切都是有序的。有谁知道问题可能是什么?
答案 0 :(得分:0)
显然问题很简单。在构造函数中调用域之前,请求需要www.
。
public function __construct($mode = 'sandbox'){
if($mode == 'live')
$this->_url = 'https://www.paypal.com/cgi-bin/webscr';
else
$this->_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
}