justauthme/php-sdk

JustAuthMe平台的官方PHP SDK

1.1.2 2021-02-21 19:46 UTC

This package is auto-updated.

Last update: 2024-09-22 04:02:40 UTC


README

内容

  1. 安装
  2. 用法
    1. 实例化SDK
    2. 显示登录链接
      1. 使用默认按钮
      2. 使用自定义链接
    3. 从您的回调中获取用户信息
  3. 完整文档
  4. 故障排除

安装

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方法接受两个参数:langsize。您可以选择fren语言,以及x1x2x4尺寸。

默认langen,默认sizex2

<?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

故障排除

如果出现任何问题,请随时在此仓库中打开一个问题,我们将很高兴为您提供帮助。