- 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
65 lines
1.8 KiB
JavaScript
65 lines
1.8 KiB
JavaScript
// 测试钉钉媒体上传 API
|
|
const axios = require('axios');
|
|
const fs = require('fs');
|
|
const FormData = require('form-data');
|
|
|
|
const APP_KEY = "ding4ursdp0l2giat4bj";
|
|
const APP_SECRET = "J0gBicjKiIHoKla7WfKKhRs1Tv8L6Xd5UhW3EVQByF16G7Vn7UUcRhP6u-PBCQNo";
|
|
|
|
// 可能的 API URLs
|
|
const API_URLS = [
|
|
'https://api.dingtalk.com/v1.0/media/upload',
|
|
'https://api-oa.dingtalk.com/v1.0/media/upload',
|
|
'https://oapi.dingtalk.com/media/upload',
|
|
];
|
|
|
|
async function getAccessToken() {
|
|
const response = await axios.post('https://api.dingtalk.com/v1.0/oauth2/accessToken', {
|
|
appKey: APP_KEY,
|
|
appSecret: APP_SECRET
|
|
});
|
|
return response.data.accessToken;
|
|
}
|
|
|
|
async function testUpload(accessToken, filePath) {
|
|
const formData = new FormData();
|
|
formData.append('type', 'image');
|
|
formData.append('file', fs.createReadStream(filePath));
|
|
|
|
console.log('测试这些 API URL:\n');
|
|
|
|
for (const url of API_URLS) {
|
|
try {
|
|
console.log(`\n尝试: ${url}`);
|
|
const response = await axios.post(url, formData, {
|
|
headers: {
|
|
'x-acs-dingtalk-access-token': accessToken,
|
|
...formData.getHeaders(),
|
|
},
|
|
maxBodyLength: Infinity,
|
|
maxContentLength: Infinity,
|
|
});
|
|
|
|
console.log(`✅ 成功! Media ID: ${JSON.stringify(response.data)}`);
|
|
return response.data;
|
|
} catch (err) {
|
|
console.log(`❌ 失败 - ${err.response?.status || '网络错误'}`);
|
|
if (err.response?.data) {
|
|
console.log(` 数据: ${JSON.stringify(err.response.data)}`);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
async function main() {
|
|
const filePath = "C:\\Users\\ALC\\.openclaw\\workspace\\yahoo_japan_screenshot.jpg";
|
|
|
|
console.log('获取 Access Token...');
|
|
const accessToken = await getAccessToken();
|
|
console.log('✅ Access Token 获取成功\n');
|
|
|
|
await testUpload(accessToken, filePath);
|
|
}
|
|
|
|
main().catch(console.error);
|