Files
workspace/send_old_api_no_print.py
aitest 15c4480db1 Add OpenClaw workspace configuration and tools
- Add agent configuration files (AGENTS.md, USER.md, IDENTITY.md, SOUL.md)
- Add git configuration and skills management scripts
- Add frontend/backend analysis tools and reports
- Add DingTalk media sender utilities and documentation
- Fix OpenClaw runtime environment (Node.js and Python)
- Configure git remotes and push scripts
2026-03-05 13:56:59 +09:00

76 lines
2.6 KiB
Python

import requests
import json
import os
DINGTALK_APP_KEY = "ding4ursdp0l2giat4bj"
DINGTALK_APP_SECRET = "J0gBicjKiIHoKla7WfKKhRs1Tv8L6Xd5UhW3EVQByF16G7Vn7UUcRhP6u-PBCQNo"
ROBOT_CODE = "ding4ursdp0l2giat4bj"
OPEN_CONVERSATION_ID = "cidcjYshXVtKck5LfOO9AqOJg=="
FILE_PATH = r"C:\Users\ALC\.openclaw\workspace\前后端功能与开源可修改性分析报告.docx"
def get_token():
url = "https://api.dingtalk.com/v1.0/oauth2/accessToken"
headers = {"Content-Type": "application/json"}
data = {"appKey": DINGTALK_APP_KEY, "appSecret": DINGTALK_APP_SECRET}
r = requests.post(url, headers=headers, json=data, timeout=10)
return r.json()["accessToken"]
def upload_old_api(token, file_path):
url = "https://open.dingtalk.com/file/upload"
files = {'media': open(file_path, 'rb')}
data = {'type': 'file'}
headers = {'x-acs-dingtalk-access-token': token}
r = requests.post(url, files=files, data=data, headers=headers, timeout=30)
return r.json()
def send_to_group_old_api(media_id):
url = "https://open.dingtalk.com/robot/send"
data = {
"msgtype": "file",
"file": {
"media_id": media_id
},
"openConversationId": OPEN_CONVERSATION_ID
}
r = requests.post(url, json=data, timeout=30)
return r.json()
def main():
try:
token = get_token()
print("Token obtained")
print("Uploading...")
upload_result = upload_old_api(token, FILE_PATH)
upload_result_json = json.dumps(upload_result, ensure_ascii=False)
with open(r"C:\Users\ALC\.openclaw\workspace\upload_result.txt", "w", encoding="utf-8") as f:
f.write(f"Upload result:\n{upload_result_json}\n")
if 'media_id' in upload_result or 'errcode' in upload_result:
if 'media_id' in upload_result:
media_id = upload_result['media_id']
else:
print(f"Upload failed: {upload_result}")
return
print("Sending to group...")
send_result = send_to_group_old_api(media_id)
with open(r"C:\Users\ALC\.openclaw\workspace\send_result.txt", "w", encoding="utf-8") as f:
f.write(f"Send result:\n{json.dumps(send_result, ensure_ascii=False)}\n")
if send_result.get('errcode') == 0:
print("SUCCESS")
else:
print(f"FAILED: {send_result}")
except Exception as e:
with open(r"C:\Users\ALC\.openclaw\workspace\error.txt", "w", encoding="utf-8") as f:
f.write(f"Error: {e}\n")
print(f"Error: {e}")
if __name__ == "__main__":
main()