我正在尝试使用 php 创建贝宝付款。我不断收到 400 格式错误的请求错误。我相信我的问题在于以下字符串:
$postData ='
{
"intent": "sale"
"redirect_urls": {
"return_url": ' . $url_success .',
"cancel_url": ' . $url_cancel .'
},
"payer": {
"payment_method": "paypal"
},
"transactions": [
{
"amount": {
"total": "' . $saleTotal .'",
"currency": "USD"
},
"description": "Test payment."
}
]
}
';
然后我在以下行中使用 cURL 发送字符串
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
这是我打印出来的字符串:
{ "intent": "sale" "redirect_urls": { "return_url":
"http://localhost/~user/test/controller/PayPalTestView.php", "cancel_url":
"http://localhost/~user/test/controller/CancelTestView.php" }, "payer": {
"payment_method": "paypal" }, "transactions": [ { "amount": { "total": "8.31782",
"currency": "USD" }, "description": "Test payment." } ] }
这是我得到的回复:
{"name":"MALFORMED_REQUEST","message":"The request JSON is not well
formed.","information_link":
"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST",
"debug_id":"7d56ae815e584"}
我很确定问题出在 $postData 中,尽管我不知道出了什么问题。我尝试按照以下示例进行操作:Paypal REST API Bad Request,但它仍然无法正常工作。我的问题与该示例类似,因为我正在成功发送和接收身份验证令牌。我的问题只是在尝试发送支付 API 调用时。有谁看到我做错了什么?谢谢!