
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_recharge_template = async function (yw_id) {
    let res = await require('./switchApp').switchApp(yw_id)
    try {
        let OPENSESSID = await redis_help.getKeyValue("OPENSESSID")
        let timestamp = helper.getCurrentUnixTimestamp()
        console.log("OPENSESSID:",OPENSESSID)
        const response =  await fetch("https://open.yuewen.com/api/WechatWebsite/PageListChargeSettingTemplates", {
            "headers":{
                "accept": "application/json, text/plain, */*",
                "cookie": `Hm_lvt_990f9ab9737a266517417cc2949bb3f4=${timestamp}; csrfToken=ffZRRnqo6A4ngGbvAVP_zK5_; OPENSESSID=${OPENSESSID}; yw_open_token=67db7bcd069db; is_read_notice=67db7bcd069db; sidebarStatus=0`,
            },
            "body": null,
            "method": "GET"
        });

        const data = await response.json();

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

module.exports = CMD;