你好,我正在使用其他人使用的代码,他们应该已经让它工作并且已经获得了他们的 token 信息。代码如下:
$ch = curl_init();
$clientId = "myclientid";
$secret = "mysecret";
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSLVERSION , 6); //NEW ADDITION
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $clientId.":".$secret);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
$result = curl_exec($ch);
if(empty($result))die("Error: No response.");
else
{
$json = json_decode($result);
print_r($json->access_token);
}
curl_close($ch); //THIS CODE IS NOW WORKING!
我从 Paypal API with PHP and cURL 中检索到此代码并且已经看到它在其他一些人的代码中实现,所以我认为它有效。但是,即使我提供了正确的客户端 ID 和密码,我也没有收到任何响应(也许最近的更新破坏了此代码?)。
Paypal 提供的获取访问 token 的指南可在此处找到-> https://developer.paypal.com/docs/integration/direct/make-your-first-call/ 但是它在 cURL 中演示了解决方案,而不是通过 PHP cURL 扩展,所以它对我来说有点神秘。有帮助吗?
最佳答案
好吧,现在似乎需要声明要使用的 SSL 版本类型,因此上面的代码将在 curl_setopt($ch, CURLOPT_SSLVERSION , 6); 时运行;//tlsv1.2
已插入。
关于php - Paypal 使用 PHP cURL 获取访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37262192/