yii-slack:在 Yii 框架中通过 Guzzle 访问 Slack API 的扩展

  • o0_847300
    了解作者
  • 6.2KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-13 04:42
    上传日期
Yii Slack 扩展 Yii 扩展,用于通过 Guzzle 访问 Yii 框架中的 Slack API。 安装 Yii Slack是作曲家库,因此您可以通过以下方式安装最新版本: php composer.phar require tatarko/yii-slack 配置 在您的应用程序配置中添加以下内容: 'components' => array ( 'slack' => array ( 'class' => 'Tatarko\\YiiSlack\\ApplicationComponent' , 'appId' => '' , // Your's application ID 'appSecret' => '' , // Your's application secret code 'tokenStateName' => 'slack.access.toke
yii-slack-master.zip
  • yii-slack-master
  • composer.json
    791B
  • LICENSE
    1.1KB
  • src
  • ApplicationComponent.php
    4.4KB
  • AuthenticationAction.php
    4.9KB
  • .gitignore
    23B
  • README.md
    2.7KB
内容介绍
# Yii Slack extension Yii extension for accessing Slack API in Yii framework via Guzzle. [![Latest Stable Version](https://poser.pugx.org/tatarko/yii-slack/v/stable.png)](https://packagist.org/packages/tatarko/yii-slack) [![Code Climate](https://codeclimate.com/github/tatarko/yii-slack/badges/gpa.png)](https://codeclimate.com/github/tatarko/yii-slack) ## Installation **Yii Slack** is composer library so you can install the latest version with: ```shell php composer.phar require tatarko/yii-slack ``` ## Configuration To your application's config add following: ```php 'components' => array( 'slack' => array( 'class' => 'Tatarko\\YiiSlack\\ApplicationComponent', 'appId' => '', // Your's application ID 'appSecret' => '', // Your's application secret code 'tokenStateName' => 'slack.access.token'; // optional - change name of the user's state variable to store access token in 'companyToken' => '', // optional - set global access token of your company's account to use slack component without user authentication ), ) ``` For OAuth authentication add following method to the controller: ```php class SiteController extends Controller { public function actions() { return array( 'slack' => array( 'class' => 'Tatarko\\YiiSlack\\AuthenticationAction', 'onAuthSuccess' => function(CEvent $event) { // you can get $event->params->access_token and store it in some persistant database instead of user's states (that is basically sessions variable) $this->redirect('welcome'); }, 'onAuthError' => function(CEvent $event) { // $event->params is instance of Exception (CException or GuzzleHttp\Exception\TransferException) $this->redirect('login'); }, ), ); } } ``` ## Usage For simple OAuth just create link in any view file: ```php <a href="<?= $this- rel='nofollow' onclick='return false;'>createUrl('site/slack') ?>">Login with Slack</a> ``` After that you can check if current web user is logged using Slack by calling: ```php var_dump(Yii::app()->slack->isAuthenticated); // boolean ``` And in case that user is really authenticated you can make API call like: ```php var_dump(Yii::app()->slack->get('auth.test')); ``` That prints something likes: ```shell array(6) { 'ok' => bool(true) 'url' => string(25) "https://myteam.slack.com/" 'team' => string(7) "My Team" 'user' => string(3) "cal" 'team_id' => string(6) "T12345" 'user_id' => string(6) "U12345" } ``` For additional arguments use: ```php Yii::app()->slack->post('channels.create', array('name' => 'mychannel')); ``` For complete list of all available methods and their arguments go to official [Slack documentation](https://api.slack.com/methods).
评论
    相关推荐
    • ansible-role-composer:Ansible角色-Composer PHP Dependency Manager
      ansible-role-composer:Ansible角色-Composer PHP Dependency Manager
    • composer php composer
      composer.exe php安装工具 , 安装时候注意选择对应的php版本(php.exe)
    • ComposerPHP
      Composer - 一个PHP的依赖管理器,帮助您声明,管理和安装PHP项目的依赖关系
    • opencart-composer
      opencart-作曲家 Composerphp 的依赖管理器现在你可以安装 composer 创建的项目并在 opencart 中使用它们。 要求 模态
    • php composer 附带使用方法和常用包名称
      php composer 附带使用方法和常用包名称。总结不易,希望对您有帮助。欢迎给我提意见。谢谢您了……
    • php_composer
      ComposerPHP 的一个依赖管理工具。它允许你申明项目所依赖的代码库,它会在你的项目中为你安装他们。
    • Composer 管理工具
      ComposerPHP5.3以上 的一个依赖管理工具。它允许你声明项目所依赖的代码库,它会在你的项目中为你安装他们。Composer 不是一个包管理器
    • php-composer
      php-composer
    • sendsms-composer
      $ composer require sendsms/sendsms 用法 如果您没有帐户,可以注册。 如果您需要查看我们软件包示例的完整列表,请转到我们的。 要调用特定函数,请包含该核心响应函数的名称空间。 这些函数位于API文档中的相应...
    • IpLocation:纯真IP库 - Composer PHP
      在你的composer.json中加入 "require": { "naux/iplocation": "dev-master" }, #使用 use Naux\IpLocation\IpLocation; $ip = new IpLocation(); $location = $ip->getlocation('119.75.217.56'); $location的内容...