File: /www/wwwroot//ly.kntsleep.com/c.php
<?php
$clientId = 'AfFNXBdfrl8X-oX9gStJHf7lsasYY5QP1TDTzENcYPXxPsmz_G6fLnZ3t2EvoLZlKO6IRFTJ9KQrBAYA';
$clientSecret ='EMz1kZwRKAKTl4UIiJ-VLCB7WlH0aw43aZd3SVeYG6fNjiQj7bCph9h-uBCinLsdI4v5ERs4lioNJnnX';
// $clientId = 'AVc0lwtgvNbMYa9N9jeWXn_dTIkiJxTQEJWl9I7TJCJ06j9gfqCBpRjpluhdHJuQ6UB_O6Y1nlgB1hKS';//yzy商户
// $clientSecret ='EKOPum4XFGuuRKuoJhD4GPtxVkxDUbUVPtue0T-yXKTTYgcnWRGPO7owxn-DIizGdCdYBW3YMdGvjhB0';
// 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: 发起查询请求
$url = 'https://api-m.paypal.com/v1/customer/disputes/?page_size=50';
$options = array(
'http' => array(
'header' => "Content-Type: application/json\r\n" .
"Authorization: Bearer " . $accessToken . "\r\n",
'method' => 'GET',
),
);
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
// echo $response;
$json = json_decode($response, true);
// 遍历纠纷记录并输出
foreach ($json['items'] as $item) {
echo "纠纷ID:" . $item['dispute_id'] . "<br>";
echo "创建时间:" . date('Y-m-d H:i:s', strtotime($item['create_time'])) . "<br>";
echo "纠纷金额:" . $item['dispute_amount']['value'] . " " . $item['dispute_amount']['currency_code'] . "<br>";
echo "原因:" . $item['reason'] . "<br>";
echo "状态:" . $item['status'] . "<br>";
echo "截止日期:" . date('Y-m-d H:i:s', strtotime($item['seller_response_due_date'])) . "<br>";
echo "详情链接:<a href=\"" . $item['links'][0]['href'] . "\">查看详情</a><br>";
echo "<br>";
}
?>