const fetch = require('node-fetch'); // Node.js 18以下版本需要安装 node-fetch
const tools = require('../../../tools');
const config  = require('../../../etc/config.json');
const redis_help = require('../../use_redis');
const helper = require('../../helper');
const CMD = {}

CMD.get_zh_call_back_template = async function() {
    try{
        let timestamp = helper.getCurrentUnixTimestamp()
        let url = `https://ecom.zhihu.com/api/km-agent/callback-rules?offset=0&limit=20`
        const response =   await fetch(url, {
            "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",
                "priority": "u=1, i",
                "sec-ch-ua": "\"Not A(Brand\";v=\"8\", \"Chromium\";v=\"132\", \"Microsoft Edge\";v=\"132\"",
                "sec-ch-ua-mobile": "?0",
                "sec-ch-ua-platform": "\"Windows\"",
                "sec-fetch-dest": "empty",
                "sec-fetch-mode": "cors",
                "sec-fetch-site": "same-origin",
                "x-requested-with": "XMLHttpRequest",
                "cookie": "_xsrf=7bCsoKjmfrIE0D36ajUc9s6CM9OxdPHQ; _zap=aa0b20fb-9951-4f27-9f66-dafff809f1a9; d_c0=ADASSwlwjxmPTrW0768vZ0BKygxzh_LFDDI=|1731902666; __zse_ck=004_RAwxSX7iODkHf=KcaqfMYfLtUB=liEm/v0fmgVHxEqKYzUEWDsJ4I5wkbR1yz3X=sAOsMm7PcwNXoQHjg5IxNkMc38yFAYS9Vcvho/AB5CWvfKZL7JZ6yb8JNCk=hJhs-xC0Hm7QqNBqkjTYlQ0LGKY50XF8sCD+ku+G/FUcrxDHtM9cxwgjtwoE7C9tAtkeLkUwyYVe6lZG1PpW/gndPL1lhcrZ53odQtwGooASih8FG2HI3W7Xpo3Bq+eqzshzK; Hm_lvt_98beee57fd2ef70ccdd5ca52b9740c49=1735787111,1735909747,1736148711; captcha_session_v2=2|1:0|10:1736148772|18:captcha_session_v2|88:YkZmazRKNXExV2dHaTkvaWIyQkJaUXpPZDFEbFNwWTR1bjNKK0dpUUdJRTcxZldZOUtFQlFSMUQzT1h1TFlNZw==|7015dcf5d48280e56784ef6d89a2b4d15352adcb1e257453c9907a664ceaa0d9; captcha_ticket_v2=2|1:0|10:1736148810|17:captcha_ticket_v2|728:eyJ2YWxpZGF0ZSI6IkNOMzFfKkxBeEhrcDFRYnhkeGxtTGRnSlZZWVdHbjhtLlc4R3BmQWl5dFNLYlA1ekZITXYydi5KRypfa3plX3poZGJRRExveDlSR3lFVDJJbmQ4Q1ZHNnJFSWkqdyppMDZKMzlXYVZJcFlIX0VHc0ZRRDBsa1BvblJrNVJldWVDNFRNeFBXRmZZcXVJWHB1Yip0ckY1SWFQdVNoS0YyKjZmUHhUKnFiOXpDaFVsc0djdHVBX1hjWENfYkNQemlxREwwSWpWekdSZHlqWUFWQ0d5aE5TaWFzZEhzdWRDWCprYy5QKkh6ajV6VU9nM2lQT296YVBxSzlXemYqcXZzRF9ENWVPU2dGQmhoUWd3d3RZb3ByT0t0M0ZpVSp3SUZsc1FmZTVMRDJwSDhTcHBOZUF4VkhWYkVEdC4zVU1USkl3SjhRWCoqb0xrKnlhU2RudDNXOElfV01mMV84RzF1d05NeUpJS0YqcmJ3MTBsejNDX2lnMFJYM2FMUTBZT04ySDFqRkpZYlNCMCpfVjJseENYdmRPMEtZanJqTEh2b3RFbERnc2xzTDF4eS5TSWZSU3owY3kxRmFpU3hadkNxV00ubUJvbExKQy5JR1BvMG1uLmtNZHRuNElMMGx6NE9DcmdKMXFHeV81aUhUMGhNajZxVTRmdFlSU1JlNUxlbkJGWWdzcnZWZnFxNVk3N192X2lfMSJ9|9a0d71076f5273fc22dd67c3e4eabb975e479e875191d79a44e51972d2d848cc; z_c0=2|1:0|10:1736148810|4:z_c0|92:Mi4xN1lrbldnQUFBQUFBTUJKTENYQ1BHU1lBQUFCZ0FsVk5TdFZvYUFCUDI3aTJFNk5MNThBZ215bXIyZVJIWXhvNXN3|707e10b967760748115ffeee34231345d9323f18a7e61ff853b0d3cf9967dae2; ecom_merchant=1857114769787609088; BEC=46faae78ffea44ab7c29d705bdab5c18",
                "Referer": "https://ecom.zhihu.com/vip-apps/out-distribution/promotion/callback/list",
                "Referrer-Policy": "no-referrer-when-downgrade"
            },
            "body": null,
            "method": "GET"
          });
    
          const data =  await response.json();
          if(data.data!=undefined&&data.data.length<=0){
            throw data
        }
          console.log('get_zh_call_back_template::响应状态:', response.status);
          console.log('get_zh_call_back_template::响应数据:', data);
          return data.data;
    }catch(error){
        console.error('get_zh_call_back_template::请求错误:', error);
        return null;
    }

}

module.exports = CMD;