【发布时间】:2012-07-08 10:38:37
【问题描述】:
$req = 'cmd=' . urlencode('_notify-validate');
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.sandbox.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HEADER, 0);
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_HTTPHEADER, array('Host: www.paypal.com'));
$res = curl_exec($ch);
curl_close($ch);
if (strcmp ($res, "VERIFIED") == 0) {
//TODO
}
else if (strcmp ($res, "INVALID") == 0) {
//TODO
}
回复
cmd=_notify-validate&transaction=Array
响应还有更多内容,但您可以看到问题是它们是 $_POST 数组中的数组。如何在 $_POST 数组中编码和去除数组的斜线?
【问题讨论】:
-
你为什么不直接使用像github.com/Quixotix/PHP-PayPal-IPN这样的PayPal IPN类