Paypal"使用"登录整合redirect_uri错误

时间:2015-04-26 20:00:06

标签: php login paypal

我在我的网站上整合了登录和PayPal,但我总是出现错误信息:

  

依赖方验证错误:请求中提供的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 = \Httpful\Request::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 = \Httpful\Request::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中配置了相同的返回网址,我还在paypal应用程序中配置了返回网址:

  • 登录developer.paypal.com
  • 点击应用
  • 在My Rest Apps下点击您的应用名称
  • 点击“应用重定向网址
  • 旁边的修改”
  • 将实时或测试的返回网址设置为&#34; MY_RETURN_URL / result.php&#34;
  • 在&#34下配置范围;使用paypal&#34;
  • 登录
  • 保存

我还为沙盒和实时应用设置了相同的网址,并在此网站中创建了一个新的应用: https://medium.com/@bartriepe/log-in-with-paypal-a-fractal-of-bad-design-58ce19939a9d

问题出在哪里?这是一个paypal错误吗?

谢谢你的帮助。

0 个答案:

没有答案