//执行一个创建掌阅链接任务 const axios = require('axios'); const helper = require('../src/helper'); const config = require('../etc/config.json'); const video_product_controllers = require('../src/data_manager/Controllers/video_product_controllers'); const tools = require('../tools'); const CMD = {} CMD.runTask = async function(t_data,main_info,PlatformInfo,call_back){ // let recharge = await get_recharge_template() let zy_conifg = JSON.parse(main_info.zy_conifg) try { let token = await require('../src/api/zy_mf/get_zy_mf_token').get_token() console.log("token:",token) let clinet = tools.getOneNewClinet() let book_info = await video_product_controllers.getProductData({book_id:t_data.product_id}) if(book_info.success==false){ throw "没有找到这本书:"+t_data.product_id } let unlock_gradients = zy_conifg.unlock_gradients let free_word_count = zy_conifg.free_word_count let start_pay_section = zy_conifg.start_pay_section!=0?zy_conifg.start_pay_section:book_info.data.default_pay_section let post_data = {} if(book_info.data.totalChapterNum==0){ post_data = { access_token:token, name:`${t_data.product_name}_${main_info.id}`, source:"toutiao2", //媒体 - 抖音小程序 只能使用 "toutiao2" - 微信小程序可选项如下 - bili B站/ - toutiao2 头条2.0 - gdt3 广点通3.0 start_pay_section:start_pay_section, //广告解锁章节 book_chapter:zy_conifg.book_chapter, //调起章节 book_id:parseInt(t_data.product_id), callback_conf_reseller_id:zy_conifg.callback_conf_reseller_id, //回传策略ID owner:zy_conifg.owner, //创建用户id app_key:zy_conifg.app_key, //应用Key free_word_count:free_word_count, //超短篇免费字数 unlock_gradients:unlock_gradients //[{"end_unlock_count":999,"start_unlock_count":0,"unlock_word_count":80}] //超短篇单本书解锁次数 } }else{ post_data = { access_token:token, name:`${t_data.product_name}_${main_info.id}`, source:"toutiao2", //媒体 - 抖音小程序 只能使用 "toutiao2" - 微信小程序可选项如下 - bili B站/ - toutiao2 头条2.0 - gdt3 广点通3.0 start_pay_section:start_pay_section, //广告解锁章节 book_chapter:zy_conifg.book_chapter, //调起章节 book_id:parseInt(t_data.product_id), callback_conf_reseller_id:zy_conifg.callback_conf_reseller_id, //回传策略ID owner:zy_conifg.owner, //创建用户id app_key:zy_conifg.app_key, //应用Key } } // console.log("post_data:",post_data) let response = await clinet.post(`https://openapi-gaia.zhangyue.com/opendata/reseller/free/book/link/create`,post_data) let promotion_info = null if(response.data.code!=0){ console.error("get_zy_account_list error:",response) }else{ promotion_info = response.data.body } if(promotion_info==null){ console.error("promotion_info==null") throw response.data } let start_page = promotion_info.start_page let start_param = promotion_info.start_params t_data.promotion_id = promotion_info.channel_id t_data.start_page = start_page t_data.start_param = start_param console.log('t_data:',t_data) await call_back(t_data,null) } catch (error) { await call_back(t_data,error) return null; } } module.exports = CMD;