const tools = require('../../../tools');
const helper = require('../../helper');
const config = require('../../../etc/config.json');
const { default: axios } = require('axios');
const CMD = {}
CMD.get_callback_template = async function (distributorId) {
    try{
        // var distributorId = config.fanqie_config.distributorId;
        var secretKey = config.fanqie_config.secretKey;
        const postData = {
            distributor_id: distributorId,
            ts: helper.getCurrentUnixTimestamp(),
            sign: helper.getSign(distributorId,secretKey),
            page_index: 0,
            page_size:100,
            media_source:1
        };
        // console.log("get_recharge_template:")
        var url = config.fanqie_config.callbacklist_host
        var base_params = `/?distributor_id=${postData.distributor_id}&ts=${postData.ts}&sign=${postData.sign}`
        var other_params = `&page_index=${postData.page_index}&page_size=${postData.page_size}&media_source=${postData.media_source}`
    
        let response =  await axios.get(`${url}${base_params}${other_params}`)
    
        let data  = response.data
        if(data.code==200){
            // console.log('get_callback_template config_list:',data.config_list);
            return data.config_list
        }else{
            throw response;
        }
    }catch(error){
        console.error("get_fq_rechargeTemplate error:",error)
        return null
    }
}
module.exports = CMD;