Skip to content

Commit

Permalink
Update report_cdn.py
Browse files Browse the repository at this point in the history
  • Loading branch information
xielk authored Sep 22, 2024
1 parent a732593 commit dcd54f0
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions report_cdn.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
import requests
import requests as req
import json
import datetime

Expand All @@ -11,8 +11,9 @@
openId = os.environ.get("OPEN_ID")
weather_template_id = os.environ.get("TEMPLATE_ID")


# 发送消息
def send_weather(access_token, bandwidth, requests):
def send_weather(access_token):
today_str = datetime.date.today().strftime("%Y年%m月%d日")
body = {
"touser": openId.strip(),
Expand All @@ -33,15 +34,25 @@ def send_weather(access_token, bandwidth, requests):
}
}
}

url = f'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={access_token}'
print(requests.post(url, json=body).text)
response = req.post(url, json=body)

# 检查响应状态
if response.status_code == 200:
print("消息发送成功:", response.json())
else:
print("发送失败:", response.status_code, response.text)

# 获取access token
def get_access_token():
url = f'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={appID.strip()}&secret={appSecret.strip()}'
response = requests.get(url).json()
response = req.get(url).json()
return response.get('access_token')

if __name__ == '__main__':
access_token = get_access_token()
send_weather(access_token, "10.00 GB", "100 次") # 测试调用
if access_token:
send_weather(access_token) # 测试调用
else:
print("获取 access_token 失败")

0 comments on commit dcd54f0

Please sign in to comment.