以下是我正在使用的代码:
$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 是沙盒 api url, url_parsed['host'] 是沙盒 paypal 主机名,这两者都是正确的,但我遇到的问题是每次调用 $res 始终为空。
在从贝宝开发者网站获取此代码之前,我使用了以下代码:
$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
请帮我找到解决方案。