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/备份的/www.ydrbh.com/1.php
<?php
// PayPal认证信息
$clientId = 'AZ5q35RRvAI9oU9ss-E4yRYVELSIaIcLpv_mmd4oPgv7WmvwJupJmzQaQXN2RTsEZgPNQhXmwzGx-D0z';  // 在PayPal开发者平台上获取
$clientSecret = 'EOsd5viKcp8D9nd6JewX7tuqFLc6m-0wl4tmHNeHFu8Giwbw1Hf06rxLuDVRH1QJyJTtmg2VXH9-VEcO';  // 在PayPal开发者平台上获取
 

 
 

// 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'];
// PayPal的支付创建 API URL
$paymentUrl = 'https://api.sandbox.paypal.com/v1/payments/payment';

// 构建支付请求数据
$paymentData = [
    'intent' => 'sale',
    'payer' => [
        'payment_method' => 'paypal'
    ],
    'transactions' => [
        [
            'amount' => [
                'total' => '10.00',
                'currency' => 'USD'
            ],
            'description' => 'Test payment'
        ]
    ],
    'redirect_urls' => [
        'return_url' => 'http://your-website.com/return',
        'cancel_url' => 'http://your-website.com/cancel'
    ]
];

 
// 设置 cURL 请求
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $paymentUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer ' . $accessToken,
    'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($paymentData));

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

// 解析响应
$data = json_decode($response, true);

if (isset($data['error'])) {
    // 错误处理
    echo 'Error: ' . $data['error']['message'];
} else {
    // 提取支付链接
    $approvalUrl = null;
    foreach ($data['links'] as $link) {
        if ($link['rel'] == 'approval_url') {
            $approvalUrl = $link['href'];
            break;
        }
    }

    if ($approvalUrl) {
        echo "Redirect the user to: " . $approvalUrl;
    } else {
        echo "Error: No approval URL found.";
    }
}