zy_mf_create_link.js 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //执行一个创建掌阅链接任务
  2. const axios = require('axios');
  3. const helper = require('../src/helper');
  4. const config = require('../etc/config.json');
  5. const video_product_controllers = require('../src/data_manager/Controllers/video_product_controllers');
  6. const tools = require('../tools');
  7. const CMD = {}
  8. CMD.runTask = async function(t_data,main_info,PlatformInfo,call_back){
  9. // let recharge = await get_recharge_template()
  10. let zy_conifg = JSON.parse(main_info.zy_conifg)
  11. try {
  12. let token = await require('../src/api/zy_mf/get_zy_mf_token').get_token()
  13. console.log("token:",token)
  14. let clinet = tools.getOneNewClinet()
  15. let book_info = await video_product_controllers.getProductData({book_id:t_data.product_id})
  16. if(book_info.success==false){
  17. throw "没有找到这本书:"+t_data.product_id
  18. }
  19. let unlock_gradients = zy_conifg.unlock_gradients
  20. let free_word_count = zy_conifg.free_word_count
  21. let start_pay_section = zy_conifg.start_pay_section!=0?zy_conifg.start_pay_section:book_info.data.default_pay_section
  22. if(start_pay_section <= 0){
  23. start_pay_section = 1
  24. }
  25. let post_data = {}
  26. if(book_info.data.totalChapterNum==0){
  27. post_data = {
  28. access_token:token,
  29. name:`${t_data.product_name}_${main_info.id}`,
  30. source:"toutiao2", //媒体 - 抖音小程序 只能使用 "toutiao2" - 微信小程序可选项如下 - bili B站/ - toutiao2 头条2.0 - gdt3 广点通3.0
  31. start_pay_section:start_pay_section, //广告解锁章节
  32. book_chapter:zy_conifg.book_chapter, //调起章节
  33. book_id:parseInt(t_data.product_id),
  34. callback_conf_reseller_id:zy_conifg.callback_conf_reseller_id, //回传策略ID
  35. owner:zy_conifg.owner, //创建用户id
  36. app_key:zy_conifg.app_key, //应用Key
  37. free_word_count:free_word_count, //超短篇免费字数
  38. unlock_gradients:unlock_gradients //[{"end_unlock_count":999,"start_unlock_count":0,"unlock_word_count":80}] //超短篇单本书解锁次数
  39. }
  40. }else{
  41. post_data = {
  42. access_token:token,
  43. name:`${t_data.product_name}_${main_info.id}`,
  44. source:"toutiao2", //媒体 - 抖音小程序 只能使用 "toutiao2" - 微信小程序可选项如下 - bili B站/ - toutiao2 头条2.0 - gdt3 广点通3.0
  45. start_pay_section:start_pay_section, //广告解锁章节
  46. book_chapter:zy_conifg.book_chapter, //调起章节
  47. book_id:parseInt(t_data.product_id),
  48. callback_conf_reseller_id:zy_conifg.callback_conf_reseller_id, //回传策略ID
  49. owner:zy_conifg.owner, //创建用户id
  50. app_key:zy_conifg.app_key, //应用Key
  51. }
  52. }
  53. // console.log("post_data:",post_data)
  54. let response = await clinet.post(`https://openapi-gaia.zhangyue.com/opendata/reseller/free/book/link/create`,post_data)
  55. let promotion_info = null
  56. if(response.data.code!=0){
  57. console.error("get_zy_account_list error:",response)
  58. }else{
  59. promotion_info = response.data.body
  60. }
  61. if(promotion_info==null){
  62. console.error("promotion_info==null")
  63. throw response.data
  64. }
  65. let start_page = promotion_info.start_page
  66. let start_param = promotion_info.start_params
  67. t_data.promotion_id = promotion_info.channel_id
  68. t_data.start_page = start_page
  69. t_data.start_param = start_param
  70. console.log('t_data:',t_data)
  71. await call_back(t_data,null)
  72. } catch (error) {
  73. await call_back(t_data,error)
  74. return null;
  75. }
  76. }
  77. module.exports = CMD;