get_qm_all_iap_book.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. const config = require("./etc/config.json");
  2. const helper = require("./src/helper");
  3. const HttpClient = require("./src/HttpClient");
  4. const redis_help = require('./src/use_redis');
  5. const mysql = require('mysql2/promise');
  6. const tools = require("./tools");
  7. const dbConfig = config.isDebug?config.debug_mysql:config.release_mysql
  8. const CMD = {}
  9. let page_index = 1;
  10. async function processTask(){
  11. let connection = null
  12. let right_status = true
  13. try{
  14. const url = 'https://new-media-fx.qimao.com/api/content/book/list';
  15. // 请求参数
  16. let params = new URLSearchParams({
  17. page: page_index,
  18. page_size: '200',
  19. env: '',
  20. t: Date.now() // 当前时间戳
  21. });
  22. var headers = {
  23. "accept": "application/json, text/plain, */*",
  24. "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
  25. "app-external-id": "4c6e8d8709c14de9a4397b6cbb978f85",
  26. "authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBY2NvdW50SUQiOjU0NDA1NjQxNjM3MTI4MjExMSwiQWNjb3VudE5hbWUiOiJ6aHVveXVlIiwiVGltZVN0YW1wIjoxNzQyMjgzOTA0LCJDbGllbnRJUCI6IjIxOS4xMzYuMTMwLjEwNyIsIkJ1ZmZlclRpbWUiOjAsImV4cCI6MTc0MjM3MDMwNCwiaXNzIjoicW1fbmV3X21lZGlhX2Z4IiwibmJmIjoxNzQyMjgzOTA0LCJFbnYiOiJyZWxlYXNlIiwiSXNTaW11bGF0aW9uTG9naW4iOmZhbHNlfQ.smEjQMawHRwsd8VGIGfvBthX67v6BjyPGAisPkQ9oBw",
  27. "project": "reader_paid_dyminiapp",
  28. "sec-ch-ua": "\"Chromium\";v=\"134\", \"Not:A-Brand\";v=\"24\", \"Microsoft Edge\";v=\"134\"",
  29. "sec-ch-ua-mobile": "?0",
  30. "sec-ch-ua-platform": "\"Windows\"",
  31. "sec-fetch-dest": "empty",
  32. "sec-fetch-mode": "cors",
  33. "sec-fetch-site": "same-origin",
  34. "signature": "80f85f7318aea80d5257d65e522c8c51c34f82a46ed5af2b03d1dc70ca9cb224",
  35. "target-id": "544180064332673816",
  36. "cookie": "sensorsdata2015jssdkcross=%7B%22%24device_id%22%3A%22193bdc124645e2-0cbeaee172d4ce8-4c657b58-921600-193bdc12465567%22%7D; sa_jssdk_2015_new-media-fx_qimao_com=%7B%22distinct_id%22%3A%22193bdc124645e2-0cbeaee172d4ce8-4c657b58-921600-193bdc12465567%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E5%BC%95%E8%8D%90%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC%22%2C%22%24latest_referrer%22%3A%22http%3A%2F%2F120.79.128.142%3A4999%2F%22%7D%2C%22identities%22%3A%22eyIkaWRlbnRpdHlfY29va2llX2lkIjoiMTkzYmRjMTI0NjQ1ZTItMGNiZWFlZTE3MmQ0Y2U4LTRjNjU3YjU4LTkyMTYwMC0xOTNiZGMxMjQ2NTU2NyJ9%22%2C%22history_login_id%22%3A%7B%22name%22%3A%22%22%2C%22value%22%3A%22%22%7D%7D; acw_tc=0a47314817422911429748370e00476f42aaf4f0543f9e1ce0bd6746886469",
  37. "Referer": "https://new-media-fx.qimao.com/backend/book-manage/index?projectId=reader_paid_dyminiapp&appId=4c6e8d8709c14de9a4397b6cbb978f85&accountId=544180064332673816",
  38. "Referrer-Policy": "strict-origin-when-cross-origin"
  39. };
  40. headers['authorization'] = await tools.getQMToken()
  41. console.log("`${url}?${params}`:",`${url}?${params}`)
  42. const response = await fetch(`${url}?${params}`, {
  43. method: 'GET',
  44. headers: headers
  45. });
  46. const data = await response.json();
  47. if(data.code!=200){
  48. throw data
  49. }
  50. if(data.data.list.length<=0){
  51. throw 0
  52. }
  53. connection = await mysql.createConnection({
  54. ...dbConfig,
  55. multipleStatements: true
  56. });
  57. const insertSQL = `
  58. INSERT IGNORE INTO qm_iap_lib
  59. (book_id, book_name, book_origin_name, book_author,
  60. book_type_text, book_word_count, book_serial_status_text, book_channel_text,
  61. book_category_text,
  62. booklist_type_text, book_first_pay_chapter, book_paid_type, book_price_type,
  63. free_ratio,price,total_price,book_type)
  64. VALUES (?)
  65. `;
  66. for (let index = 0; index < data.data.list.length; index++) {
  67. const element = data.data.list[index];
  68. await connection.query(insertSQL, [[
  69. element.book_id+"",
  70. element.book_name,
  71. element.book_origin_name,
  72. element.book_author,
  73. element.book_type_text,
  74. element.book_word_count,
  75. element.book_serial_status_text,
  76. element.book_channel_text,
  77. element.book_category_text,
  78. element.booklist_type_text,
  79. element.book_first_pay_chapter,
  80. element.book_paid_type,
  81. element.book_price_type,
  82. element.free_ratio,
  83. element.price,
  84. element.total_price,
  85. element.book_type
  86. ]]);
  87. }
  88. }catch(e){
  89. if(e==0){
  90. right_status = false
  91. }
  92. console.error("processTask error:",e)
  93. } finally{
  94. if(right_status){
  95. page_index++;
  96. global.setTimeout(processTask, 1000);
  97. }
  98. if(connection!=null){
  99. connection.end()
  100. }
  101. }
  102. }
  103. CMD.init = async function(){
  104. redis_help.connect((results)=>{
  105. if(results){
  106. processTask();
  107. }
  108. })
  109. }
  110. CMD.init()