Yii PayPal IPN模拟器返回无效答案
我正在尝试实现paypal IPN侦听器。问题是,无论我尝试什么,我仍然从IPN模拟器得到无效的答案。我搜索了很多论坛,但没有找到任何帮助。有人知道吗,有什么问题吗 请看下面我的代码。 YII_DEBUG是真的 使用沙盒是正确的 我尝试了使用或不使用cacert.pem的实现,但没有任何效果Yii PayPal IPN模拟器返回无效答案,yii,paypal,paypal-ipn,Yii,Paypal,Paypal Ipn,我正在尝试实现paypal IPN侦听器。问题是,无论我尝试什么,我仍然从IPN模拟器得到无效的答案。我搜索了很多论坛,但没有找到任何帮助。有人知道吗,有什么问题吗 请看下面我的代码。 YII_DEBUG是真的 使用沙盒是正确的 我尝试了使用或不使用cacert.pem的实现,但没有任何效果 public function actionProcessPayment() { // Read POST data // reading posted data directly from
public function actionProcessPayment()
{
// Read POST data
// reading posted data directly from $_POST causes serialization
// issues with array data in POST. Reading raw POST data from input stream instead.
$raw_post_data = file_get_contents('php://input');
if(YII_DEBUG == true) {
Yii::log(date('[Y-m-d H:i e] '). "Original data: " . $raw_post_data . PHP_EOL, 'warning');
}
$req = 'cmd=_notify-validate&'.$raw_post_data;
// Post IPN data back to PayPal to validate the IPN data is genuine
// Without this step anyone can fake IPN data
if(self::USE_SANDBOX == true) {
$paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
} else {
$paypal_url = "https://www.paypal.com/cgi-bin/webscr";
}
$ch = curl_init($paypal_url);
if ($ch == FALSE) {
return FALSE;
}
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
if(YII_DEBUG == true) {
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
}
// Set TCP timeout to 30 seconds
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
$cert = dirname(__FILE__).'/../components/cacert.pem';
curl_setopt($ch, CURLOPT_CAINFO, $cert);
$res = curl_exec($ch);
if (curl_errno($ch) != 0) // cURL error
{
if(YII_DEBUG == true) {
Yii::log(date('[Y-m-d H:i e] '). "Can't connect to PayPal to validate IPN message: " . curl_error($ch) . PHP_EOL, 'warning');
}
curl_close($ch);
exit;
} else {
// Log the entire HTTP response if debug is switched on.
if(YII_DEBUG == true) {
Yii::log(date('[Y-m-d H:i e] '). "HTTP request of validation request:". curl_getinfo($ch, CURLINFO_HEADER_OUT) ." for IPN payload: $req" . PHP_EOL, 'warning');
Yii::log(date('[Y-m-d H:i e] '). "HTTP response of validation request: $res" . PHP_EOL, 'warning');
}
curl_close($ch);
}
// Inspect IPN validation result and act accordingly
// Split response headers and payload, a better way for strcmp
$tokens = explode("\r\n\r\n", trim($res));
$res = trim(end($tokens));
if (strcmp ($res, "VERIFIED") == 0) {
// check whether the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your PayPal email
// check that payment_amount/payment_currency are correct
// process payment and mark item as paid.
// assign posted variables to local variables
//$item_name = $_POST['item_name'];
//$item_number = $_POST['item_number'];
//$payment_status = $_POST['payment_status'];
//$payment_amount = $_POST['mc_gross'];
//$payment_currency = $_POST['mc_currency'];
//$txn_id = $_POST['txn_id'];
//$receiver_email = $_POST['receiver_email'];
//$payer_email = $_POST['payer_email'];
if(isset($_POST['custom'], $_POST['payment_status']))
if($_POST['payment_status'] == 'Completed')
Order::processPayment($_POST['custom']);
if(YII_DEBUG == true) {
Yii::log(date('[Y-m-d H:i e] '). "Verified IPN: $req ". PHP_EOL, 'warning');
}
} else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
// Add business logic here which deals with invalid IPN messages
if(YII_DEBUG == true) {
Yii::log(date('[Y-m-d H:i e] '). "Invalid IPN: $req" . PHP_EOL, 'warning');
}
}
Yii::app()->end();
}
问题是因为IPN模拟器自动用本地(捷克)格式的日期和(StředníEvropa(běěěnýčas)字符串填充字段支付ýu日期。我在IPN模拟器中将其替换为(GMT标准时间),everythink现在工作正常