dz_create_link.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //执行一个创建点众链接任务
  2. const axios = require('axios');
  3. const helper = require('../src/helper');
  4. const config = require('../etc/config.json')
  5. const HttpClient = require('../src/HttpClient')
  6. const CMD = {}
  7. CMD.runTask = async function(data,main_info,PlatformInfo,call_back){
  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 chongzhi_list = JSON.parse(PlatformInfo.chongzhi)
  12. // let huichuan_list = JSON.parse(PlatformInfo.huichuan)
  13. let recharge_template_id = ""
  14. let call_back_template_id = ""
  15. let timestamp = helper.getCurrentUnixTimestamp()
  16. let clientId = config.dianzhong_config.clientId
  17. let token = config.dianzhong_config.token
  18. if(PlatformInfo.mini_program_platform_id==config.wx){
  19. clientId = config.dianzhong_channel_config.clientId
  20. token = config.dianzhong_channel_config.token
  21. }else if(PlatformInfo.mini_program_platform_id==config.dy){
  22. if(main_info.pay_type==0){
  23. clientId = config.dianzhong_mf_channel_config.clientId
  24. token = config.dianzhong_mf_channel_config.token
  25. }else{
  26. clientId = config.dianzhong_config.clientId
  27. token = config.dianzhong_config.token
  28. }
  29. }
  30. let signKey = helper.md5(clientId+token+timestamp)
  31. // for (let index = 0; index < chongzhi_list.length; index++) {
  32. // const cz_obj = chongzhi_list[index];
  33. // if(cz_obj.id==chongzhi_id){
  34. // recharge_template_id = cz_obj.value
  35. // break
  36. // }
  37. // }
  38. recharge_template_id = chongzhi_id
  39. // for (let index = 0; index < huichuan_list.length; index++) {
  40. // const hc_obj = huichuan_list[index];
  41. // if(hc_obj.id==huichuan_id){
  42. // call_back_template_id = hc_obj.value
  43. // break
  44. // }
  45. // }
  46. call_back_template_id = huichuan_id
  47. try {
  48. let client = new HttpClient()
  49. let bookId = data.product_id;
  50. let chapterIdx = 1;
  51. let name = data.product_name;
  52. let mediaSource = "dy";
  53. let channelId = main_info.channelId;
  54. let batchId = recharge_template_id;
  55. let CallbackConfigId = call_back_template_id;
  56. let fromDrId = "zywzfromDrId";
  57. let chapterChargeStart = 0;
  58. let chapterKandian = 0;
  59. let postData ={
  60. signKey:signKey,
  61. clientId:clientId,
  62. timestamp:timestamp,
  63. bookId:bookId,
  64. chapterIdx:chapterIdx,
  65. name:`${name}${main_info.id}`,
  66. mediaSource:mediaSource,
  67. channelId:channelId,
  68. batchId:batchId,
  69. CallbackConfigId:CallbackConfigId,
  70. fromDrId:fromDrId,
  71. chapterChargeStart:chapterChargeStart,
  72. chapterKandian:chapterKandian
  73. }
  74. console.log("postData:",postData)
  75. let response = await client.post(config.dianzhong_config.create_link_host,postData)
  76. if(response.code!=1){
  77. throw response
  78. }
  79. let params = response.data.path.split('?')
  80. let start_page = params[0]
  81. let start_param = params[1]
  82. let promotion_id = response.data.referralId
  83. data.start_page = start_page
  84. data.start_param = start_param
  85. data.promotion_id = promotion_id
  86. // console.log("response:",response)
  87. await call_back(data,null)
  88. } catch (error) {
  89. await call_back(data,error)
  90. console.error('dz_create_link :Error:', error);
  91. // 处理错误
  92. }
  93. }
  94. module.exports = CMD;