Skip to content

Webhook 推送

访问限制

本部分 API 属于增值服务,开发者 Token 需要额外开通权限,请联系商务

预警信息支持通过 Webhook 推送,单条预警记录的结构与 API 返回结构一致。

POST Body:

json
{
  "sign": "xxxx", // 根据规则生成的签名
  "nonce": "xxxx", // 随机字符串
  "server_time": 1761706359,
  "alert": {
    "id": "ALERT_CN_21040041600000_20251029104400",
    "alert_type": 156110206,
    "area_code": "210400",
    "color": { "red": 55, "green": 100, "blue": 255, "alpha": 1.0 }, // RGB 为 int 类型,alpha 为 float 类型
    "publish_time": 1761705878,
    "expire_time": 1761781418, // 预警过期时间戳(秒)
    "region_code": "CN",
    "source": 1,
    "status": 1,
    "data": [
      {
        "language_code": "zh-CN",
        "name": "大风蓝色预警",
        "text": "大风蓝色预警信号:预计29日上午到夜间,抚顺市区、抚顺县西南风4到6级,阵风7到8级,请注意出行安全,加固临时搭建物,防范高空坠物等风险。抚顺市气象台2025年10月29日10时44分发布(数据来源:国家预警信息发布中心)",
        "title": "抚顺市气象台发布大风蓝色预警信号[Ⅳ级/一般]"
      }
    ]
  }
}

签名计算规则

计算规则为:

text
sign = md5("{token}-{id}-{publish_time}-{nonce}-{server_time}")

Python/Go/Java/PHP 示例代码如下:

py
import hashlib


def generate_sign(token, id, publish_time, nonce, server_time):
    # 拼接字符串
    data = f"{token}-{id}-{publish_time}-{nonce}-{server_time}"
    # 计算 MD5 签名
    sign = hashlib.md5(data.encode()).hexdigest()
    return sign


# 示例数据
token = "your_token"
id = "your_id"
publish_time = 1234567890
nonce = "your_nonce"
server_time = 9876543210

# 生成签名
sign = generate_sign(token, id, publish_time, nonce, server_time)
print(sign)
# Output: ed72493981fff6ddc4770dc70aeeb1ad
go
package main

import (
 "crypto/md5"
 "encoding/hex"
 "fmt"
)

func generateSign(token, id string, publishTime int64, nonce string, serverTime int64) string {
 // 拼接字符串
 data := fmt.Sprintf("%s-%s-%d-%s-%d", token, id, publishTime, nonce, serverTime)
 // 计算 MD5 签名
 hash := md5.Sum([]byte(data))
 return hex.EncodeToString(hash[:])
}

func main() {
 // 示例数据
 token := "your_token"
 id := "your_id"
 publishTime := int64(1234567890)
 nonce := "your_nonce"
 serverTime := int64(9876543210)

 // 生成签名
 sign := generateSign(token, id, publishTime, nonce, serverTime)
 fmt.Println(sign)
    // Output: ed72493981fff6ddc4770dc70aeeb1ad
}
java
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class SignDemo {

    public static void main(String[] args) {
        String token = "your_token";
        String id = "your_id";
        long publishTime = 1234567890L;
        String nonce = "your_nonce";
        long serverTime = 9876543210L;

        // 拼接字符串
        String input = String.format("%s-%s-%d-%s-%d", token, id, publishTime, nonce, serverTime);

        // 计算 MD5 签名
        String sign = md5(input);

        // 输出签名
        System.out.println("计算出的签名: " + sign);

        // 验证是否与预期结果匹配
        String expectedSign = "ed72493981fff6ddc4770dc70aeeb1ad";
        if (sign.equals(expectedSign)) {
            System.out.println("签名匹配!");
        } else {
            System.out.println("签名不匹配!");
        }
    }

    // 计算 MD5 哈希
    public static String md5(String input) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] hashBytes = md.digest(input.getBytes(StandardCharsets.UTF_8));
            StringBuilder sb = new StringBuilder();
            for (byte b : hashBytes) {
                sb.append(String.format("%02x", b));
            }
            return sb.toString();
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }
}
php
<?php

function calculateSign($token, $id, $publishTime, $nonce, $serverTime) {
    // 拼接字符串
    $input = sprintf("%s-%s-%d-%s-%d", $token, $id, $publishTime, $nonce, $serverTime);

    // 计算 MD5 签名
    return md5($input);
}

// 样例数据
$token = "your_token";
$id = "your_id";
$publishTime = 1234567890;
$nonce = "your_nonce";
$serverTime = 9876543210;

// 计算签名
$sign = calculateSign($token, $id, $publishTime, $nonce, $serverTime);

echo "计算出的签名: " . $sign . "\n";

// 预期的签名
$expectedSign = "ed72493981fff6ddc4770dc70aeeb1ad";

// 验证签名是否匹配
if ($sign === $expectedSign) {
    echo "签名匹配!\n";
} else {
    echo "签名不匹配!\n";
}
?>
更多语言签名计算代码

上述代码都是用 LLM 生成的,使用的 prompts 如下:

md
我有一个签名的计算方式为:

sign = md5("{token}-{id}-{publish_time}-{nonce}-{server_time}")

其中:

- token: str, eg "your_token"
- id: str, eg "your_id"
- publish_time: int64, eg 1234567890
- nonce: str, eg "your_nonce"
- server_time: int64, eg 9876543210

帮我编写对应的 Python&Go 的 demo,并用样例数据验证签名计算是否为 `ed72493981fff6ddc4770dc70aeeb1ad`

请根据自己的需求修改 prompts,并用样例数据验证签名计算是否正确。