gpt4 book ai didi

php - Paypal 单笔支付 - 'Json request malformed'

转载 作者:太空宇宙 更新时间:2023-11-03 15:54:37 25 4
gpt4 key购买 nike

我正在尝试使用 Paypal 沙盒进行单笔付款。我得到的错误是:

'MALFORMED_REQUEST_ERROR' - 'Json request malformed.'

成功收到 token 后,我设置了单笔付款明细数组并对 json 进行编码,然后使用 curl 发布它,但没有成功。代码如下:

if ($token) {
$ch = curl_init();

$data = [
'sender_batch_header' => [
'email_subject' => "You have a payment",
'sender_batch_id' => '184328423'
],
'items' => [
'recipient_type' => "EMAIL",
'amount' => [
'value' => 12.00,
'currency' => "USD"
],
'receiver' => 'test123test@hotmail.com',
'note' => 'Hello World',
'sender_item_id' => "123"
],
];


$headers = [
'Content-Type:application/json',
'Authorization:Bearer ' . $token,
];



curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payouts?sync_mode=true");
// curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

$result = curl_exec($ch);

if(empty($result))die("Error: No response.");
else
{
$json = json_decode($result);
print_r($json);
}

curl_close($ch);

}

最佳答案

我花了一些时间才注意到它。答案:

$data = [
'sender_batch_header' => [
'email_subject' => "You have a payment",
'sender_batch_id' => $randId

],
'items' => [
[
'recipient_type' => "EMAIL",
'amount' => [
'value' => "12.00",
'currency' => "USD"
],
'receiver' => 'test123test@hotmail.com',
'note' => 'Hello World',
'sender_item_id' => "A123"
],
],
];

关于php - Paypal 单笔支付 - 'Json request malformed',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39682740/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com