class = new Feishu($this->app_id, $this->app_secret); } /** * 飞书消息模板 * @param string $scene * @param array $options */ public function messageTemplates(string $scene = 'group-send', array $options = []) { try { $template = match ($scene) { 'inquiry-group-send' => $this->groupNewTemplates( $options['quality'], $options['order_no'], $options['channel'], $options['country'], $options['enter_user'], $options['r_time'] ), 'inquiry-group-update' => $this->groupUpdateTemplates( $options['quality'], $options['order_no'], $options['channel'], $options['country'], $options['enter_user'], $options['r_time'], $options['t_time'] ), 'inquiry-person-allocation' => $this->personAllocationTemplates( $options['quality'], $options['order_no'], $options['channel'], $options['country'], $options['enter_user'], $options['r_time'], $options['t_time'] ), 'crm-person-follow-up' => $this->personFollowUpTemplates( $options['contacts'], $options['follow_next'], $options['follow_last'] ) }; } catch (\UnhandledMatchError $e) { throw new BusinessException($e->getMessage()); } return $template; } /** * 发送飞书消息 * @param array $options */ public function messageSend(string $scene = 'group-send', array $options = []) { $template = $this->messageTemplates($scene, $options); $result = $this->class->sendMessages($options['receive_id'], $template, $options['msg_type'], $options['receive_id_type']); if (!isset($result['code']) || $result['code'] !== 0) { throw new BusinessException('发送飞书消息失败'); } return $result; } /** * 线索消息发送 */ public function groupNewTemplates($quality = '💛 银牌商机', $order_no = 'SN2025072365640', $channel = '谷歌', $country = '白俄罗斯', $enter_user = '木子李', $r_time = '2025-07-24 09:41:23') { $content = '{ "schema": "2.0", "config": { "update_multi": true, "style": { "text_size": { "normal_v2": { "default": "normal", "pc": "normal", "mobile": "heading" } } } }, "body": { "direction": "vertical", "horizontal_spacing": "8px", "vertical_spacing": "16px", "horizontal_align": "left", "vertical_align": "top", "padding": "0px 20px 20px 20px", "elements": [ { "tag": "hr", "margin": "0px 0px 0px 0px" }, { "tag": "column_set", "horizontal_align": "left", "columns": [ { "tag": "column", "width": "weighted", "elements": [ { "tag": "markdown", "content": " **'.$quality.'**\n- **编号:** '.$order_no.'\n- **渠道:** '.$channel.'\n- **国家:** '.$country.'\n- **发布人:** '.$enter_user.'\n- **发布时间:** '.$r_time.'", "text_align": "left", "text_size": "normal_v2", "margin": "0px 0px 0px 0px" } ], "vertical_spacing": "8px", "horizontal_align": "left", "vertical_align": "top", "weight": 1 } ] }, { "tag": "form", "elements": [ { "tag": "hr", "margin": "0px 0px 0px 0px" }, { "tag": "column_set", "flex_mode": "stretch", "horizontal_spacing": "8px", "horizontal_align": "left", "columns": [ { "tag": "column", "width": "auto", "elements": [ { "tag": "button", "text": { "tag": "plain_text", "content": "立即跟踪" }, "type": "primary_filled", "width": "fill", "size": "medium", "icon": { "tag": "standard_icon", "token": "list-check-bold_outlined" }, "confirm": { "title": { "tag": "plain_text", "content": "确认跟踪?" }, "text": { "tag": "plain_text", "content": "客户线索:'.$order_no.'" } }, "behaviors": [ { "type": "callback", "value": "'.$order_no.'" } ], "form_action_type": "submit", "name": "Button_m7d0zqa2", "element_id": "track" } ], "direction": "vertical", "horizontal_spacing": "8px", "vertical_spacing": "8px", "horizontal_align": "left", "vertical_align": "top" }, { "tag": "column", "width": "auto", "elements": [], "direction": "vertical", "horizontal_spacing": "8px", "vertical_spacing": "8px", "horizontal_align": "left", "vertical_align": "top" }, { "tag": "column", "width": "auto", "elements": [], "padding": "0px 0px 0px 0px", "direction": "vertical", "horizontal_spacing": "8px", "vertical_spacing": "8px", "horizontal_align": "left", "vertical_align": "top", "margin": "0px 0px 0px 0px" } ], "margin": "4px 0px 0px 0px" } ], "direction": "vertical", "horizontal_spacing": "8px", "vertical_spacing": "12px", "horizontal_align": "left", "vertical_align": "top", "padding": "0px 0px 0px 0px", "margin": "0px 0px 0px 0px", "name": "Form_m7d0zqa1" } ] }, "header": { "title": { "tag": "plain_text", "content": "新的【公海】客户线索" }, "subtitle": { "tag": "plain_text", "content": "" }, "template": "default", "icon": { "tag": "standard_icon", "token": "ai-common_colorful" }, "padding": "12px 12px 12px 20px" } }'; return $content; } /** * 线索消息更新 */ public function groupUpdateTemplates($quality = '💛 银牌商机', $order_no = 'SN2025072365640', $channel = '谷歌', $country = '白俄罗斯', $enter_user = '木子李', $r_time = '2025-07-24 09:41:23', $t_time = '2025-07-24 14:41:23') { $content = '{ "schema": "2.0", "config": { "update_multi": true, "style": { "text_size": { "normal_v2": { "default": "normal", "pc": "normal", "mobile": "heading" } } } }, "body": { "direction": "vertical", "horizontal_spacing": "8px", "vertical_spacing": "16px", "horizontal_align": "left", "vertical_align": "top", "padding": "0px 20px 20px 20px", "elements": [ { "tag": "hr", "margin": "0px 0px 0px 0px" }, { "tag": "column_set", "horizontal_align": "left", "columns": [ { "tag": "column", "width": "weighted", "elements": [ { "tag": "markdown", "content": " **'.$quality.'**\n- **编号:** '.$order_no.'\n- **渠道:** '.$channel.'\n- **国家:** '.$country.'\n- **发布人:** '.$enter_user.'\n- **发布时间:** '.$r_time.'", "text_align": "left", "text_size": "normal_v2", "margin": "0px 0px 0px 0px" } ], "vertical_spacing": "8px", "horizontal_align": "left", "vertical_align": "top", "weight": 1 } ] }, { "tag": "hr", "margin": "0px 0px 0px 0px" }, { "tag": "div", "text": { "tag": "plain_text", "content": "跟踪时间:'.$t_time.'", "text_size": "notation", "text_align": "left", "text_color": "green" }, "icon": { "tag": "standard_icon", "token": "chat-done_outlined", "color": "green" }, "element_id": "track_time" } ] }, "header": { "title": { "tag": "plain_text", "content": "【公海】客户线索" }, "subtitle": { "tag": "plain_text", "content": "" }, "text_tag_list": [ { "tag": "text_tag", "text": { "tag": "plain_text", "content": "已跟踪" }, "color": "orange" } ], "template": "green", "icon": { "tag": "standard_icon", "token": "ai-common_colorful" }, "padding": "12px 12px 12px 20px" } }'; return $content; } /** * 线索分配消息 */ public function personAllocationTemplates($quality = '💛 银牌商机', $order_no = 'SN2025072365640', $channel = '谷歌', $country = '白俄罗斯', $enter_user = '木子李', $r_time = '2025-07-24 09:41:23', $t_time = '2025-07-24 14:41:23') { $content = '{ "schema": "2.0", "config": { "update_multi": true, "style": { "text_size": { "normal_v2": { "default": "normal", "pc": "normal", "mobile": "heading" } } } }, "body": { "direction": "vertical", "horizontal_spacing": "8px", "vertical_spacing": "16px", "horizontal_align": "left", "vertical_align": "top", "padding": "0px 20px 20px 20px", "elements": [ { "tag": "hr", "margin": "0px 0px 0px 0px" }, { "tag": "column_set", "horizontal_align": "left", "columns": [ { "tag": "column", "width": "weighted", "elements": [ { "tag": "markdown", "content": " **'.$quality.'**\n- **编号:** '.$order_no.'\n- **渠道:** '.$channel.'\n- **国家:** '.$country.'\n- **录单人:** '.$enter_user.'\n- **录入时间:** '.$r_time.'", "text_align": "left", "text_size": "normal_v2", "margin": "0px 0px 0px 0px" } ], "vertical_spacing": "8px", "horizontal_align": "left", "vertical_align": "top", "weight": 1 } ] }, { "tag": "hr", "margin": "0px 0px 0px 0px" }, { "tag": "div", "text": { "tag": "plain_text", "content": "分配时间:'.$t_time.'", "text_size": "notation", "text_align": "left", "text_color": "green" }, "icon": { "tag": "standard_icon", "token": "chat-done_outlined", "color": "green" }, "element_id": "allocation_time" } ] }, "header": { "title": { "tag": "plain_text", "content": "新的客户线索" }, "subtitle": { "tag": "plain_text", "content": "" }, "text_tag_list": [ { "tag": "text_tag", "text": { "tag": "plain_text", "content": "指定" }, "color": "yellow" } ], "template": "blue", "icon": { "tag": "standard_icon", "token": "todo_colorful" }, "padding": "12px 12px 12px 20px" } }'; return $content; } /** * 跟进提醒消息 */ public function personFollowUpTemplates($contacts = '木子李', $follow_next = '2025-07-24 14:41:23', $follow_last = '2025-07-24 14:41:23') { $content = '{ "schema": "2.0", "config": { "update_multi": true, "style": { "text_size": { "normal_v2": { "default": "normal", "pc": "normal", "mobile": "heading" } } } }, "body": { "direction": "vertical", "horizontal_spacing": "8px", "vertical_spacing": "16px", "horizontal_align": "left", "vertical_align": "top", "padding": "0px 20px 20px 20px", "elements": [ { "tag": "hr", "margin": "0px 0px 0px 0px" }, { "tag": "column_set", "horizontal_align": "left", "columns": [ { "tag": "column", "width": "weighted", "elements": [ { "tag": "markdown", "content": "- **客户名称:** '.$contacts.'\n- **跟进时间:** '.$follow_next.'", "text_align": "left", "text_size": "normal_v2", "margin": "0px 0px 0px 0px" } ], "vertical_spacing": "8px", "horizontal_align": "left", "vertical_align": "top", "weight": 1 } ] }, { "tag": "hr", "margin": "0px 0px 0px 0px" }, { "tag": "div", "text": { "tag": "plain_text", "content": "最近跟进:'.$follow_last.'", "text_size": "notation", "text_align": "left", "text_color": "grey" }, "icon": { "tag": "standard_icon", "token": "chat_outlined", "color": "grey" }, "element_id": "track_time" } ] }, "header": { "title": { "tag": "plain_text", "content": "跟进提醒" }, "subtitle": { "tag": "plain_text", "content": "" }, "template": "green", "icon": { "tag": "standard_icon", "token": "calendar_colorful" }, "padding": "12px 12px 12px 20px" } }'; return $content; } }