贝宝“登录”整合重定向
我正在将我的网站上的登录与贝宝集成在一起,但我一直都会输出错误消息:
依赖方验证错误:请求中提供的redirect_uri与注册的redirect_uri不匹配。 请检查请求。
我认为我做的都对,我已经使用了这个例子:http://www.sitepoint.com/implement-user-log-paypal/以及“www.formget.com/paypal-oauth/”
的index.php
<script src="https://www.paypalobjects.com/js/external/api.js"></script>
<script>
paypal.use( ["login"], function(login) {
login.render ({
"appid": "MY_APP_ID",
//"authend": "sandbox",
"scopes": "profile email https://uri.paypal.com/services/paypalattributes",
"containerid": "myContainer",
"locale": "en-us",
"returnurl": "<?php echo('http://'.$_SERVER['HTTP_HOST'].preg_replace('/index.php/','result.php',$_SERVER['SCRIPT_NAME']))?>"
});
});
</script>
result.php
<?php require('paypal_login_inc.php') ?>
<!DOCTYPE html>
<html>
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<title>Login with PayPal - Demo App</title>
<style type="text/css">
body {
text-align: center;
padding:20px;
}
</style>
</head>
<body>
<h1>Login with PayPal - Demo App</h1>
<p>Great! Now you are a member of our site.</p>
<hr/>
<h2>Your Data</h2>
<p><b>Name:</b> <?php echo htmlspecialchars_decode($user->given_name . ' ' . $user->family_name); ?></p>
<p><b>Address:</b> <?php echo htmlspecialchars_decode($user->address->street_address . ', ' . $user->address->locality); ?></p>
<hr/>
<p><button class="btn btn-success form-control" type="button" onclick="window.close()">Ok, done.</button></p>
</body>
</html>
paypal_login_inc.php
<?php
include('./httpful.phar');
// helper package autoload.
require __DIR__ . '/PayPal-PHP-SDK/autoload.php';
// setting some variables here.
$clientId = 'MY_APP_ID';
$clientSecret = 'MY_SECRET_ID';
$requestData = '?grant_type=authorization_code&code='.$_GET['code'].'&return_url=http://MY_RETURN_URL/result.php';
// here we exchange the authorization code with access and refresh tokens. api.sandbox
$response = HttpfulRequest::get('https://api.paypal.com/v1/identity/openidconnect/tokenservice' . $requestData)
->authenticateWith($clientId, $clientSecret)
->send();
$jsonResponse = json_decode($response->raw_body);
// checking out for errors.
if(isset($jsonResponse->error))
{
die('Error: just got some problems during operations. Try again.');
}
// getting user data, using the Identity APIs. api.sandbox
$response = HttpfulRequest::get('https://api.paypal.com/v1/identity/openidconnect/userinfo/?schema=openid')
->contentType("application/json")
->authorization($jsonResponse->access_token)
->authenticateWith($clientId, $clientSecret)
->send();
// user data is here!
$user = json_decode($response->raw_body);
?>
我在index.php和paypal_login_inc.php中配置了相同的返回url,我还在paypal应用程序中配置了返回url:
我还为沙盒和实时应用程序设置了相同的网址,并在此网站中创建一个新应用程序:https://medium.com/@bartriepe/log-in-with-paypal-a-fractal-of-bad-设计58ce19939a9d
那么问题在哪里? 它是一个贝宝错误?
感谢您的帮助。
链接地址: http://www.djcxy.com/p/90385.html