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/备份的/jf.cwoyt.com/2.php
 
 
<?php
 
$clientId = 'AV215uV-cE-AZ9nd4dNWf24vzrj6UyvA3rA8FDGVW09Y531j9H3GO7FtJmphimXNwisgYNHFvW-6wYMo';
$clientSecret = 'EJb5xUSW8QtuPJeaHuOjAXl9WXp2kj4-zkym-7fXCBM-TssNhkK2FB1-iJOmxYsGcASO8zBTHaPRoJH_';
// PayPal OAuth2 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, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Basic ' . $auth,
    'Content-Type: application/x-www-form-urlencoded'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");

// 执行请求并获取响应
$response = curl_exec($ch);

// 关闭 cURL 连接
curl_close($ch);

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

// 检查是否成功获取访问令牌
if (isset($responseData['access_token'])) {
    $accessToken = $responseData['access_token'];
} else {
    echo "Error: " . $responseData['error_description'];
    exit;
}

$paymentData = [
    'intent' => 'sale', // 交易类型
    'payer' => [
        'payment_method' => 'credit_card', // 使用信用卡
        'funding_instruments' => [
            [
                'credit_card' => [
                    'type' => 'visa', // 卡片类型,支持 visa, mastercard 等
                    'number' => '4111111111111111', // 沙盒环境信用卡号
                    'expire_month' => 12, // 到期月份
                    'expire_year' => 2025, // 到期年份
                    'cvv2' => '123', // 卡片 CVV2
                    'first_name' => 'John',
                    'last_name' => 'Doe',
                    'billing_address' => [
                        'line1' => '123 Main St',
                        'city' => 'San Jose',
                        'state' => 'CA',
                        'postal_code' => '95131',
                        'country_code' => 'US'
                    ]
                ]
            ]
        ]
    ],
    'transactions' => [
        [
            'amount' => [
                'total' => '100.00', // 支付金额
                'currency' => 'USD'
            ],
            'description' => 'Payment for product/service'
        ]
    ]
];

// PayPal 沙盒支付创建接口
$paymentUrl = "https://api.sandbox.paypal.com/v1/payments/payment";

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

// 设置 cURL 请求的选项
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));

// 执行请求并获取响应
$response = curl_exec($ch);
curl_close($ch);

// 解析响应数据
$responseData = json_decode($response, true);

// 处理支付结果
if (isset($responseData['state']) && $responseData['state'] == 'approved') {
    echo "Payment Successful! Payment ID: " . $responseData['id'];
} else {
    echo "Payment failed. Error: " . $responseData['message'];
}