const fetch = require('node-fetch'); // Node.js 18以下版本需要安装 node-fetch
const tools = require('../../../tools');
const helper = require('../../helper');
const config  = require('../../../etc/config.json')
const CMD = {}
CMD.get_qm_account_list = async function () {
    const url = 'https://new-media-fx.qimao.com/api/account/optimizer/list';
    // 请求参数
    const params = new URLSearchParams({
        page: '1',
        page_size: '50',
        env: '',
        // t: Date.now()  // 当前时间戳
        t:"1746256708347"
    });
    // 请求头
    var headers = {
        "accept": "application/json, text/plain, */*",
        "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
        "app-external-id": "",
        "authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBY2NvdW50SUQiOjU0NDA1NjQxNjM3MTI4MjExMSwiQWNjb3VudE5hbWUiOiJ6aHVveXVlIiwiVGltZVN0YW1wIjoxNzQ2MjU1MjQ1LCJDbGllbnRJUCI6IjEyMS4zMy4yMTcuMjE4IiwiQnVmZmVyVGltZSI6MCwiZXhwIjoxNzQ2MzQxNjQ1LCJpc3MiOiJxbV9uZXdfbWVkaWFfZngiLCJuYmYiOjE3NDYyNTUyNDUsIkVudiI6InJlbGVhc2UiLCJJc1NpbXVsYXRpb25Mb2dpbiI6ZmFsc2V9.Mb-ANPtISIoYJvA630D_o_ydZxQ2AfWiTONGfM2PTkc",
        "project": "",
        "sec-ch-ua": "\"Microsoft Edge\";v=\"135\", \"Not-A.Brand\";v=\"8\", \"Chromium\";v=\"135\"",
        "sec-ch-ua-mobile": "?1",
        "sec-ch-ua-platform": "\"Android\"",
        "sec-fetch-dest": "empty",
        "sec-fetch-mode": "cors",
        "sec-fetch-site": "same-origin",
        "signature": "68c4f2ebfca43dca1e012a5ac6fa502ac64531e63140ca68151c21e77df60b98",
        "target-id": "",
        "cookie": "sensorsdata2015jssdkcross=%7B%22%24device_id%22%3A%22193bdc124645e2-0cbeaee172d4ce8-4c657b58-921600-193bdc12465567%22%7D; sa_jssdk_2015_new-media-fx_qimao_com=%7B%22distinct_id%22%3A%22193bdc124645e2-0cbeaee172d4ce8-4c657b58-921600-193bdc12465567%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E5%BC%95%E8%8D%90%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC%22%2C%22%24latest_referrer%22%3A%22http%3A%2F%2F120.79.128.142%3A4999%2F%22%7D%2C%22identities%22%3A%22eyIkaWRlbnRpdHlfY29va2llX2lkIjoiMTkzYmRjMTI0NjQ1ZTItMGNiZWFlZTE3MmQ0Y2U4LTRjNjU3YjU4LTkyMTYwMC0xOTNiZGMxMjQ2NTU2NyJ9%22%2C%22history_login_id%22%3A%7B%22name%22%3A%22%22%2C%22value%22%3A%22%22%7D%7D; acw_tc=0aef832217460080378292172e00524a7f76928c9ddbb68a937b2c3f32083d",
        "Referer": "https://new-media-fx.qimao.com/backend/account-manage/index?projectId=0&appId=0&accountId=0",
        "Referrer-Policy": "strict-origin-when-cross-origin"
    };


    // headers['authorization'] = await tools.getQMToken()
    try {
        const response = await fetch(`${url}?${params}`, {
            method: 'GET',
            headers: headers
        });

        const data = await response.json();

        if(data.code!=200){
            throw data
        }
        
        console.log('响应状态:', response.status);
        console.log('响应数据:', data);
        return data.data;
    } catch (error) {
        console.error('请求错误:', error);
        throw error;
    }
}

// Node.js 18及以上版本可以直接运行
// Node.js 18以下版本需要先安装 node-fetch:
// npm install node-fetch@2

module.exports = CMD;