larafly/feishu

laravel 飞书sdk

v1.2.1 2024-12-05 02:26 UTC

This package is auto-updated.

Last update: 2025-01-05 02:37:28 UTC


README

install

composer require larafly/feishu

Config

  1. publish the config file to config directory:
php artisan vendor:publish --provider="Larafly\Feishu\FeishuServiceProvider"

Use

  • get application
<?php
use Larafly\Feishu\Application;

$config = [
    "app_id" => "1234",
    "app_secret" => "AT7rW8JOJUFOVrWSdgh5XdQ3Akia8K1r"
];
$application = Application::getInstance($config);

dump($application->getConfig());
  • auth login
<?php
use Larafly\Feishu\Application;

$config = [
    "app_id" => "1234",
    "app_secret" => "AT7rW8JOJUFOVrWSdgh5XdQ3Akia8K1r",
    "redirect_uri" =>"http://localhost"
];
$redirect_uri = Application::getInstance($config)->createAuth()->redirect($config['redirect_uri']);

redirect($redirect_uri);

//after login
$code = request()->get('code');
try {
    $user_info = Application::getInstance($config)->createAuth()->getUserByCode($code);
    dump($user_info);
 }catch (\Larafly\Feishu\Exceptions\RequestException $exception){
    
 }
  • send message
<?php
use Larafly\Feishu\Application;

$config = [
    "app_id" => "1234",
    "app_secret" => "AT7rW8JOJUFOVrWSdgh5XdQ3Akia8K1r",
    "redirect_uri" =>"http://localhost"
];
$message = Application::getInstance($config)->createMessage();

//send message str
$content = "send a message";
$receive_id = 'ou_ce8eaa702c9f310401a2b21f2a00b13d';
$response = $message->text($receive_id,$content);

//send message card
$receive_id = 'ou_ce8eaa702c9f310401a2b21f2a00b13d';
$template_id = "AAqjjGlz51b4V";
$template_variable = [
        'title'=>"title",
        'id'=>"123",
        'content'=>"this is a message\n created_at:2024-01-01 12:12:12",
        'created_info'=>"updated_at:2024-01-01 12:12:12",
        "redirect_url"=>"https://open.feishu.cn/cardkit/editor?cardId=AAqjjGlz51b4V&cardLocale=zh_cn&host=message"
];
$response = $message->card($receive_id,$template_id,$template_variable);
  • get user information
$mobiles = [
      '13222222222'
] ;
$user = Application::getInstance()->createUser();
$res  = $user->getOpenIdByMobiles($mobiles);
dump($res);
  • request other api
$mobiles = [
      '13222222222'
] ;
$client = Application::getInstance()->createClient();
$res  =  $client->get('/user/v1/batch_get_id?mobiles='.$mobiles);;
dump($res);