PHP code example of larafly / feishu
1. Go to this page and download the library: Download larafly/feishu library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
larafly / feishu example snippets
use Larafly\Feishu\Application;
$config = [
"app_id" => "1234",
"app_secret" => "AT7rW8JOJUFOVrWSdgh5XdQ3Akia8K1r"
];
$application = Application::getInstance($config);
dump($application->getConfig());
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){
}
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);
$mobiles = [
'13222222222'
] ;
$user = Application::getInstance()->createUser();
$res = $user->getOpenIdByMobiles($mobiles);
dump($res);
$mobiles = [
'13222222222'
] ;
$client = Application::getInstance()->createClient();
$res = $client->get('/user/v1/batch_get_id?mobiles='.$mobiles);;
dump($res);
shell
php artisan vendor:publish --provider="Larafly\Feishu\FeishuServiceProvider"