justauthme / php-sdk
JustAuthMe平台的官方PHP SDK
1.1.2
2021-02-21 19:46 UTC
Requires
- php: >=7.1.0
- ext-json: *
README
内容
安装
composer require justauthme/php-sdk
用法
1. 实例化SDK
<?php use JustAuthMe\SDK\JamSdk; /* * Params: * @string app_id The app_id provided by the developers console * @string redirect_url The callback URL your provided at your app creation * @string api_secret The secret delivered to you by the developers console */ $jamSdk = new JamSdk($app_id, $redirect_url, $api_secret);
2. 显示登录链接
2.1 使用默认按钮(已弃用)
请参阅官方按钮仓库的完整文档:https://github.com/justauthme/button
generateDefaultButtonHtml方法接受两个参数:lang和size。您可以选择fr和en语言,以及x1、x2和x4尺寸。
默认lang为en,默认size为x2。
<?php /* DEPRECATED */ echo $jamSdk->generateDefaultButtonHtml($lang, $size); ?>
2.2 使用自定义链接
<a href="<?php echo $jamSdk->generateLoginUrl(); ?>">Login with JustAuthMe</a>
3. 从您的回调中获取用户信息:redirect_url
<?php use JustAuthMe\SDK\JamSdk; if (isset($_GET['access_token'])) { // The expected access_token is present $jamSdk = new JamSdk($app_id, $redirect_url, $api_secret); try { $user_infos = $jamSdk->getUserInfos($_GET['access_token']); /* * Everything is fine, you can now register or login the user, * depending on the presence in your Database of * the provided $user_infos->jam_id */ } catch (Exception $e) { error_log($e->getMessage()); // Login fail, you should redirect to an error page } } else { /* * The callback URL wasn't called with the correct parameter * you should redirect to an error page */ }
完整文档
有关此SDK的完整文档,请参阅DOCUMENTATION.md
故障排除
如果出现任何问题,请随时在此仓库中打开一个问题,我们将很高兴为您提供帮助。