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

CMD.switchApp = async function(yw_id,coopid=24) {
    // let res =  await require('./yw_login').yw_login()
    // console.log("res:",res.headers)
    let OPENSESSID = await redis_help.getKeyValue("OPENSESSID")
    let timestamp = helper.getCurrentUnixTimestamp()
    if(yw_id==0){
      coopid = 0
    }
    // return await fetch("https://open.yuewen.com/api/account/switchApp", {
    //     "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": `{\"coopid\":${coopid},\"appid\":${yw_id}}`,
    //     "method": "POST"
    // });

    let client = tools.getOneNewClinet( {
      "cookie": `Hm_lvt_990f9ab9737a266517417cc2949bb3f4=${timestamp}; csrfToken=ffZRRnqo6A4ngGbvAVP_zK5_; OPENSESSID=${OPENSESSID}; yw_open_token=67db7bcd069db; is_read_notice=67db7bcd069db; sidebarStatus=0`,
    })

    return await client.post("https://open.yuewen.com/api/account/switchApp",{
      coopid:coopid,
      appid:yw_id
    })
}

module.exports = CMD;