zy_mf_create_link.js 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. let post_data = {}
  23. if(book_info.data.totalChapterNum==0){
  24. post_data = {
  25. access_token:token,
  26. name:`${t_data.product_name}_${main_info.id}`,
  27. source:"toutiao2", //媒体 - 抖音小程序 只能使用 "toutiao2" - 微信小程序可选项如下 - bili B站/ - toutiao2 头条2.0 - gdt3 广点通3.0
  28. start_pay_section:start_pay_section, //广告解锁章节
  29. book_chapter:zy_conifg.book_chapter, //调起章节
  30. book_id:parseInt(t_data.product_id),
  31. callback_conf_reseller_id:zy_conifg.callback_conf_reseller_id, //回传策略ID
  32. owner:zy_conifg.owner, //创建用户id
  33. app_key:zy_conifg.app_key, //应用Key
  34. free_word_count:free_word_count, //超短篇免费字数
  35. unlock_gradients:unlock_gradients //[{"end_unlock_count":999,"start_unlock_count":0,"unlock_word_count":80}] //超短篇单本书解锁次数
  36. }
  37. }else{
  38. post_data = {
  39. access_token:token,
  40. name:`${t_data.product_name}_${main_info.id}`,
  41. source:"toutiao2", //媒体 - 抖音小程序 只能使用 "toutiao2" - 微信小程序可选项如下 - bili B站/ - toutiao2 头条2.0 - gdt3 广点通3.0
  42. start_pay_section:start_pay_section, //广告解锁章节
  43. book_chapter:zy_conifg.book_chapter, //调起章节
  44. book_id:parseInt(t_data.product_id),
  45. callback_conf_reseller_id:zy_conifg.callback_conf_reseller_id, //回传策略ID
  46. owner:zy_conifg.owner, //创建用户id
  47. app_key:zy_conifg.app_key, //应用Key
  48. }
  49. }
  50. // console.log("post_data:",post_data)
  51. let response = await clinet.post(`https://openapi-gaia.zhangyue.com/opendata/reseller/free/book/link/create`,post_data)
  52. let promotion_info = null
  53. if(response.data.code!=0){
  54. console.error("get_zy_account_list error:",response)
  55. }else{
  56. promotion_info = response.data.body
  57. }
  58. if(promotion_info==null){
  59. console.error("promotion_info==null")
  60. throw response.data
  61. }
  62. let start_page = promotion_info.start_page
  63. let start_param = promotion_info.start_params
  64. t_data.promotion_id = promotion_info.channel_id
  65. t_data.start_page = start_page
  66. t_data.start_param = start_param
  67. console.log('t_data:',t_data)
  68. await call_back(t_data,null)
  69. } catch (error) {
  70. await call_back(t_data,error)
  71. return null;
  72. }
  73. }
  74. module.exports = CMD;