File: //www/wwwroot/ly.kntsleep.com/j.php
<?php
$clientId = 'AfFNXBdfrl8X-oX9gStJHf7lsasYY5QP1TDTzENcYPXxPsmz_G6fLnZ3t2EvoLZlKO6IRFTJ9KQrBAYA';
$clientSecret ='EMz1kZwRKAKTl4UIiJ-VLCB7WlH0aw43aZd3SVeYG6fNjiQj7bCph9h-uBCinLsdI4v5ERs4lioNJnnX';
$transactionId = '39890179N66412348';
// Step 1: 获取访问令牌(Access Token)
$tokenUrl = 'https://api.paypal.com/v1/oauth2/token';
$tokenData = http_build_query(array('grant_type' => 'client_credentials'));
$options = array(
'http' => array(
'header' => "Authorization: Basic " . base64_encode($clientId . ':' . $clientSecret) . "\r\n" .
"Content-Type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => $tokenData,
),
);
$context = stream_context_create($options);
$response = file_get_contents($tokenUrl, false, $context);
$tokenData = json_decode($response, true);
$accessToken = $tokenData['access_token'];
// echo $accessToken;
// Step 2: 发起查询请求
$disputes = 'PP-R-WPS-518964452';
$url = 'https://api-m.paypal.com/v1/customer/disputes/'.$disputes.'';
$access_token = $accessToken;
$options = array(
'http' => array(
'header' => "Content-Type: application/json\r\n" .
"Authorization: Bearer $access_token\r\n",
'method' => 'GET'
)
);
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
if ($response === FALSE) {
echo "Error fetching data";
} else {
echo $response;//可以输出很多的结果
}
$jsonData = json_decode($response, true);
// 获取所需数据
$seller_transaction_id = $jsonData['disputed_transactions'][0]['seller_transaction_id'];
$transaction_status = $jsonData['disputed_transactions'][0]['transaction_status'];
$name = $jsonData['disputed_transactions'][0]['buyer']['name'];
// 输出结果
echo "交易码: $seller_transaction_id\n";
echo "结果: $transaction_status\n";
echo "客户名字: $name\n";
?>