我想做一个应用app,然后后端使用python,应用需要向app用户推送消息,我现在已经实现测试推送成功,但是不会用python进行推送消息,uni-push,代码的参数不知道怎么找,
import requests
import json
def send_uni_push(appid, appsecret, title, content, target):
url = "https://openapi.dcloud.net.cn/v2/message/push"
headers = {
'Content-Type': 'application/json',
'X-DC-APPID': appid,
'X-DC-APPSECRET': appsecret
}
data = {
"to_user": target, # 可以是用户ID、别名或标签等
"title": title,
"content": content
}
response = requests.post(url, headers=headers, data=json.dumps(data))
return response.json()
# 使用示例
appid = "YOUR_APPID"
appsecret = "YOUR_APPSECRET"
title = "Hello"
content = "This is a push message from Python!"
target = "all" # 发送给所有用户,你可以根据需要修改为目标用户ID、别名或标签
result = send_uni_push(appid, appsecret, title, content, target)
print(result)