<?php

$GOOGLE_CHAT_WEBHOOK_URL = "https://chat.googleapis.com/v1/spaces/AAAA7hXAOCM/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=YupvEeDhNq2aF9ldCAf8TeJw8kmafVAXpj3xJWIzRGw%3D";
$GAME_TYPE_DISPLAY="G1";
$COUNTRY_CODE_DISPLAY="EN";
$CRASH_DATA="TEST";
date_default_timezone_set('Asia/Taipei');
$DATETIME = date('Y-m-d H:i:s');

# 發送訊息
$MESSAGE_GOOGLE_CHAT="
{
  \"cards\": [
    {
      \"sections\": [
        {
          \"widgets\": [
            {
              \"image\": {
                \"imageUrl\": \"https://dlg.x-legend.tw/apk/warning.png\",
              },
            },
            {
              \"textParagraph\": {
                \"text\": \"<b>[CRASH NOTIFY]</b><br><b>${GAME_TYPE_DISPLAY}-${COUNTRY_CODE_DISPLAY}</b> <b><font color='#008000'>(${DATETIME})</font></b><br><b><font color='#ff0000'>${CRASH_DATA}</font></b>\"
              }
            },
          ]
        }
      ]
    }
  ]
}
";

echo $MESSAGE_GOOGLE_CHAT . "\n";

# 送出資訊給 Google Chat Webhook
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $GOOGLE_CHAT_WEBHOOK_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
#curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $MESSAGE_GOOGLE_CHAT);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($MESSAGE_GOOGLE_CHAT)));
$ret = curl_exec($ch);
curl_close($ch);

#curl -sS -X POST -H 'Content-Type: application/json' $GOOGLE_CHAT_WEBHOOK_URL -d "${MESSAGE_GOOGLE_CHAT}"
