0251 | whmcs line notify แจ้งเตือน invoice
เอาไปใส่ใน folder includes/hooks/linenotify.php (อย่าลืมเปิด tag php)
<?php add_hook('EmailPreSend', 1, function($vars) { if (empty($vars['mergefields']) || empty($vars['mergefields']['client_custom_field_linenotifytoken'])) return; if ($vars['messagename'] == 'Invoice Created') { $message = "THZHost.com: มีใบแจ้งชำระเงินใหม่\n\n"; foreach ($vars['mergefields']['invoice_items'] as $item) { $message .= strip_tags($item['description'])." (".$item['amount']->__toString().")\n"; } $message .= "\nยอดค้างชำระ: ".$vars['mergefields']['invoice_balance']->__toString()."\nกำหนดชำระ: ".$vars['mergefields']['invoice_date_due']."\nhttps://www.thzhost.com/viewinvoice.php?id=".$vars['mergefields']['invoice_id']; line_notify_message($vars['mergefields']['client_custom_field_linenotifytoken'], $message); } elseif ($vars['messagename'] == 'Invoice Payment Reminder') { $message = "THZHost.com: ยอดชำระคงค้างใกล้ถึงกำหนดชำระ\n\n"; foreach ($vars['mergefields']['invoice_items'] as $item) { $message .= strip_tags($item['description'])." (".$item['amount']->__toString().")\n"; } $message .= "\nยอดค้างชำระ: ".$vars['mergefields']['invoice_balance']->__toString()."\nกำหนดชำระ: ".$vars['mergefields']['invoice_date_due']."\nhttps://www.thzhost.com/viewinvoice.php?id=".$vars['mergefields']['invoice_id']; line_notify_message($vars['mergefields']['client_custom_field_linenotifytoken'], $message); } elseif ($vars['messagename'] == 'Invoice Payment Confirmation') { $message = "THZHost.com: ยืนยันการชำระเงิน\n\n"; foreach ($vars['mergefields']['invoice_items'] as $item) { $message .= strip_tags($item['description'])." (".$item['amount']->__toString().")\n"; } $message .= "\nยอดรวม: ".$vars['mergefields']['invoice_total']->__toString()."\nขอบคุณที่ชำระค่าบริการ"; line_notify_message($vars['mergefields']['client_custom_field_linenotifytoken'], $message); } }); function line_notify_message($line_token, $message) { file_put_contents('/tmp/linenotify', print_r($message, true)); $line_api = 'https://notify-api.line.me/api/notify'; $queryData = array('message' => $message); $queryData = http_build_query($queryData,'','&'); $headerOptions = array( 'http'=>array( 'method'=>'POST', 'timeout' => 5, 'header'=> "Content-Type: application/x-www-form-urlencoded\r\n" ."Authorization: Bearer ".$line_token."\r\n" ."Content-Length: ".strlen($queryData)."\r\n", 'content' => $queryData ) ); $context = stream_context_create($headerOptions); $result = file_get_contents($line_api, FALSE, $context); $res = json_decode($result); return $res; } |
Tags: whmcs