我有一个无法解决的问题。我正在尝试在wordpress上创建一个应用程序,当用户访问页面时,它将自动要求用户使用paypal帐户登录和验证。成功登录后,我想显示配置文件详细信息(首先仅用于测试),然后再次对其进行编码以用于预期用途。但是,我使用下面的代码,当我成功登录时,进行身份验证并重定向到redirect_url
(意味着登录和验证过程正确完成),print_r
的预期配置文件详细信息为空
<?php
/* Paypal app details */
$client_id = 'xxxx'; // paypal client id
$client_secret = 'xxx'; // client secret
$scopes = 'email profile'; //e.g. openid email profile https://uri.paypal.com/services/paypalattributes
$app_return_url = 'http://website.ccc/verify/'; // Redirect url
$nonce = time() . rand();
$code = $_REQUEST["code"];
if(empty($code)) {
#IF the code paramater is not available, load the auth url.
$state = md5(uniqid(rand(), TRUE)); // CSRF protection
$paypal_auth_url = "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize?"
."client_id=".$client_id
."&response_type=code"
."&scope=".$scopes
."&nonce=".$nonce
."&state=".$state
."&redirect_uri=".urlencode($app_return_url);
header("Location: $paypal_auth_url");
}else{
/* GET Access TOKEN */
$token_url = "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/tokenservice";
$postvals = "client_id=".$client_id
."&client_secret=".$client_secret
."&grant_type=authorization_code"
."&code=".$code;
$ch = curl_init($token_url);
$options = array(
CURLOPT_POST => 1,
CURLOPT_VERBOSE => 1,
CURLOPT_POSTFIELDS => $postvals,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSLVERSION => 3
);
curl_setopt_array( $ch, $options );
$response = curl_exec($ch);
curl_close($ch);
$atoken = json_decode($response);
/* GET PROFILE DETAILS */
$profile_url = "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/userinfo?"
."schema=openid"
."access_token=".$atoken->access_token;
$ch = curl_init($profile_url);
$options = array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSLVERSION => 3
);
curl_setopt_array( $ch, $options );
$response = curl_exec($ch);
curl_close($ch);
$profile= json_decode($response,true); // PROFILE DETAILs in Array format
/* View the Profile Details */
echo "<pre>";
print_r($profile);
echo "</pre>";
}
?>
你能帮我解决这个问题吗?
答案 0 :(得分:2)
你好朋友只需添加'&amp;'在访问令牌之前,
$ profile_url =“https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/userinfo?” “模式= OpenID的” “**&安培; ** =的access_token” $ atoken-&GT;的access_token;