我一直在尝试使用Login with Paypal来验证卖家的电子邮件和帐户我们的网站。
##########################################################################################################
##########################################################################################################
##########################################################################################################
define("CLIENT_ID", $CLIENT_ID);
define("CLIENT_SECRET", $CLIENT_SECRET);
//define("URI_LIVE", "https://api.sandbox.paypal.com/v1/");
define("URI_LIVE", "https://api.paypal.com/v1/");
class paypal{
private $access_token;
private $token_type;
/**
* Constructor
*
* Handles oauth 2 bearer token fetch
* @link https://developer.paypal.com/webapps/developer/docs/api/#authentication--headers
*/
public function __construct($code=''){
$postvals = "grant_type=authorization_code&code=".$code."&redirect_uri=https://biddingblock.com/api/seller.htm";
$uri = URI_LIVE . "oauth2/token";
$auth_response = self::curl($uri, 'POST', $postvals, true);
$this->access_token = $auth_response['body']->access_token;
$this->token_type = $auth_response['body']->token_type;
}
///////////////////////////////////////////////////////////
public function getInfo(){
$uri = URI_SANDBOX . "identity/openidconnect/userinfo/?schema=openid";
return self::curl($uri, 'GET');
}
///////////////////////////////////////////////////////////
/**
* cURL
*
* Handles GET / POST requests for auth requests
* @link http://php.net/manual/en/book.curl.php
*/
private function curl($url, $method = 'GET', $postvals = null, $auth = false){
$ch = curl_init($url);
//if we are sending request to obtain bearer token
if ($auth){
$headers = array("Accept: application/json", "Accept-Language: en_US");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, CLIENT_ID . ":" .CLIENT_SECRET);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
//if we are sending request with the bearer token for protected resources
} else {
$headers = array("Content-Type:application/json", "Authorization:{$this->token_type} {$this->access_token}");
}
$options = array(
CURLOPT_HEADER => true,
CURLINFO_HEADER_OUT => true,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_VERBOSE => true,
CURLOPT_TIMEOUT => 10
);
if ($method == 'POST'){
$options[CURLOPT_POSTFIELDS] = $postvals;
$options[CURLOPT_CUSTOMREQUEST] = $method;
}
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
// showMe($response);
$header = substr($response, 0, curl_getinfo($ch,CURLINFO_HEADER_SIZE));
$body = json_decode(substr($response, curl_getinfo($ch,CURLINFO_HEADER_SIZE)));
curl_close($ch);
return array('header' => $header, 'body' => $body);
}
}
##########################################################################################################
##########################################################################################################
##########################################################################################################
showMe('We\'ve Got More Milk!');
showMe($_GET);
showMe('We\'ve Got Access!');
$code = $_GET['code'];
$z = new paypal($code);
showMe($z);
showMe('We\'ve Got Info!');
$zz = $z->getInfo();
showMe($zz);
这可以正确获取访问令牌,但是当我发送访问令牌以检索电子邮件和帐户状态时,它不会按要求返回电子邮件或帐户状态。
((当客户使用“我们网站上的PayPal登录信箱”时向客户披露)
感谢任何帮助。
答案 0 :(得分:0)
敏达,
我能看到的唯一问题是这一行:
$uri = URI_SANDBOX . "identity/openidconnect/userinfo/?schema=openid";
我没有看到URI_SANDBOX被声明,看起来你正在使用URI_LIVE进行现场测试。
更改此内容已解决了我的代码副本中的问题。