fq_search_book.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. const axios = require('axios');
  2. const querystring = require('querystring');
  3. const config = require("../../../etc/config.json")
  4. const helper = require('../../helper');
  5. const https = require('https');
  6. const tools = require('../../../tools');
  7. const fetch = require('node-fetch');
  8. const CMD = {}
  9. const cookies = {
  10. passport_csrf_token: 'f6e9bb6f5be3ac1ca88eaef7ec45af18',
  11. sid_guard: '975a2c17dcea431af25f475a39199337%7C1751542938%7C5184000%7CMon%2C+01-Sep-2025+11%3A42%3A18+GMT',
  12. sessionid: '975a2c17dcea431af25f475a39199337',
  13. adUserId: '3657398892890426',
  14. distributorId: '1823565160001931'
  15. }
  16. const temp_cookie = `sid_guard=${cookies.sid_guard}; sessionid=${cookies.sessionid}`
  17. CMD.根据番茄免费ID查询付费书籍 = async function(bookId,isTaskRequire = false){
  18. if(!isTaskRequire){
  19. return null
  20. }
  21. await tools.tj_api("根据番茄免费ID查询付费书籍")
  22. let client = tools.getOneNewClinet()
  23. try{
  24. let response = await client.get(`${config.fanqie_config.find_child_book_host}${bookId}`)
  25. if(response.data["code"]==401){
  26. throw response.data["msg"]
  27. }
  28. let book_info = response.data
  29. // console.log(book_info)
  30. let info = {}
  31. info.words = book_info.word_count
  32. info.book_name = book_info.book_name
  33. info.book_id = book_info.book_id
  34. info.publish_time = book_info.on_shelf_time
  35. info.author = book_info.author
  36. if(book_info.genre==8){
  37. info.genre = 3;
  38. }else{
  39. info.genre = 1;
  40. }
  41. return info;
  42. }catch(e){
  43. console.error("qm_find_parent_book error:",e)
  44. return null
  45. }
  46. }
  47. CMD.根据番茄付费ID查询免费书籍 = async function(bookId,isTaskRequire = false){
  48. if(!isTaskRequire){
  49. return null
  50. }
  51. await tools.tj_api("根据番茄付费ID查询免费书籍")
  52. let client = tools.getOneNewClinet()
  53. try{
  54. let response = await client.get(`${config.fanqie_mf_config.find_parent_book_host}${bookId}`)
  55. if(response.data["code"]==401){
  56. throw response.data["msg"]
  57. }
  58. let book_info = response.data
  59. let info = {}
  60. info.words = book_info.ad_word_number
  61. info.book_name = book_info.book_name
  62. info.book_id = book_info.book_id
  63. info.publish_time = book_info.on_shelf_time
  64. info.author = book_info.author
  65. if(book_info.genre==8){
  66. info.genre = 3;
  67. }else{
  68. info.genre = 1;
  69. }
  70. return info;
  71. }catch(e){
  72. console.error("qm_find_parent_book error:",e)
  73. return null
  74. }
  75. }
  76. CMD.search_id = async function(bookId,distributorId){
  77. const postData = {
  78. distributor_id: distributorId,
  79. ts: helper.getCurrentUnixTimestamp(),
  80. sign: helper.getSign(distributorId,config.fanqie_config.secretKey),
  81. book_id: bookId
  82. };
  83. var url = `https://www.changdunovel.com/novelsale/openapi/content/book_meta/v1/?distributor_id=${postData.distributor_id}&ts=${postData.ts}&sign=${postData.sign}&book_id=${postData.book_id}`
  84. console.log("url",url)
  85. let response = await axios.get(url)
  86. return response.data
  87. }
  88. // 设置 Cookie
  89. CMD.search_name = function(keyword){
  90. // 搜索关键词
  91. const encodedKeyword = encodeURIComponent(keyword); // 对关键词进行 URL 编码
  92. // 设置正确的 Cookie 字符串
  93. const cookie = 'passport_csrf_token=82f80619e2d3c3eb0aa7962d7c94305e; sid_tt=c00d65a0717e75e79ad8aecaa82f4064; sessionid=c00d65a0717e75e79ad8aecaa82f4064';
  94. // 设置请求的 URL
  95. const url = `https://www.changdunovel.com/novelsale/distributor/content/book/list/v1?permission_statuses=3,4&search_type=2&query=${encodedKeyword}&page_index=0&page_size=10`;
  96. // 设置请求头
  97. const headers = {
  98. 'Accept': 'application/json, text/plain, */*',
  99. 'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
  100. 'Agw-Js-Conv': 'str',
  101. 'Appid': '546801',
  102. 'Apptype': '1',
  103. 'Cache-Control': 'no-cache',
  104. 'Cookie': cookie,
  105. 'Distributorid': '1814786227164185',
  106. 'Pragma': 'no-cache',
  107. 'Priority': 'u=1, i',
  108. 'Referer': `https://www.changdunovel.com/sale/novel/list?permission_statuses=3%2C4&search_type=2&query=${encodedKeyword}&page_index=1&page_size=10`,
  109. 'Sec-Ch-Ua': '"Chromium";v="130", "Google Chrome";v="130", "Not?A_Brand";v="99"',
  110. 'Sec-Ch-Ua-Mobile': '?0',
  111. 'Sec-Ch-Ua-Platform': '"macOS"',
  112. 'Sec-Fetch-Dest': 'empty',
  113. 'Sec-Fetch-Mode': 'cors',
  114. 'Sec-Fetch-Site': 'same-origin',
  115. 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36',
  116. 'X-Secsdk-Csrf-Token': 'DOWNGRADE'
  117. };
  118. // 执行请求
  119. axios.get(url, { headers })
  120. .then(response => {
  121. console.log(response.data); // 输出结果
  122. })
  123. .catch(error => {
  124. console.error('Error:', error.message); // 输出错误信息
  125. });
  126. }
  127. CMD.search_new_id = async function(bookId,call_back){
  128. const url = `${config.fanqie_config.search_id}${bookId}&t=1`
  129. try{
  130. let client = tools.getOneNewClinet()
  131. let response = await client.get(url)
  132. // console.log("book_info:",response.data)
  133. if(response.data["code"]==401){
  134. throw response.data["msg"]
  135. }
  136. let book_info = response.data
  137. let info = {}
  138. info.words = book_info.word_count
  139. info.book_name = book_info.book_name
  140. info.book_id = book_info.book_id
  141. info.publish_time = book_info.on_shelf_time
  142. info.author = book_info.author
  143. if(book_info.genre==8){
  144. info.genre = 3;
  145. }else{
  146. info.genre = 1;
  147. }
  148. return info;
  149. }catch(e){
  150. console.error("search_new_id error:",e)
  151. return null
  152. }
  153. }
  154. CMD.search_mf_new_id = async function(bookId){
  155. const url = `${config.fanqie_mf_config.search_id}${bookId}&t=1`
  156. try{
  157. let client = tools.getOneNewClinet()
  158. let response = await client.get(url)
  159. if(response.data["code"]==401){
  160. throw response.data["msg"]
  161. }
  162. let book_info = response.data
  163. let info = {}
  164. // console.log("book_info:",book_info)
  165. info.words = book_info.word_count
  166. info.book_name = book_info.book_name
  167. info.book_id = book_info.book_id
  168. info.publish_time = book_info.on_shelf_time
  169. info.author = book_info.author
  170. if(book_info.genre==8){
  171. info.genre = 3;
  172. }else{
  173. info.genre = 1;
  174. }
  175. return info;
  176. }catch(e){
  177. console.error("search_new_id error:",e)
  178. return null
  179. }
  180. }
  181. module.exports = CMD;