2026-02-26 15:27:54 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\controller;
|
|
|
|
|
|
|
|
|
|
use app\service\FeishuNotificationService;
|
|
|
|
|
use Webman\Http\Request;
|
|
|
|
|
use Webman\Http\Response;
|
|
|
|
|
|
|
|
|
|
class TestController extends BaseController
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* 测试发送飞书通知
|
|
|
|
|
*/
|
|
|
|
|
public function testNotification(Request $request): Response
|
|
|
|
|
{
|
|
|
|
|
$userId = (int) ($request->get('user_id') ?? 1);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$notification = new FeishuNotificationService();
|
|
|
|
|
|
2026-02-26 16:27:33 +08:00
|
|
|
// 获取用户的company_id和feishu_app_id
|
2026-02-26 15:27:54 +08:00
|
|
|
$user = \app\model\User::find($userId);
|
|
|
|
|
if (!$user) {
|
|
|
|
|
return $this->error('用户不存在');
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-26 16:27:33 +08:00
|
|
|
if (!$user->feishu_app_id) {
|
|
|
|
|
return $this->error('用户未绑定飞书应用');
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-26 15:27:54 +08:00
|
|
|
$notification->setCompany($user->company_id);
|
2026-02-26 16:27:33 +08:00
|
|
|
$notification->setApp($user->feishu_app_id);
|
2026-02-26 15:27:54 +08:00
|
|
|
|
|
|
|
|
// 发送测试消息
|
|
|
|
|
$result = $notification->sendApprovalNotification([
|
|
|
|
|
'user_id' => $userId,
|
|
|
|
|
'title' => '测试审批通知',
|
|
|
|
|
'applicant' => '系统测试',
|
|
|
|
|
'type' => '测试申请',
|
|
|
|
|
'content' => '这是一条测试消息,用于验证飞书通知功能是否正常工作。',
|
|
|
|
|
'url' => 'https://xsm.dev.hnxinyouhe.com/dashboard',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
if ($result) {
|
2026-02-26 16:27:33 +08:00
|
|
|
// 获取用户在该应用下的feishu_user_id
|
|
|
|
|
$feishuUserId = $user->getFeishuUserId($user->feishu_app_id);
|
|
|
|
|
|
2026-02-26 15:27:54 +08:00
|
|
|
return $this->success([
|
|
|
|
|
'message' => '测试消息发送成功',
|
|
|
|
|
'user_id' => $userId,
|
|
|
|
|
'user_name' => $user->name,
|
2026-02-26 16:27:33 +08:00
|
|
|
'feishu_user_id' => $feishuUserId,
|
|
|
|
|
'feishu_app_id' => $user->feishu_app_id,
|
2026-02-26 15:27:54 +08:00
|
|
|
]);
|
|
|
|
|
} else {
|
|
|
|
|
return $this->error('测试消息发送失败,请查看日志');
|
|
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return $this->error('测试失败: ' . $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|