dz_create_link.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 signKey = helper.md5(config.dianzhong_config.clientId+config.dianzhong_config.token+timestamp)
  17. for (let index = 0; index < chongzhi_list.length; index++) {
  18. const cz_obj = chongzhi_list[index];
  19. if(cz_obj.id==chongzhi_id){
  20. recharge_template_id = cz_obj.value
  21. break
  22. }
  23. }
  24. for (let index = 0; index < huichuan_list.length; index++) {
  25. const hc_obj = huichuan_list[index];
  26. if(hc_obj.id==huichuan_id){
  27. call_back_template_id = hc_obj.value
  28. break
  29. }
  30. }
  31. try {
  32. let client = new HttpClient()
  33. let clientId= config.dianzhong_config.clientId;
  34. let bookId = data.product_id;
  35. let chapterIdx = 1;
  36. let name = data.product_name;
  37. let mediaSource = "dy";
  38. let channelId = main_info.channelId;
  39. let batchId = recharge_template_id;
  40. let CallbackConfigId = call_back_template_id;
  41. let fromDrId = "zywzfromDrId";
  42. let chapterChargeStart = 1;
  43. let chapterKandian = 1;
  44. let postData ={
  45. signKey:signKey,
  46. clientId:clientId,
  47. timestamp:timestamp,
  48. bookId:bookId,
  49. chapterIdx:chapterIdx,
  50. name:`${name}${main_info.id}`,
  51. mediaSource:mediaSource,
  52. channelId:channelId,
  53. batchId:batchId,
  54. CallbackConfigId:CallbackConfigId,
  55. fromDrId:fromDrId,
  56. chapterChargeStart:chapterChargeStart,
  57. chapterKandian:chapterKandian
  58. }
  59. // console.log("postData:",postData)
  60. let response = await client.post(config.dianzhong_config.create_link_host,postData)
  61. if(response.code!=1){
  62. throw response
  63. }
  64. let params = response.data.path.split('?')
  65. let start_page = params[0]
  66. let start_param = params[1]
  67. let promotion_id = response.data.referralId
  68. data.start_page = start_page
  69. data.start_param = start_param
  70. data.promotion_id = promotion_id
  71. // console.log("response:",response)
  72. call_back(data,null)
  73. } catch (error) {
  74. call_back(data,error)
  75. console.error('dz_create_link :Error:', error);
  76. // 处理错误
  77. }
  78. }
  79. module.exports = CMD;