ejlin/line-login-sdk-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ejlin/line-login-sdk-php

最新稳定版本:0.1.2

Composer 安装命令:

composer require ejlin/line-login-sdk-php

包简介

SDK of the LINE Login API for PHP

README 文档

README

SDK of the LINE Login API for PHP

Documentation

See the official API documentation for more information.

Installation

Use the package manager composer to install package.

composer require ejlin/line-login-sdk-php

Usage

###Pure PHP version:

$httpClient = new \EJLin\LINELogin\GuzzleHTTPClient();

// Channel Basic Information: https://developers.line.biz/console/channel/<channel id>/basics
$LINELogin = new \EJLin\LINELogin($httpClient, ['clientId' => '<channel id>','clientSecret' => '<channel secret>']);

// Step 3. After login, the LINE will redirect to the URL that you requested with state and code
if(isset($_GET['code']) && isset($_GET['state']))
{
    // TODO: Check the state code same as what you requested
    
    // Request access token from the LINE platform
    $token = $LINELogin->requestToken(
        'https://yourdomain.com', // The url must be the same as requested
        $_GET['code'] // Each code only can request a token once
    );
    
    // Get user profile from the LINE platform
    $userProfile = $LINELogin->getUserProfile($token);
    
    printf("Hello %s !",$userProfile->getDisplayName());
    
    exit;
}

// A unique alphanumeric string used to prevent cross-site request forgery
$state = \EJLin\LINELogin\Helper::randomString(40);

// Step 1. Make authorize url
$authorizeUrl = $LINELogin->makeAuthorizeUrl(
    'https://yourdomain.com', // Callback URL: https://developers.line.biz/console/channel/<channel id>/line-login
    'profile openid email', // Permissions requested from the user: https://developers.line.biz/en/docs/line-login/integrate-line-login/#scopes
    $state
);

// Step 2. Redirect to authorize url
header("Location: $authorizeUrl");
exit;

###Laravel support:

After installed, add LINE_LOGIN_CHANNEL_ID and LINE_LOGIN_CHANNEL_SECRET to .env

LINE_LOGIN_CHANNEL_ID=<channel id>
LINE_LOGIN_CHANNEL_SECRET=<channel secret>

then you can use LINELogin and LINELoginHelper facades like following.

// Step 3.
if(request()->has('code') && request()->has('state'))
{
    $token = \EJLin\Laravel\Facades\LINELogin::requestToken(
            url()->current(),
            request()->input('code'),
        );

    $userProfile = \EJLin\Laravel\Facades\LINELogin::getUserProfile($token);

    return "Hello {$userProfile->getDisplayName()} !";
}

$state = \EJLin\Laravel\Facades\LINELoginHelper::randomString(40);

// Step 1.
$authorizeUrl = \EJLin\Laravel\Facades\LINELogin::makeAuthorizeUrl(
    url()->current(),
    'profile openid email',
    $state
);

// Step 2.
return redirect()->away($authorizeUrl);

Reference

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

统计信息

  • 总下载量: 385
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-10-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固