fix: [esign] 알림톡 버튼 URL을 등록된 템플릿 URL 그대로 사용 (동적 URL 템플릿 불일치 수정)

This commit is contained in:
김보곤
2026-02-24 18:41:55 +09:00
parent 7cf1f20fdb
commit 504f59dc99

View File

@@ -1035,8 +1035,10 @@ private function sendAlimtalk(
$templateName = $isReminder ? '전자계약_리마인드' : '전자계약_서명요청';
// 등록된 템플릿 본문을 가져와서 변수 치환 (정확한 포맷 유지)
$templateContent = $this->getTemplateContent($barobill, $member->biz_no, $channelId, $templateName);
// 등록된 템플릿 본문 + 버튼 정보 조회 (정확한 포맷 유지)
$tplData = $this->getTemplateData($barobill, $member->biz_no, $channelId, $templateName);
$templateContent = $tplData['content'];
$templateButtons = $tplData['buttons'];
if ($templateContent) {
$message = str_replace(
@@ -1054,18 +1056,21 @@ private function sendAlimtalk(
: " 안녕하세요, {$signer->name}님. \n 전자계약 서명 요청이 도착했습니다.\n\n ■ 계약명: {$contract->title}\n ■ 서명 기한: {$expires}\n\n 아래 버튼을 눌러 계약서를 확인하고 서명해 주세요.";
}
// 등록된 버튼 URL을 그대로 사용 (동적 URL 사용 시 템플릿 불일치 오류)
$buttons = ! empty($templateButtons) ? $templateButtons : [
['Name' => '계약서 확인하기', 'ButtonType' => 'WL',
'Url1' => 'https://mng.codebridge-x.com', 'Url2' => 'https://mng.codebridge-x.com'],
];
$receiverNum = preg_replace('/[^0-9]/', '', $signer->phone);
\Log::info('E-Sign 알림톡 발송 시도', [
'contract_id' => $contract->id,
'signer_id' => $signer->id,
'sender_id' => $member->barobill_id,
'yellow_id' => $channelId,
'template_name' => $templateName,
'template_from_api' => (bool) $templateContent,
'buttons_from_api' => ! empty($templateButtons),
'receiver_num' => $receiverNum,
'message_length' => mb_strlen($message),
'sign_url' => $signUrl,
]);
$result = $barobill->sendATKakaotalkEx(
@@ -1077,14 +1082,7 @@ private function sendAlimtalk(
receiverNum: $receiverNum,
title: '',
message: $message,
buttons: [
[
'Name' => '계약서 확인하기',
'ButtonType' => 'WL',
'Url1' => $signUrl,
'Url2' => $signUrl,
],
],
buttons: $buttons,
);
// 발송 접수 후 결과 확인 (SendKey 반환 시)
@@ -1178,14 +1176,18 @@ private function getKakaotalkChannelId(BarobillService $barobill, string $bizNo)
}
/**
* 바로빌 등록 템플릿의 본문 내용 조회
* 바로빌 등록 템플릿의 본문 내용 및 버튼 정보 조회
*
* @return array{content: string|null, buttons: array}
*/
private function getTemplateContent(BarobillService $barobill, string $bizNo, string $channelId, string $templateName): ?string
private function getTemplateData(BarobillService $barobill, string $bizNo, string $channelId, string $templateName): array
{
$empty = ['content' => null, 'buttons' => []];
$result = $barobill->getKakaotalkTemplates($bizNo, $channelId);
if (! ($result['success'] ?? false) || empty($result['data'])) {
return null;
return $empty;
}
$data = $result['data'];
@@ -1199,11 +1201,31 @@ private function getTemplateContent(BarobillService $barobill, string $bizNo, st
foreach ($items as $tpl) {
if (($tpl->TemplateName ?? '') === $templateName) {
return $tpl->TemplateContent ?? null;
$buttons = [];
$btnData = $tpl->Buttons ?? null;
if ($btnData) {
$btnList = $btnData->KakaotalkButton ?? null;
if ($btnList) {
$btnList = is_array($btnList) ? $btnList : [$btnList];
foreach ($btnList as $btn) {
$buttons[] = [
'Name' => $btn->Name ?? '',
'ButtonType' => $btn->ButtonType ?? 'WL',
'Url1' => $btn->Url1 ?? '',
'Url2' => $btn->Url2 ?? '',
];
}
}
}
return [
'content' => $tpl->TemplateContent ?? null,
'buttons' => $buttons,
];
}
}
return null;
return $empty;
}
/**