簡介

SkyNotice API 讓您可以透過程式化的方式發送推播通知到多個平台,包括 LINE、Facebook Messenger、Telegram、Email 及網頁推播。

快速開始

只需要準備 company_tokentype_token,即可透過 API 發送通知。

API 端點

POST
https://skynotice.tw/api/notify

請求標頭

Content-Type: application/json

請求參數

參數必填類型說明
company_token必填string公司 Token,可在後台取得
type_token必填string通知類別 Token,可在後台建立與取得
timestamp必填integerUnix 時間戳,用於防止重放攻擊(±5分鐘內有效)
title必填string通知標題
content必填string通知內容
weblink選填string連結網址,點擊通知後跳轉的目標

回應格式

成功回應

JSON
{
    "status": "success",
    "code": "OK",
    "message": "通知已成功建立",
    "data": {
        "notice_code": "aBcDeFgH12345678"
    }
}

失敗回應

JSON
{
    "status": "error",
    "code": "INVALID_TOKEN",
    "message": "驗證失敗,Token 無效"
}

錯誤代碼

錯誤代碼說明
METHOD_NOT_ALLOWED請求方法不允許,僅接受 POST
INVALID_CONTENT_TYPEContent-Type 必須為 application/json
EMPTY_BODY請求內容為空
INVALID_JSONJSON 格式錯誤
MISSING_TIMESTAMP缺少 timestamp 參數
INVALID_TIMESTAMPtimestamp 格式錯誤
TIMESTAMP_EXPIRED請求已過期(timestamp 超過 ±5 分鐘)
RATE_LIMIT_EXCEEDED請求過於頻繁(每 Token 每分鐘限 100 次)
MISSING_REQUIRED_FIELDS缺少必填欄位
INVALID_TOKENToken 驗證失敗
EMPTY_TITLE標題不可為空
EMPTY_CONTENT內容不可為空
程式碼範例

PHP 範例

PHP
$url = "https://skynotice.tw/api/notify";

$data = array(
    'company_token'    => 'your_company_token',
    'type_token'       => 'your_type_token',
    'timestamp'        => time(),  // 必填,防止重放攻擊
    'title'            => '訂單成立通知',
    'content'          => '您的訂單 #12345 已成立,預計 3-5 個工作天送達',
    'weblink'          => 'https://yourshop.com/order/12345'
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);

$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

$result = json_decode($response, true);

if ($result['status'] === 'success') {
    echo "發送成功!通知編號:" . $result['data']['notice_code'];
} else {
    echo "發送失敗:" . $result['message'];
}

JavaScript 範例

JavaScript
const sendNotification = async () => {
    const response = await fetch('https://skynotice.tw/api/notify', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({
            company_token: 'your_company_token',
            type_token: 'your_type_token',
            timestamp: Math.floor(Date.now() / 1000),  // Unix 時間戳
            title: '訂單成立通知',
            content: '您的訂單 #12345 已成立',
            weblink: 'https://yourshop.com/order/12345',
        })
    });

    const result = await response.json();

    if (result.status === 'success') {
        console.log('發送成功!通知編號:', result.data.notice_code);
    } else {
        console.error('發送失敗:', result.message);
    }
};

Python 範例

Python
import requests
import time

url = "https://skynotice.tw/api/notify"

data = {
    "company_token": "your_company_token",
    "type_token": "your_type_token",
    "timestamp": int(time.time()),  # Unix 時間戳
    "title": "訂單成立通知",
    "content": "您的訂單 #12345 已成立",
    "weblink": "https://yourshop.com/order/12345"
}

response = requests.post(url, json=data, timeout=30)
result = response.json()

if result["status"] == "success":
    print(f"發送成功!通知編號:{result['data']['notice_code']}")
else:
    print(f"發送失敗:{result['message']}")

cURL 範例

Bash
curl -X POST https://skynotice.tw/api/notify \
  -H "Content-Type: application/json" \
  -d '{
    "company_token": "your_company_token",
    "type_token": "your_type_token",
    "timestamp": '$(date +%s)',
    "title": "測試通知",
    "content": "這是一則測試通知"
  }'

需要技術支援?

我們的技術團隊隨時為您解答 API 整合問題

聯絡我們