| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- #!/usr/bin/env node
- /** 探测 TikHub 直连抖音 endpoint(绕过 APIG) */
- const fs = require('fs');
- const path = require('path');
- const os = require('os');
- const https = require('https');
- const xhsConf = JSON.parse(fs.readFileSync(path.join(os.homedir(), '.openclaw', 'skills', 'xiaohongshu-search-notes', 'api-config.json'), 'utf-8'));
- const TOKEN = xhsConf.endpoint.headers.Authorization.replace(/^Bearer\s+/, '');
- function req(opts, body) {
- return new Promise((resolve) => {
- const r = https.request(opts, (res) => {
- const chunks = [];
- res.on('data', (c) => chunks.push(c));
- res.on('end', () => resolve({ status: res.statusCode, body: Buffer.concat(chunks).toString('utf-8') }));
- });
- r.on('error', (e) => resolve({ status: 0, body: e.message }));
- r.setTimeout(30000, () => { r.destroy(); resolve({ status: 0, body: 'timeout' }); });
- if (body) r.write(body);
- r.end();
- });
- }
- // TikHub 官方 douyin endpoints(根据 tikhub.io 文档)
- const tries = [
- // Web 版
- ['/thapi/v1/douyin/web/fetch_general_search_result?keyword=乳酸菌素片&offset=0&count=20&sort_type=0&publish_time=0'],
- ['/thapi/v1/douyin/web/fetch_user_video_list?sec_user_id=&max_cursor=0&count=20'],
- // App 版
- ['/thapi/v1/douyin/app/v3/fetch_general_search?keyword=乳酸菌素片&cursor=0&sort_type=1&publish_time=180'],
- ['/thapi/v1/douyin/app/v1/fetch_general_search?keyword=乳酸菌素片&cursor=0'],
- // 别的可能的路径
- ['/thapi/v1/douyin/search/fetch_general_search_v2?keyword=乳酸菌素片&cursor=0'],
- ];
- (async () => {
- for (const [p] of tries) {
- const { status, body } = await req({
- hostname: 'server.fmode.cn',
- path: encodeURI(p),
- method: 'GET',
- headers: {
- Authorization: `Bearer ${TOKEN}`,
- Accept: 'application/json',
- },
- timeout: 30000,
- });
- const prev = body.slice(0, 200).replace(/\n/g, ' ');
- console.log(`[${status}] ${p.slice(0, 80)}...`);
- console.log(` ${prev}`);
- console.log('');
- await new Promise((r) => setTimeout(r, 1000));
- }
- })();
|