我在我的网页中集成了 PayPal 的 Identity API。像往常一样,当用户点击时login with paypal
(JavaScript 按钮 https://developer.paypal.com/webapps/developer/docs/integration/direct/identity/button-js-builder/)它会打开一个新窗口用于登录。但在有效登录后,它会将我重定向到同一个弹出窗口。
注:我将我的域名替换为domain
应用程序返回 URL(测试): http://domain.esy.es/index.php/users/paypalidentity http://domain.esy.es/index.php/users/paypalidentity
View
//url http://domain.esy.es/index.php
<span id="paypalButton"></span>
<script src="https://www.paypalobjects.com/js/external/api.js"></script>
<script>
paypal.use( ["login"], function(login) {
login.render ({
"appid": MYAPPID,
"authend": "sandbox",
"scopes": "openid email profile address phone https://uri.paypal.com/services/paypalattributes",
"containerid": "paypalButton",
"locale": "en-us",
"returnurl": "http://domain.esy.es/index.php/users/paypalidentity"
});
});
</script>
控制器
//url http://domain.esy.es/index.php/users/paypalidentity
require_once __DIR__ . '/../../vendor/autoload.php';
$apicontext = new PPApiContext(array('mode' => 'sandbox'));
$code = $_REQUEST['code'];
$apicontext = new PPApiContext(array('mode' => 'sandbox'));
$params = array(
'client_id' => MYCLIENTID,
'client_secret' => MYSECRET,
'code' => $code
);
$token = PPOpenIdTokeninfo::createFromAuthorizationCode($params,$apicontext);
$apicontext = new PPApiContext(array('mode' => 'sandbox'));
$params = array('access_token' => $token->getAccessToken());
$user = PPOpenIdUserinfo::getUserinfo($params,$apicontext);
$this->session->set_userdata(
array(
'name'=>$user->getName()
)
);
redirect(base_url());
Successful Login
![enter image description here](https://i.stack.imgur.com/Sh0hO.jpg)
Redirecting to the configured redirect URL
![enter image description here](https://i.stack.imgur.com/QFC2B.jpg)