gpt4 book ai didi

php - 为什么这个 php 代码显示 json 数组而没有代码来显示它?

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

<?php

function pay()
{
$data = '
{
"intent":"sale",

"redirect_urls":
{
"return_url":"http://n1.lchs-is.org",
"cancel_url":"http://n1.lchs-is.org"
},

"payer":
{
"payment_method":"paypal"
},

"transactions":
[
{
"amount":
{
"total":"7.47",
"currency":"USD"
},

"description":"This is the payment transaction description."
}
]
}
';


//Start curl request
$ch = curl_init();

//Set curl options
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 A101.lTxNCRX3B-vhQIN4991wdthA6SzCtPKganKXVOZta84hADs-25S5OGk4yyG-HLzR.lM-rDOIJAaEXGWhcYi2YF8yhnRy",
));

//Display results
$json = curl_exec($ch); // <------- It's displaying this array that it receives from curl right here
curl_close($ch);
}
pay();

?>

我编写了这段 PHP 代码来简单地创建一个 paypal 支付,当我运行它时,它显示 JSON 数组,即使我没有编写它。为什么会这样,我该如何解决?

此外,我在执行 pay() 函数后键入的任何代码都不会执行。例如,如果我输入 echo "test"; 那行代码不会被执行。

最佳答案

您可能需要设置 CURLOPT_RETURNTRANSFER

例如

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // Store value in string $response below
$response = curl_exec($curl); //execute and get the results

关于php - 为什么这个 php 代码显示 json 数组而没有代码来显示它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33443681/

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