Files
MarketAnalysis-ETL/EXTERNAL/OTHERS/external_triggered_email.py
2026-04-20 14:55:25 +08:00

42 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Databricks notebook source
import base64
import time
import urllib.parse
import requests
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
# === 配置区 ===
# Spring Boot 服务端的密钥Base64编码
SECRET_KEY_BASE64 = "qkLkLHPnqNfJ5d3X6DgLpw=="
# 接口地址
# https://mdcuat.astrazeneca.cn/earth/app/mail/task/ma/check
# https://mdc.astrazeneca.cn/earth/app/mail/task/ma/check
API_URL = "https://mdc.astrazeneca.cn/earth/app/mail/task/ma/check"
# === AES 加密函数 ===
def generate_aes_token(secret_key_base64: str) -> str:
# Hutool 的 SecureUtil.aes() 默认是 AES/ECB/PKCS5Padding
secret_key = base64.b64decode(secret_key_base64)
cipher = AES.new(secret_key, AES.MODE_ECB)
# 加密当前时间戳(毫秒)
timestamp = str(int(time.time() * 1000))
encrypted = cipher.encrypt(pad(timestamp.encode("utf-8"), AES.block_size))
# 输出 Base64 编码的 token
return base64.b64encode(encrypted).decode("utf-8")
# === 调用接口 ===
def call_check_api():
token = generate_aes_token(SECRET_KEY_BASE64)
encoded_token = urllib.parse.quote(token)
url = f"{API_URL}?token={encoded_token}"
print(f"请求URL: {url}")
response = requests.get(url)
print("响应状态码:", response.status_code)
print("响应内容:", response.text)
if __name__ == "__main__":
call_check_api()