qm_new_create_link.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. const fetch = require('node-fetch'); // Node.js 18以下版本需要安装 node-fetch
  2. const tools = require('../tools');
  3. const helper = require('../src/helper');
  4. const config = require('../etc/config.json')
  5. const CMD = {}
  6. CMD.runTask = async function (data,main_info,PlatformInfo,call_back) {
  7. let timestamp = helper.getCurrentUnixTimestamp()
  8. let tg_link_config = JSON.parse(main_info.tg_link_config)
  9. let chongzhi_id = tg_link_config['chongzhi_id']
  10. let huichuan_id = tg_link_config['huichuan_id']
  11. let f_chongzhi_id = tg_link_config['f_chongzhi_id']
  12. let chongzhi_list = JSON.parse(PlatformInfo.chongzhi)
  13. let huichuan_list = JSON.parse(PlatformInfo.huichuan)
  14. let f_chongzhi_list = JSON.parse(PlatformInfo.f_chongzhi)
  15. let recharge_template_id = ""
  16. let f_recharge_template_id = ""
  17. let call_back_template_id = ""
  18. for (let index = 0; index < chongzhi_list.length; index++) {
  19. const cz_obj = chongzhi_list[index];
  20. if(cz_obj.id==chongzhi_id){
  21. recharge_template_id = cz_obj.value
  22. break
  23. }
  24. }
  25. for (let index = 0; index < huichuan_list.length; index++) {
  26. const hc_obj = huichuan_list[index];
  27. if(hc_obj.id==huichuan_id){
  28. call_back_template_id = hc_obj.value
  29. break
  30. }
  31. }
  32. for (let index = 0; index < f_chongzhi_list.length; index++) {
  33. const cz_obj = f_chongzhi_list[index];
  34. if(cz_obj.id==f_chongzhi_id){
  35. f_recharge_template_id = cz_obj.value
  36. break
  37. }
  38. }
  39. let param_list = main_info.qm_id.split(',')
  40. let app_external_id = param_list[1]
  41. let target_id = param_list[0]
  42. let postData = {
  43. admin_account_name:"zhuoyue",
  44. account_id:target_id,
  45. project:PlatformInfo.mini_program_platform_id==config.wx?8:6, // 6 抖音小程序 8 微信小程序
  46. appid:main_info.app_id,
  47. book_id:data.product_id,
  48. chapter_num:1,
  49. name:data.product_name,
  50. media_id: '1', //1 巨量 2 广点通 3 百度 4 微博 5 B站
  51. postback_rule_id: call_back_template_id, //# 回传规则 value
  52. first_panel_id:recharge_template_id, //首充模板id
  53. repeated_panel_id:f_recharge_template_id, //# 复充模板id
  54. }
  55. console.log("postData:",postData)
  56. try{
  57. let client = tools.getOneNewClinet()
  58. let response = await client.post(config.qimao_config.new_create_link_host,postData)
  59. if(response.code!=0){
  60. throw response
  61. }
  62. let n_data = response.data
  63. let promotion_id = n_data.id
  64. let promotion_info = n_data.link
  65. let t_params = promotion_info.split('?')
  66. let start_page = t_params[0]
  67. let start_param = t_params[1]
  68. data.start_page = start_page
  69. data.start_param = start_param
  70. data.promotion_id = promotion_id
  71. call_back(data,null)
  72. } catch (error) {
  73. call_back(data,error)
  74. console.error('请求错误:', error);
  75. }
  76. }
  77. module.exports = CMD;