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/3.php
<?php
// PayPal API凭证

 
// 获取 PayPal Access Token
function getPaypalAccessToken($clientId, $secret) {
    $url = "https://api.sandbox.paypal.com/v1/oauth2/token";
    
    // 初始化 cURL
    $ch = curl_init();
    
    // 设置请求头和请求数据
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_USERPWD, $clientId . ":" . $secret);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
    
    // 执行请求
    $response = curl_exec($ch);
    curl_close($ch);
    
    // 解析响应
    $response = json_decode($response, true);
    
    return $response['access_token'] ?? null;
}

// 创建支付
function createPaypalPayment($accessToken, $orderId, $cardDetails) {
    $url = "https://api.sandbox.paypal.com/v1/payments/payment";
    
    // 设置请求头
    $headers = [
        "Authorization: Bearer $accessToken",
        "Content-Type: application/json"
    ];
    
    // 创建支付请求数据
    $data = [
        "intent" => "sale",
        "payer" => [
            "payment_method" => "credit_card",
         
            
              "funding_instruments" => [
            [
                "credit_card" => [
                    "type" => "visa",
                    "number" => "4111111111111111",
                    "expire_month" => "12",
                    "expire_year" => "2025",
                    "cvv2" => "123",
                    "first_name" => "John",
                    "last_name" => "Doe"
                ]
            ]
        ]
       
        ],
        "transactions" => [
            [
                "amount" => [
                    "total" => $cardDetails['amount'],  // 支付金额
                    "currency" => "USD"  // 支付货币
                ],
                "description" => "Order #$orderId"
            ]
        ]
    ];
    
    // 初始化 cURL
    $ch = curl_init();
    
    // 设置请求
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    
    // 执行请求
    $response = curl_exec($ch);
    curl_close($ch);
    
    // 解析响应
    $response = json_decode($response, true);
    
    return $response;
}

// 设置 PayPal 沙盒的客户端ID和Secret
 
$clientId = 'AV215uV-cE-AZ9nd4dNWf24vzrj6UyvA3rA8FDGVW09Y531j9H3GO7FtJmphimXNwisgYNHFvW-6wYMo';
$secret = 'EJb5xUSW8QtuPJeaHuOjAXl9WXp2kj4-zkym-7fXCBM-TssNhkK2FB1-iJOmxYsGcASO8zBTHaPRoJH_';

// 获取 PayPal 访问令牌
$accessToken = getPaypalAccessToken($clientId, $secret);

// 假设的订单信息和信用卡信息
$orderId = "123456789";  // 假设订单ID
$cardDetails = [
    'type' => 'visa',  // 信用卡类型 (visa, mastercard, etc.)
    'number' => '4111111111111111',  // 信用卡号
    'expire_month' => '12',  // 到期月份
    'expire_year' => '2025',  // 到期年份
    'cvv' => '123',  // CVV
    'first_name' => 'John',  // 名字
    'last_name' => 'Doe',  // 姓氏
    'amount' => '10.00'  // 支付金额 (USD)
];

// 调用 PayPal API 创建支付
$paymentResponse = createPaypalPayment($accessToken, $orderId, $cardDetails);

// 处理响应
if (isset($paymentResponse['state']) && $paymentResponse['state'] == 'approved') {
    // 成功支付,输出交易ID
    $transactionId = $paymentResponse['transactions'][0]['related_resources'][0]['sale']['id'];
    echo "支付成功,交易ID:$transactionId";
} else {
    // 失败,输出错误信息
    echo "支付失败,原因:";
    echo isset($paymentResponse['message']) ? $paymentResponse['message'] : "未知错误";
}
?>