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
This commit is contained in:
66
test_upload_endpoints.py
Normal file
66
test_upload_endpoints.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import requests
|
||||
import json
|
||||
import os
|
||||
|
||||
DINGTALK_APP_KEY = "ding4ursdp0l2giat4bj"
|
||||
DINGTALK_APP_SECRET = "J0gBicjKiIHoKla7WfKKhRs1Tv8L6Xd5UhW3EVQByF16G7Vn7UUcRhP6u-PBCQNo"
|
||||
ROBOT_CODE = "ding4ursdp0l2giat4bj"
|
||||
|
||||
FILE_PATH = r"C:\Users\ALC\.openclaw\workspace\前后端功能与开源可修改性分析报告.docx"
|
||||
FILE_NAME = "前后端功能与开源可修改性分析报告.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 try_upload_endpoints(token):
|
||||
endpoints = [
|
||||
"https://api.dingtalk.com/v2.0/media/upload",
|
||||
"https://api.dingtalk.com/v1.0/media/upload",
|
||||
"https://open.dingtalk.com/file/upload",
|
||||
]
|
||||
|
||||
for url in endpoints:
|
||||
try:
|
||||
print(f"Trying: {url}")
|
||||
files = {'media': (FILE_NAME, open(FILE_PATH, 'rb'))}
|
||||
params = {'type': 'file'}
|
||||
headers = {'x-acs-dingtalk-access-token': token}
|
||||
r = requests.post(url, params=params, headers=headers, files=files, timeout=30)
|
||||
print(f"Status: {r.status_code}")
|
||||
|
||||
if r.status_code == 200:
|
||||
print(f"Response: {r.text[:300]}")
|
||||
result = r.json()
|
||||
if "mediaId" in result:
|
||||
return result["mediaId"]
|
||||
else:
|
||||
print(f"Failed: {r.text[:200]}")
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
print("")
|
||||
|
||||
return None
|
||||
|
||||
def main():
|
||||
try:
|
||||
print("=== Testing Upload Endpoints ===")
|
||||
token = get_token()
|
||||
print("Token obtained")
|
||||
|
||||
media_id = try_upload_endpoints(token)
|
||||
if media_id:
|
||||
print(f"\n=== SUCCESS ===\nMedia ID: {media_id}")
|
||||
else:
|
||||
print("\n=== All endpoints failed ===")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user