在PHP中使用restapi进行Paypal支付

在PHP中使用restapi进行Paypal支付,php,curl,paypal,Php,Curl,Paypal,我不清楚如何将这个代码示例放入PHP的CURL结构,特别是-d句柄 curl -v https://api.sandbox.paypal.com/v1/payments/payment \ -H 'Content-Type:application/json' \ -H 'Authorization:Bearer EOjEJigcsRhdOgD7_76lPfrr45UfuI43zzNzTktUk1MK' \ -d '{ "intent":"sale", "redirect_urls":{

我不清楚如何将这个代码示例放入PHP的CURL结构,特别是-d句柄

curl -v https://api.sandbox.paypal.com/v1/payments/payment \
-H 'Content-Type:application/json' \
-H 'Authorization:Bearer EOjEJigcsRhdOgD7_76lPfrr45UfuI43zzNzTktUk1MK' \
-d '{
  "intent":"sale",
  "redirect_urls":{
    "return_url":"http://<return URL here>",
    "cancel_url":"http://<cancel URL here>"
  },
  "payer":{
    "payment_method":"paypal"
  },
  "transactions":[
    {
      "amount":{
        "total":"7.47",
        "currency":"USD"
      },
      "description":"This is the payment transaction description."
    }
  ]
}'

试着这样做,-d是您要发布的数据。自定义标头使用CURLOPT_HTTPHEADER设置

$data = '{
  "intent":"sale",
  "redirect_urls":{
    "return_url":"http://<return URL here>",
    "cancel_url":"http://<cancel URL here>"
  },
  "payer":{
    "payment_method":"paypal"
  },
  "transactions":[
    {
      "amount":{
        "total":"7.47",
        "currency":"USD"
      },
      "description":"This is the payment transaction description."
    }
  ]
}';

curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payment");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  "Content-Type: application/json",
  "Authorization: Bearer EOjEJigcsRhdOgD7_76lPfrr45UfuI43zzNzTktUk1MK", 
  "Content-length: ".strlen($data))
);
$data='1!'{
“意图”:“出售”,
“重定向URL”:{
“返回url”:“http://”,
“取消url”:“http://”
},
“付款人”:{
“付款方式”:“贝宝”
},
“交易”:[
{
“金额”:{
“总计”:“7.47”,
“货币”:“美元”
},
“说明”:“这是付款交易说明。”
}
]
}';
curl_setopt($ch,CURLOPT_URL,”https://api.sandbox.paypal.com/v1/payments/payment");
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
curl_setopt($ch,CURLOPT_HTTPHEADER,数组(
“内容类型:应用程序/json”,
“授权:持有人EOjEJigcsRhdOgD7_76lPfrr45UfuI43zzNzTktUk1MK”,
“内容长度:”.strlen($data))
);
看看这里的选项,
设置curl_setopt($ch,CURLOPT_头,false);例如,如果您不需要返回标题。

这是一个完整的解决方案吗?我没有得到回应。我将授权更改为从代码中检索到的类型和访问令牌,与第一个示例中的非常相似。它给出错误:无响应。它只给出0响应…请为那些得到错误:无响应的人建议正确的代码。如果您使用的是旧的php版本,它将无法工作,因为OpenSSL握手问题。我只是用PHP5.3.x进行测试,切换到PHP5.6.28版本后它就不工作了,因为它有一个更新的OpenSSL版本……。即使你使用curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);对我来说还是不行。谢谢
$data = '{
  "intent":"sale",
  "redirect_urls":{
    "return_url":"http://<return URL here>",
    "cancel_url":"http://<cancel URL here>"
  },
  "payer":{
    "payment_method":"paypal"
  },
  "transactions":[
    {
      "amount":{
        "total":"7.47",
        "currency":"USD"
      },
      "description":"This is the payment transaction description."
    }
  ]
}';

curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payment");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  "Content-Type: application/json",
  "Authorization: Bearer EOjEJigcsRhdOgD7_76lPfrr45UfuI43zzNzTktUk1MK", 
  "Content-length: ".strlen($data))
);