- 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
72 lines
2.4 KiB
Python
72 lines
2.4 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"
|
|
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 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 via old API...")
|
|
upload_result = upload_old_api(token, FILE_PATH)
|
|
print(f"Upload result: {json.dumps(upload_result, ensure_ascii=False)[:200]}")
|
|
|
|
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 with errcode: {upload_result.get('errcode')}")
|
|
return
|
|
|
|
print("Sending to group...")
|
|
send_result = send_to_group_old_api(media_id)
|
|
print(f"Send result: {json.dumps(send_result, ensure_ascii=False)}")
|
|
|
|
if send_result.get('errcode') == 0:
|
|
print("\n=== SUCCESS ===")
|
|
else:
|
|
print(f"\n=== FAILED ===\n{send_result}")
|
|
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
if __name__ == "__main__":
|
|
main()
|