hy_create_link.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //执行一个创建黑岩链接任务
  2. const CMD = {}
  3. const axios = require('axios');
  4. let get_hy_recharge_template = require('../src/api/hy/get_hy_recharge_template')
  5. let get_hy_paid_point = require('../src/api/hy/get_hy_paid_point')
  6. let get_hy_call_back_template = require('../src/api/hy/get_hy_call_back_template');
  7. const tools = require('../tools');
  8. //卡点
  9. function get_paid_point(book_id,kadian_name,call_back){
  10. let chapter_num = parseInt(kadian_name)
  11. if(chapter_num==0||chapter_num>10){
  12. return call_back("")
  13. }
  14. get_hy_paid_point.get_hy_paid_point(book_id,(data)=>{
  15. if(chapter_num>=data.rows.length){
  16. call_back("")
  17. }else{
  18. call_back(""+chapter_num)
  19. }
  20. })
  21. }
  22. //回传
  23. function get_call_back(huichuan_name,call_back){
  24. get_hy_call_back_template.get_callback_template((data)=>{
  25. if(data.code==200){
  26. let is_find = false
  27. for (let index = 0; index < data.data.length; index++) {
  28. const obj = data.data[index];
  29. if(obj.value==huichuan_name){
  30. is_find = true
  31. call_back(obj.key)
  32. break
  33. }
  34. }
  35. if(!is_find){
  36. call_back('6')
  37. }
  38. }else{
  39. call_back('6')
  40. }
  41. })
  42. }
  43. function get_recharge_template(book_id,chongzhi_name,call_back){
  44. get_hy_recharge_template.get_recharge_template(book_id,(data)=>{
  45. if(data.code==200){
  46. let is_find = false
  47. for (let index = 0; index < data.data.length; index++) {
  48. const obj = data.data[index];
  49. if(obj.value==chongzhi_name){
  50. is_find = true
  51. call_back(obj.key)
  52. break
  53. }
  54. }
  55. if(!is_find){
  56. call_back('0')
  57. }
  58. }else{
  59. call_back('0')
  60. }
  61. })
  62. }
  63. CMD. = function(data,main_info,PlatformInfo,call_back){
  64. // console.log("data:",data)
  65. // console.log("PlatformInfo:",PlatformInfo)
  66. // console.log("main_info:",main_info.tg_link_config)
  67. let tg_link_config = JSON.parse(main_info.tg_link_config)
  68. let kadian_id = tg_link_config['kadian_id']
  69. let chongzhi_id = tg_link_config['chongzhi_id']
  70. let huichuan_id = tg_link_config['huichuan_id']
  71. let chongzhi_list = JSON.parse(PlatformInfo.chongzhi)
  72. let huichuan_list = JSON.parse(PlatformInfo.huichuan)
  73. let kadian_list = JSON.parse(PlatformInfo.kadian)
  74. let chongzhi_name = null
  75. let huichuan_name = null
  76. let kadian_name = null
  77. for (let index = 0; index < chongzhi_list.length; index++) {
  78. const cz_obj = chongzhi_list[index];
  79. if(cz_obj.id==chongzhi_id){
  80. chongzhi_name = cz_obj.name
  81. break
  82. }
  83. }
  84. for (let index = 0; index < huichuan_list.length; index++) {
  85. const hc_obj = huichuan_list[index];
  86. if(hc_obj.id==huichuan_id){
  87. huichuan_name = hc_obj.name
  88. break
  89. }
  90. }
  91. for (let index = 0; index < kadian_list.length; index++) {
  92. const kd_obj = kadian_list[index];
  93. if(kd_obj.id==kadian_id){
  94. kadian_name = kd_obj.name
  95. break
  96. }
  97. }
  98. // console.log("chongzhi_name:",chongzhi_name)
  99. // console.log("huichuan_name:",huichuan_name)
  100. // console.log("kadian_name:",kadian_name)
  101. let num = 0;
  102. let tg_config = {
  103. chongzhi_key:'',
  104. huichuan_key:'',
  105. kadian_key:''
  106. }
  107. // start_page: 'pages/readPage/chapter',
  108. // start_param: 'pid=1809545659599544322&bookId=1849369533770342401&linkId=1860983668277948418&channels=4&hyChannel=1'
  109. let create_hy_link = async () =>{
  110. let topUpTemplateId = tg_config.chongzhi_key; //充值模板
  111. let passBackTemplateId = tg_config.huichuan_key; //回传模板
  112. let paidPoint = tg_config.kadian_key; //卡点
  113. console.log("tg_config:",tg_config)
  114. const postData = {
  115. cmd:"create_link",
  116. name:data.product_name,
  117. bookId:data.product_id,
  118. topUpTemplateId:topUpTemplateId,
  119. passBackTemplateId:passBackTemplateId,
  120. paidPoint:paidPoint,
  121. token:await tools.getHyToken()
  122. };
  123. axios.post('http://127.0.0.1:8080', postData)
  124. .then(response => {
  125. let params = response.data.received_data.fullPath.split('?')
  126. // let appId = response.data.data.appId
  127. let start_page = params[0]
  128. let start_param = params[1]
  129. const linkId = start_param.match(/linkId=([^&]*)/)[1];
  130. data.promotion_id = linkId
  131. data.start_page = start_page
  132. data.start_param = start_param
  133. // console.log("response.data.received_data:",response.data.received_data)
  134. call_back(data)
  135. })
  136. .catch(error => {
  137. call_back(null)
  138. console.error('There was an error!', error);
  139. });
  140. }
  141. let count_num = ()=>{
  142. num++;
  143. if(num==3){
  144. create_hy_link()
  145. }
  146. }
  147. get_recharge_template(data.book_id,chongzhi_name,(chongzhi_key)=>{
  148. tg_config.chongzhi_key = chongzhi_key
  149. count_num()
  150. })
  151. get_call_back(huichuan_name,(huichuan_key)=>{
  152. tg_config.huichuan_key = huichuan_key
  153. count_num()
  154. })
  155. get_paid_point(data.book_id,kadian_name,(kadian_key)=>{
  156. tg_config.kadian_key = kadian_key
  157. count_num()
  158. })
  159. }
  160. module.exports = CMD;