承接 antcool/easy-lark 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

antcool/easy-lark

Composer 安装命令:

composer require antcool/easy-lark

包简介

PHP SDK for Lark

README 文档

README

PHP SDK for Lark Open.

Overtrue! Respect!

文档链接

安装

$ composer require antcool/easy-lark -vvv

使用

创建实例

<?php

require 'vendor/autoload.php';

// 配置项
$config = [ 
    // 开启 debug 将在 logger_file 写入请求日志
    'debug' => true,
    // 指定日志文件
    'runtime_path' => '/tmp/easy-lark',

    // 应用信息
    'app_id' => '',
    'app_secret' => '',

    // curl 配置
    'http' => [
        'timeout' => 10,
        'base_uri' => 'https://open.feishu.cn',
    ],

    // 事件订阅信息
    'event' => [
        // Encrypt Key, 配置后将会自动解密消息
        'encrypt_key' => '',
        
        // Verification Token, 配置后将会自动校验消息 token 字段
        'verify_token' => '',
        
        // 是否开启请求来源签名验证(依赖 encrypt_key)
        'verify_request' => true,
    ],

    'access_token' => \AntCool\EasyLark\Support\AccessToken::class,
];

$app = new \AntCool\EasyLark\Application($config);

$client = $app->getClient();
$server = $app->getServer();
$config = $app->getConfig();

在 Laravel 中注册

$config = [
    'debug' => env('APP_DEBUG', false),
    'runtime_path' => storage_path('lark'),

    'app_id' => '',
    'app_secret' => '',

    'http' => [
        'timeout' => 10,
        'base_uri' => 'https://open.feishu.cn',
    ],
    
    'event' => [
        'encrypt_key' => '',
        'verify_token' => '',
        'verify_request' => true,
    ],
    
    'access_token' => \AntCool\EasyLark\Support\AccessToken::class,
]; 

// AppServiceProvider
public function boot()
{
    $this->app->singleton('lark', fn () => new Application($config));
}

$app = app('lark');

基本用法

try {
    // 发起 API 请求
    $response = $app->getClient()->getJson('uri', $query = []);
    $response = $app->getClient()->postJson('uri', $data = [], $query = []);
    
    // 免登授权
    $response = $app->getClient()->postJson('/open-apis/authen/v1/access_token', [
        'grant_type' => 'authorization_code',
        'code'       => 'dDieky8JXDywpnOlhR8ydf',
    ]);

   
    // 飞书审批 (飞书部分接口使用的 www.feishu.cn 域名, 但是 AccessToken 相同)
    $app->getClient()->postJson('https://www.feishu.cn/approval/openapi/v2/approval/get', [
        'approval_code' => '376DA07B-XXXX-XXXX-XXXX-98B7B907C6B3',
    ]);
    
    // 文件上传
    $file = new \AntCool\EasyLark\Support\File('file path');
    $app->getClient()->uploadFile(
        '/open-apis/im/v1/files' // 消息与群组消息文件上传,
        $file,
        ['file_type' => $file->extension, 'file_name' => $file->name]
    );
} catch (Throwable $exception) {
    echo $exception->getMessage();
}

事件订阅

需在应用后台订阅, 审批事件订阅后需对 Approval Code 进行订阅

// 订阅指定审批单
$response = app('lark')->getClient()->postJson(
    'https://www.feishu.cn/approval/openapi/v2/subscription/subscribe',
    ['approval_code' => 'approval_code']
);

// 订阅事件处理
$server = $this->app->getServer();

// 方式一: 获取来自飞书服务器的推送事件内容, 你可以自行处理后 return $server->serve()
$event = $server->getRequestEvent();

// 方式二: 事件处理中间件处理, 可注册多个事件处理中间件
$server->with(function (Event $event, \Closure $next) {
    $body = $event->getBody(); // 推送的消息内容
    return $next($event);
});

// 方式三: 指定事件名称处理中间件
$server->addEventListener('approval_instance', function (Event $event, \Closure $next) {
    $body = $event->getBody(); // 推送的消息内容
    return $next($event);
});

// 别忘了调用 $server->serve();
return $server->serve();

自定义 AccessToken

class YourAccessToken implements AccessTokenInterface{
    public function getToken():string
    {
        
    }
}

$config = [
    'access_token' => YourAccessToken::class
];

TODO

  • 事件订阅
  • 消息模板
  • 机器人

Contributing

You can contribute in one of three ways:

  1. File bug reports using the issue tracker.
  2. Answer questions or fix bugs on the issue tracker.
  3. Contribute new features or update the wiki.

The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.

License

MIT

antcool/easy-lark 适用场景与选型建议

antcool/easy-lark 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.7k 次下载、GitHub Stars 达 58, 最近一次更新时间为 2022 年 03 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 antcool/easy-lark 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 antcool/easy-lark 我们能提供哪些服务?
定制开发 / 二次开发

基于 antcool/easy-lark 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5.7k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 59
  • 点击次数: 28
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-03-10