飞书/企微仅标题+客户信息+用户旅程,去掉计划归因与 JSON 附录;HTTP 改为精简 JSON。 Co-authored-by: Cursor <cursoragent@cursor.com>
73 lines
2.5 KiB
PHP
73 lines
2.5 KiB
PHP
#!/usr/bin/env php
|
||
<?php
|
||
namespace think\facade {
|
||
class Log
|
||
{
|
||
public static function warning($m, $c = []) {}
|
||
}
|
||
}
|
||
|
||
namespace {
|
||
require dirname(__DIR__) . '/application/cunkebao/service/LeadWebhookDeliveryService.php';
|
||
|
||
use app\cunkebao\service\LeadWebhookDeliveryService;
|
||
|
||
$sample = [
|
||
'event' => 'lead.created',
|
||
'eventText' => '客资新建',
|
||
'triggerAt' => '2026-05-25 10:00:00',
|
||
'plan' => [
|
||
'id' => 123,
|
||
'name' => '全局计划',
|
||
'sceneName' => '海报获客',
|
||
'planType' => 0,
|
||
'planTypeText' => '全局计划',
|
||
],
|
||
'lead' => [
|
||
'phone' => '13800138000',
|
||
'name' => '张三',
|
||
'source' => '官网表单',
|
||
'statusText' => '未处理',
|
||
],
|
||
'tags' => ['all' => ['高意向', '新客']],
|
||
'planTimeline' => [
|
||
['label' => '进入获客计划', 'time' => '2026-05-25 09:58:00', 'source' => '官网表单', 'stage' => 'entered'],
|
||
['label' => '客资新建', 'time' => '2026-05-25 10:00:00', 'stage' => 'webhook_push'],
|
||
],
|
||
];
|
||
|
||
$text = LeadWebhookDeliveryService::formatImText($sample);
|
||
assert(strpos($text, '【海报获客 · 全局计划「全局计划」】客资新建') !== false);
|
||
assert(strpos($text, '▎客户信息') !== false);
|
||
assert(strpos($text, '▎用户旅程') !== false);
|
||
assert(strpos($text, '计划归因') === false);
|
||
assert(strpos($text, '结构化数据') === false);
|
||
assert(strpos($text, '电话:13800138000') !== false);
|
||
|
||
$compact = LeadWebhookDeliveryService::buildCompactPayload($sample);
|
||
assert(isset($compact['customerInfo'], $compact['userJourney']));
|
||
assert(!isset($compact['attribution']));
|
||
|
||
$url = 'https://open.feishu.cn/open-apis/bot/v2/hook/test';
|
||
$body = LeadWebhookDeliveryService::toFeishuBotBody($sample);
|
||
assert(($body['msg_type'] ?? '') === 'text');
|
||
|
||
$err = LeadWebhookDeliveryService::parseResponse(
|
||
$url,
|
||
200,
|
||
'{"code":19002,"msg":"params error, msg_type need"}'
|
||
);
|
||
assert(!$err['success']);
|
||
|
||
echo "[PASS] LeadWebhookDeliveryService compact IM format\n";
|
||
|
||
$liveUrl = getenv('FEISHU_HOOK_URL') ?: ($argv[1] ?? '');
|
||
if ($liveUrl !== '') {
|
||
$r = LeadWebhookDeliveryService::deliver($liveUrl, $sample);
|
||
echo json_encode($r, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT), "\n";
|
||
exit($r['success'] ? 0 : 1);
|
||
}
|
||
|
||
echo "[SKIP] live deliver (pass hook url as argv[1])\n";
|
||
}
|