gpt4 book ai didi

php - 使用 Paypal 登录 API 集成的成功 Paypal 登录返回预期数据为空

转载 作者:太空宇宙 更新时间:2023-11-03 16:18:44 25 4
gpt4 key购买 nike

我有一个我无法解决的问题。我正在尝试在 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>";
}

?>

你能帮我挖掘一下吗?

最佳答案

嗨, friend ,只需在访问 token 前添加“&”,

$profile_url = "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/userinfo ?" ."schema=openid" ."**&**access_token=".$atoken->access_token;

关于php - 使用 Paypal 登录 API 集成的成功 Paypal 登录返回预期数据为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21968913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com