yw_search_book.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. const fetch = require('node-fetch'); // Node.js 18以下版本需要安装 node-fetch
  2. const tools = require('../../../tools');
  3. const helper = require('../../helper');
  4. const redis_help = require('../../use_redis');
  5. const CMD = {}
  6. CMD.search_id = async function (bookId) {
  7. try {
  8. let OPENSESSID = await redis_help.getKeyValue("OPENSESSID")
  9. const response = await fetch(`https://open.yuewen.com/api/wechatspread/bookSpread?cbid=${bookId}&page=1&version=2&order_field=allwords&order_type=0&content_type=1&category1=-1&allwords=-1&category2=-1&isfinish=-1&level=-1`, {
  10. "headers": {
  11. "accept": "application/json, text/plain, */*",
  12. "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
  13. "priority": "u=1, i",
  14. "sec-ch-ua": "\"Microsoft Edge\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"",
  15. "sec-ch-ua-mobile": "?0",
  16. "sec-ch-ua-platform": "\"Windows\"",
  17. "sec-fetch-dest": "empty",
  18. "sec-fetch-mode": "cors",
  19. "sec-fetch-site": "same-origin",
  20. "cookie": `Hm_lvt_990f9ab9737a266517417cc2949bb3f4=1736394515; csrfToken=9EeGTClKZ3EJFZjIQDcVozZj; OPENSESSID=${OPENSESSID}; yw_open_token=6784835e6c51a; is_read_notice=6784835e6c51a; sidebarStatus=0`,
  21. "Referer": "https://open.yuewen.com/new/library",
  22. "Referrer-Policy": "strict-origin-when-cross-origin"
  23. },
  24. "body": null,
  25. "method": "GET"
  26. });
  27. const data = await response.json();
  28. if(data.code!=0){
  29. throw data
  30. }
  31. // console.log('响应状态:', response.status);
  32. // console.log('响应数据:', data.data.list[0]);
  33. if(data.data.list.length<=0){
  34. return null
  35. }
  36. let book_info = data.data.list[0]
  37. let info = {}
  38. info.words = book_info.WordsCntShow
  39. info.book_name = book_info.BookName
  40. info.book_id = book_info.cbid
  41. info.genre = 999;
  42. if(book_info.CategoryName=="短篇"){
  43. info.genre = 3;
  44. }else{
  45. info.genre = 1;
  46. }
  47. return info;
  48. } catch (error) {
  49. return null
  50. }
  51. }
  52. // Node.js 18及以上版本可以直接运行
  53. // Node.js 18以下版本需要先安装 node-fetch:
  54. // npm install node-fetch@2
  55. module.exports = CMD;