//执行一个创建黑岩链接任务 const CMD = {} const axios = require('axios'); let get_hy_recharge_template = require('../src/api/hy/get_hy_recharge_template') let get_hy_paid_point = require('../src/api/hy/get_hy_paid_point') let get_hy_call_back_template = require('../src/api/hy/get_hy_call_back_template'); const tools = require('../tools'); //卡点 function get_paid_point(book_id,kadian_name,call_back){ let chapter_num = parseInt(kadian_name) if(chapter_num==0||chapter_num>10){ return call_back("") } get_hy_paid_point.get_hy_paid_point(book_id,(data)=>{ if(chapter_num>=data.rows.length){ call_back("") }else{ call_back(""+chapter_num) } }) } //回传 function get_call_back(huichuan_name,call_back){ get_hy_call_back_template.get_callback_template((data)=>{ if(data.code==200){ let is_find = false for (let index = 0; index < data.data.length; index++) { const obj = data.data[index]; if(obj.value==huichuan_name){ is_find = true call_back(obj.key) break } } if(!is_find){ call_back('6') } }else{ call_back('6') } }) } function get_recharge_template(book_id,chongzhi_name,call_back){ get_hy_recharge_template.get_recharge_template(book_id,(data)=>{ if(data.code==200){ let is_find = false for (let index = 0; index < data.data.length; index++) { const obj = data.data[index]; if(obj.value==chongzhi_name){ is_find = true call_back(obj.key) break } } if(!is_find){ call_back('0') } }else{ call_back('0') } }) } CMD.runTask = function(data,main_info,PlatformInfo,call_back){ // console.log("data:",data) // console.log("PlatformInfo:",PlatformInfo) // console.log("main_info:",main_info.tg_link_config) let tg_link_config = JSON.parse(main_info.tg_link_config) let kadian_id = tg_link_config['kadian_id'] let chongzhi_id = tg_link_config['chongzhi_id'] let huichuan_id = tg_link_config['huichuan_id'] let chongzhi_list = JSON.parse(PlatformInfo.chongzhi) let huichuan_list = JSON.parse(PlatformInfo.huichuan) let kadian_list = JSON.parse(PlatformInfo.kadian) let chongzhi_name = null let huichuan_name = null let kadian_name = null for (let index = 0; index < chongzhi_list.length; index++) { const cz_obj = chongzhi_list[index]; if(cz_obj.id==chongzhi_id){ chongzhi_name = cz_obj.name break } } for (let index = 0; index < huichuan_list.length; index++) { const hc_obj = huichuan_list[index]; if(hc_obj.id==huichuan_id){ huichuan_name = hc_obj.name break } } for (let index = 0; index < kadian_list.length; index++) { const kd_obj = kadian_list[index]; if(kd_obj.id==kadian_id){ kadian_name = kd_obj.name break } } // console.log("chongzhi_name:",chongzhi_name) // console.log("huichuan_name:",huichuan_name) // console.log("kadian_name:",kadian_name) let num = 0; let tg_config = { chongzhi_key:'', huichuan_key:'', kadian_key:'' } // start_page: 'pages/readPage/chapter', // start_param: 'pid=1809545659599544322&bookId=1849369533770342401&linkId=1860983668277948418&channels=4&hyChannel=1' let create_hy_link = async () =>{ let topUpTemplateId = tg_config.chongzhi_key; //充值模板 let passBackTemplateId = tg_config.huichuan_key; //回传模板 let paidPoint = tg_config.kadian_key; //卡点 console.log("tg_config:",tg_config) const postData = { cmd:"create_link", name:data.product_name, bookId:data.product_id, topUpTemplateId:topUpTemplateId, passBackTemplateId:passBackTemplateId, paidPoint:paidPoint, token:await tools.getHyToken() }; axios.post('http://127.0.0.1:8080', postData) .then(response => { let params = response.data.received_data.fullPath.split('?') // let appId = response.data.data.appId let start_page = params[0] let start_param = params[1] const linkId = start_param.match(/linkId=([^&]*)/)[1]; data.promotion_id = linkId data.start_page = start_page data.start_param = start_param // console.log("response.data.received_data:",response.data.received_data) call_back(data) }) .catch(error => { call_back(null) console.error('There was an error!', error); }); } let count_num = ()=>{ num++; if(num==3){ create_hy_link() } } get_recharge_template(data.book_id,chongzhi_name,(chongzhi_key)=>{ tg_config.chongzhi_key = chongzhi_key count_num() }) get_call_back(huichuan_name,(huichuan_key)=>{ tg_config.huichuan_key = huichuan_key count_num() }) get_paid_point(data.book_id,kadian_name,(kadian_key)=>{ tg_config.kadian_key = kadian_key count_num() }) } module.exports = CMD;