我正在尝试使用我的PayPal API凭据获取访问令牌,这是代码
<?php
class PayPalAPI
{
private $sandbox = true;
private $url;
private $clientid;
private $secret;
private $data;
public function __construct($sbox = true)
{
$this->url['sandbox'] = "https://api.sandbox.paypal.com";
$this->url['live'] = "https://api.paypal.com";
$this->clientid['sandbox'] = "secretsandboxclientid";
$this->clientid['live'] = "secretliveclientid";
$this->secret['sandbox'] = "secretsandboxkey";
$this->secret['live'] = "secretlivekey";
$this->sandbox = $sbox;
if ($this->sandbox == true)
{
$this->url['use'] = $this->url['sandbox'];
$this->clientid['use'] = $this->clientid['sandbox'];
$this->secret['use'] = $this->secret['sandbox'];
}
else
{
$this->url['use'] = $this->url['live'];
$this->clientid['use'] = $this->clientid['live'];
$this->secret['use'] = $this->secret['live'];
}
}
public function getAccessToken()
{
$ch = curl_init($this->url['use'] + "/v1/oauth2/token");
curl_setopt($ch, CURLOPT_ENCODING, "Accept: application/json");
curl_setopt($ch, CURLOPT_ENCODING, "Accept-Language: en_US");
curl_setopt($ch, CURLOPT_USERPWD, $this->clientid['use'] . ":" . $this->secret['use']);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
}
$api = new PayPalAPI();
$token = $api->getAccessToken();
var_dump($token);
?>
但是回应并不像预期的那样,出于某种原因,它正在倾倒神父#34;这是一个很酷的未来&#34;
以下是链接http://xlagmasterx.com/test.php
为什么这会返回页面?