以下是我正在使用的代码:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->paypal_url);
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: ' . $url_parsed['host']));
$res = curl_exec($ch);
curl_close($ch);
this-> paypal_url是sandbox api url,url_parsed ['host']是沙盒paypal主机名这些都是正确的,但我遇到的问题是每次调用$ res总是为空。
在从paypal开发者网站获取此代码之前,我使用了以下代码:
$fp = fsockopen('ssl://' . $url_parsed['host'],"443",$err_num,$err_str,30);
fputs($fp, "POST $url_parsed[path] HTTP/1.1\r\n");
fputs($fp, "Host: $url_parsed[host]\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ".strlen($post_string)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $post_string . "\r\n\r\n");
并且无法打开套接字错误。
在使用ssl之前我使用的是以下代码: $ fp = fsockopen($ url_parsed ['host'],“80”,$ err_num,$ err_str,30);
我收到了这个回复:
Server:
HTTP/1.0 302 Moved Temporarily
Location: https://www.sandbox.paypal.com
Server: BigIP
Content-Length: 0
X-Cache: MISS from proxyco.confiz.com
X-Cache-Lookup: MISS from proxyco.confiz.com:3128
Via: 1.0 proxyco.confiz.com:3128 (squid/2.6.STABLE21)
Connection: close
请帮我找到解决方案。
答案 0 :(得分:0)
希望以下链接可以帮助您..
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_admin_IPNIntro
下载示例代码
https://www.x.com/developers/PayPal/documentation-tools/code-sample/216623
IPN Listner非常有用且易于集成