 |
สอบถามเรื่อง LINE Flex message Loop ข้อมูลใน SQL เพื่อส่งข้อความครับ |
|
 |
|
|
 |
 |
|
Code
<?php
require 'sendMessage.php';
include '.\connectsale.php';
$query = "
SELECT 'LCS' COMPANY_CODE,
pl.productlevelcode AS STORE_ID,
DATE_FORMAT(ot.SaleDate, '%d-%b-%Y') AS BUSINESS_DATE,
IF (ot.salemode = 1, 'DI', 'TA') AS CHANNEL_TYPE,
FORMAT(SUM(ot.receiptsaleprice ),2) AS GROSS_SALES,
FORMAT (SUM(ot.receiptdiscount),2) AS DISCOUNT,
FORMAT (SUM(ot.transactionvat),2) AS SALES_TAX,
FORMAT (SUM(ot.receiptsaleprice - ot.transactionvat),2) AS NET_SALES,
SUM(ot.nocustomer) AS CUSTOMER,
COUNT(*) AS DOCKET
FROM ordertransaction ot,
productlevel pl
WHERE ot.shopid = pl.productlevelid
AND ot.saledate = '2021-11-24'
AND ot.receiptid <> 0
AND ot.transactionstatusid = 2
GROUP BY pl.productlevelid,
pl.productlevelcode,
ot.saledate,
ot.salemode
ORDER BY ot.saledate,
productlevelcode,
ot.salemode;
";
$result_query = mysqli_query($condb,$query);
$arrBubble = [];
foreach ($result_query as $row) {
$data_STORE_ID = $row['STORE_ID'];
$data_GROSS_SALES = $row['GROSS_SALES'];
$data_CHANNEL_TYPE = $row['CHANNEL_TYPE'];
$data_DOCKET = $row['DOCKET'];
$data_CUSTOMER = $row['CUSTOMER'];
$arrBubble[] = '
[
{
"type": "bubble",
"hero": {
"type": "image",
"url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/01_5_carousel.png",
"size": "full",
"aspectRatio": "20:13",
"aspectMode": "cover"
},
"body": {
"type": "box",
"layout": "vertical",
"spacing": "sm",
"contents": [
{
"type": "text",
"text": "$data_STORE_ID",
"size": "xl",
"weight": "bold",
"wrap": true
},
{
"type": "box",
"layout": "baseline",
"contents": [
{
"type": "text",
"text": "$49",
"flex": 0,
"size": "xl",
"weight": "bold",
"wrap": true
},
{
"type": "text",
"text": ".99",
"flex": 0,
"size": "sm",
"weight": "bold",
"wrap": true
}
]
}
]
},
"footer": {
"type": "box",
"layout": "vertical",
"spacing": "sm",
"contents": [
{
"type": "button",
"action": {
"type": "uri",
"label": "Add to Cart",
"uri": "https://linecorp.com"
},
"style": "primary"
},
{
"type": "button",
"action": {
"type": "uri",
"label": "Add to whishlist",
"uri": "https://linecorp.com"
}
}
]
}
}
]
';
}
$flexDataJson = '{
"type": "flex",
"altText": "Flex Message",
"contents": {
"type": "carousel",
"contents": [
$arrBubble
]
}
}';
echo '<pre>'; var_dump( $flexDataJson ); echo '</pre>';
$flexDataJsonDeCode = json_decode($flexDataJson,true);
$datas['url'] = "https://api.line.me/v2/bot/message/push";
$datas['token'] = "QZSVnrwrgWZNXf7Vt3EepOOfcV9bqtbrhKBXf8rMujJtFpoTBCpRvtmoJ8H3f8BPPjFsDFODCIiqrD9+MhyYpuVQ3Su4oAm4NgW3Drc+7aEnBBZSzYCxEQcyligCLsS4ZSqQ/gvzDyO/sx31eiUzAwdB04t89/1O/w1cDnyilFU=";
$messages['to'] = "Ua41de6946e0184a06e4664325c2aca9b";
$messages['messages'][] = $flexDataJsonDeCode;
$encodeJson = json_encode($messages);
sentMessage($encodeJson,$datas);
?>
ผมต้องการ Loop ข้อมูลใน SQL มาใส่ใน $flexDataJson แล้ววส่งไปให้ทางไลน์ครับ โดยข้อมูลที่ Loop มาช่อตัวแปร $arrBubble แต่ไม่สามารถทำการส่งได้ อยากขอคำแนะนำครับ
Tag : PHP, MySQL
|
|
 |
 |
 |
 |
Date :
2021-11-28 02:04:40 |
By :
yurayatjm |
View :
1954 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โครงสร้างผิด
Code (JavaScript)
"contents": [
{
"type": "bubble",
//box-1
},
{
"type": "bubble",
//box-2
},
{
"type": "bubble",
//box-n
}
]
ลองเอาตัวนี้ออก
Code (PHP)
$arrBubble[] = '
//[ เอาตัวนี้และ ] ด้านล่างออก
// หรือไม่ก็ทดสอบแบบ static ให้ถูกต้องก่อน
{
"type": "bubble",
"hero": {
"type": "image",
"url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/01_5_carousel.png",
"size": "full",
"aspectRatio": "20:13",
"aspectMode": "cover"
},
.....
|
 |
 |
 |
 |
Date :
2021-12-01 14:55:36 |
By :
Guest |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|