HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/ly.ydrbh.com/2.php
 
 
 
<?php



// $clientId = 'AZ5q35RRvAI9oU9ss-E4yRYVELSIaIcLpv_mmd4oPgv7WmvwJupJmzQaQXN2RTsEZgPNQhXmwzGx-D0z';
// $clientSecret = 'EOsd5viKcp8D9nd6JewX7tuqFLc6m-0wl4tmHNeHFu8Giwbw1Hf06rxLuDVRH1QJyJTtmg2VXH9-VEcO'; 
$clientId = 'AV215uV-cE-AZ9nd4dNWf24vzrj6UyvA3rA8FDGVW09Y531j9H3GO7FtJmphimXNwisgYNHFvW-6wYMo';
$clientSecret = 'EJb5xUSW8QtuPJeaHuOjAXl9WXp2kj4-zkym-7fXCBM-TssNhkK2FB1-iJOmxYsGcASO8zBTHaPRoJH_'; 
// PayPal API 认证 URL (沙盒环境)
$authUrl = "https://api.sandbox.paypal.com/v1/oauth2/token";

// 创建认证信息
$auth = base64_encode($clientId . ":" . $clientSecret);

// 初始化 cURL
$ch = curl_init();

// 设置 cURL 请求选项
curl_setopt($ch, CURLOPT_URL, $authUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Authorization: Basic $auth",
    "Content-Type: application/x-www-form-urlencoded"
]);

// 设置请求体
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");

// 执行 cURL 请求
$response = curl_exec($ch);
curl_close($ch);

// 解析响应并获取访问令牌
$data = json_decode($response, true);
$accessToken = $data['access_token']; 

 
 
// echo  $accessToken;
// Step 2: 发起查询请求
 $access_token = $accessToken;

// PayPal交易ID或交易码
$transaction_id = '2FP84762A6562791V'; // 替换成你的交易ID或交易码

// PayPal REST API endpoint
$api_url = 'https://api.sandbox.paypal.com/v1/payments/sale/' . $transaction_id;

// 构建请求
$options = array(
    'http' => array(
        'header' => "Authorization: Bearer " . $access_token . "\r\n" .
                    "Content-Type: application/json\r\n",
        'method' => 'GET'
    )
);

$context = stream_context_create($options);
$response = file_get_contents($api_url, false, $context);

if ($response === false) {
    die('Failed to fetch data from PayPal API');
}

// 解析响应
$data = json_decode($response, true);
echo $response;
if ($data === null) {
    die('Error parsing JSON');
}

// 提取支付价格
if (isset($data['amount']['total']) && isset($data['amount']['currency'])) {
    $total_amount = $data['amount']['total'];
    $currency = $data['amount']['currency'];
    echo "支付金额: $total_amount $currency";
   
} else {
    echo '未找到支付信息';
}