如何在本地机器上使用即时付款通知模拟器?IPN 处理程序 URL 中将提供什么?我无法访问我们的路由器。
谢谢
您可以使用ngrok在 localhost 上进行测试。
只需在本地运行 ngrok,然后粘贴 ngrok 为您提供的测试 url(类似于http://1bc7d09d.ngrok.com/)
它为您的本地主机提供了一条隧道。
Paypal 的 IPN 模拟器不适用于 localhost。但是,您可以模拟模拟器:-)。为此,您需要安装浏览器插件/扩展程序,例如firefox的海报或 google chrome 的Advanced Rest Client。
打开应用程序并输入您正在收听 IPN 响应的 url:
http://localhost/ipn
将以下内容作为您的 POST 数据并提交请求:
residence_country=US&invoice=abc1234&address_city=San+Jose&first_name=John&payer_id=TESTBUYERID01&mc_fee=0.44&txn_id=421462822&receiver_email=seller%40paypalsandbox.com&custom=xyz123+CUSTOMHASH&payment_date=12%3A40%3A25+27+Aug+2013+PDT&address_country_code=US&address_zip=95131&item_name1=something&mc_handling=2.06&mc_handling1=1.67&tax=2.02&address_name=John+Smith&last_name=Smith&receiver_id=seller%40paypalsandbox.com&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AgAAjEU7A5rthY2aP4j1jOIrjuGx&address_country=United+States&payment_status=Completed&address_status=confirmed&business=seller%40paypalsandbox.com&payer_email=buyer%40paypalsandbox.com¬ify_version=2.4&txn_type=cart&test_ipn=1&payer_status=unverified&mc_currency=USD&mc_gross=12.34&mc_shipping=3.02&mc_shipping1=1.02&item_number1=AK-1234&address_state=CA&mc_gross1=9.34&payment_type=instant&address_street=123%2C+any+street
更新:我刚刚开始使用另一个更简单的选项,https://localtunnel.me。要安装和运行模块,请执行以下操作。它将显示您的公共 URL。对该公共 URL 的所有请求都将转发到您的本地主机。
npm install -g localtunnel
lt --port 80
您无法在本地主机上测试 IPN,因为 IPN 是关于 PayPal 的服务器向您定义的 URL 发起服务器端 POST 的全部内容。
因此,您的 IPN 脚本必须可以被外界访问(或者您可以使用诸如 ngrok.me/localtunnel.me 之类的隧道)。
您可以通过运行我在您的本地主机上创建的以下脚本来模拟 PayPal 的 IPN 帖子(您需要安装 curl)。只要您的侦听器指向沙箱,它就应该验证。将您的听众更改为实时贝宝,它应该无法验证。
<?php
// SIMULATE PAYPAL IPN LOCALLY
//
// Sometimes you need to test on your local host and this can be difficult due
// to IP routing issues. Use this code on your local machine to simulate the
// same process that the sandbox IPN simulator does when posting to your URL.
//
// Run this code in command line or via the browser. It will post IPN data just
// like Paypal would. If the code you've written to process your IPN data
// posts back to the sandbox, it should come back as valid.
// Put the full url to test in $paypal_url, include file extensions if necessary
$paypal_url = 'http://localhost/paypal_ipn/process'; // IPN listener to test
//example posted data from paypal IPN
$test = 'residence_country=US&invoice=abc1234&address_city=San+Jose&first_name=John&payer_id=TESTBUYERID01&mc_fee=0.44&txn_id=421462822&receiver_email=seller%40paypalsandbox.com&custom=xyz123+CUSTOMHASH&payment_date=12%3A40%3A25+27+Aug+2013+PDT&address_country_code=US&address_zip=95131&item_name1=something&mc_handling=2.06&mc_handling1=1.67&tax=2.02&address_name=John+Smith&last_name=Smith&receiver_id=seller%40paypalsandbox.com&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AgAAjEU7A5rthY2aP4j1jOIrjuGx&address_country=United+States&payment_status=Completed&address_status=confirmed&business=seller%40paypalsandbox.com&payer_email=buyer%40paypalsandbox.com¬ify_version=2.4&txn_type=cart&test_ipn=1&payer_status=unverified&mc_currency=USD&mc_gross=12.34&mc_shipping=3.02&mc_shipping1=1.02&item_number1=AK-1234&address_state=CA&mc_gross1=9.34&payment_type=instant&address_street=123%2C+any+street';
/*
* More detailed breakout of the raw data
_POST EXAMPLE ARRAY FROM PAYPAL:
Array
(
[residence_country] => US
[invoice] => abc1234
[address_city] => San Jose
[first_name] => John
[payer_id] => TESTBUYERID01
[mc_fee] => 0.44
[txn_id] => 421462822
[receiver_email] => seller@paypalsandbox.com
[custom] => xyz123 CUSTOMHASH
[payment_date] => 12:40:25 27 Aug 2013 PDT
[address_country_code] => US
[address_zip] => 95131
[item_name1] => something
[mc_handling] => 2.06
[mc_handling1] => 1.67
[tax] => 2.02
[address_name] => John Smith
[last_name] => Smith
[receiver_id] => seller@paypalsandbox.com
[verify_sign] => AFcWxV21C7fd0v3bYYYRCpSSRl31AgAAjEU7A5rthY2aP4j1jOIrjuGx
[address_country] => United States
[payment_status] => Completed
[address_status] => confirmed
[business] => seller@paypalsandbox.com
[payer_email] => buyer@paypalsandbox.com
[notify_version] => 2.4
[txn_type] => cart
[test_ipn] => 1
[payer_status] => unverified
[mc_currency] => USD
[mc_gross] => 12.34
[mc_shipping] => 3.02
[mc_shipping1] => 1.02
[item_number1] => AK-1234
[address_state] => CA
[mc_gross1] => 9.34
[payment_type] => instant
[address_street] => 123, any street
)
*/
//#
// PayPal IPN processor in PHP
// fake paypal post to test scripts
//#
//----------------------------------------------------------
// Create FAKE post from PayPal.
//----------------------------------------------------------
$req = $test; // use test data
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $paypal_url);
curl_setopt($ch,CURLOPT_POST, substr_count($req,'&')+1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $req);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
?>
我在本地主机上进行测试。您可以使用 dyn.com 或 noip.com 之类的服务,或者将子域指向您的本地地址(如果它是静态的)。
/ngrok http -host-header=yourwebsite.com 80
将使用正确的主机标头隧道到 localhost