123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- const fetch = require('node-fetch'); // Node.js 18以下版本需要安装 node-fetch
- const tools = require('../../../tools');
- const config = require('../../../etc/config.json');
- const redis_help = require('../../use_redis');
- const helper = require('../../helper');
- const mldbConfig = config.isDebug?config.debug_mysql:config.release_mysql
- const mysql = require('mysql2/promise');
- const CMD = {}
- CMD.search_id = async function(bookId) {
- try{
- let timestamp = helper.getCurrentUnixTimestamp()
- let token = await require('./get_zy_token').get_token()
- let app_key = "donglingstory_mini"
- let user_id = 6312
- let clinet = tools.getOneNewClinet()
- let param = `access_token=${token}&app_key=${app_key}&user_id=${user_id}&book_id=${bookId}&page=1&size=10`
- let response = await clinet.get(`https://openapi-gaia.zhangyue.com/opendata/reseller/pay/book/list?${param}`)
- let list = null
- if(response.data.code!=0){
- console.error("search_id error:",response)
- throw response.data
- }else{
- list = response.data.body.list
- }
- if(list.length<=0){
- throw list
- }
-
- let book_info = list[0]
- console.log('zy书籍::响应状态:', response.status,book_info);
- let info = {}
- info.words = book_info.word_count
- info.book_name = book_info.book_name
- info.book_id = book_info.book_id
- info.publish_time = book_info.create_time
- info.genre = 3;
- return info;
- }catch(error){
- console.error('zy书籍::请求错误:', error);
- return null;
- }
- }
- CMD.new_search_id = async function(bookId) {
- try{
- let authorization = await redis_help.getKeyValue("zy_token")
- console.log("authorization:",authorization)
- let clinet = tools.getOneNewClinet({
- // "cookie":"acw_tc=1a0c639417498037411406820e006fb57d572ffdc9c83cd8a46aaf8d19ca00",
- "authorization": authorization,
- })
- let list = null
- let response = await clinet.get(`https://gaia.zhangyue.com/gaia/v1/open_api/pay/book/getBookInfoList?reseller_id=9390&application_key=donglingstory_mini&book_ids=${bookId}&book_content_type=&author=©right_type=&category_sex=&is_complete=&total=0&page=1&size=10&sort=&order=&psize=10&scheme_id=39`)
- if(response.data.code!=0){
- console.error("new_search_id error:",response)
- throw response.data
- }else{
- list = response.data.body.list
- }
- if(list.length<0){
- throw response.data
- }
- let book_info = list[0]
- let info = {}
- console.log("book_info:",book_info)
- info.words = book_info.word_count
- info.book_name = book_info.book_name
- info.book_id = book_info.book_id
- info.publish_time = book_info.create_time
- info.totalChapterNum = book_info.chapter_count
- info.default_pay_section = book_info.default_pay_section //默认付费章节
- info.default_price = book_info.default_price // 加个
- info.fee_unit = book_info.fee_unit //10 = 整本, 20 = 千字
- info.author = book_info.author
- if(book_info.word_count<100000){
- info.genre = 3;
- }else{
- info.genre = 1;
- }
- let gender = 0
- if(book_info.category_sex=='male'){
- gender = 1
- }else if(book_info.category_sex=='female'){
- gender = 2
- }
- info.gender = gender
- return info;
- }catch(e){
- return null
- }
- }
- CMD.search_name_by_lib = async function(bookName) {
- let connection = null
- try{
- //先搜索库里是否存在
- connection = await mysql.createConnection({
- ...mldbConfig,
- multipleStatements: true
- });
- let sql = `SELECT * FROM zy_lib WHERE product_name ="${bookName}" LIMIT 1`
- let [info] = await connection.execute(sql)
- if(info.length<=0){
- throw 0
- }
- return info[0]
-
- }catch(e){
- return null
- }finally{
- if(connection!=null){
- connection.end()
- }
- }
- }
- CMD.new_search_name = async function(bookName) {
- try{
- let lib_book_info = await CMD.search_name_by_lib(bookName)
- if(bookName!=null){
- return {book_name:lib_book_info.product_name,book_id:lib_book_info.product_id}
- }
- let authorization = await redis_help.getKeyValue("zy_token")
- console.log("authorization:",authorization)
- let clinet = tools.getOneNewClinet({
- // "cookie":"acw_tc=1a0c639417498037411406820e006fb57d572ffdc9c83cd8a46aaf8d19ca00",
- "authorization": authorization,
- })
- let list = null
- let response = await clinet.get(`https://gaia.zhangyue.com/gaia/v1/open_api/search/pay/book/channel/price/getBookNameList?application_uniq_id=zhuyunstory_mini&name=${encodeURIComponent(bookName)}&page=1&size=10&scheme_id=39`)
- if(response.data.code!=0){
- console.error("new_search_id error:",response)
- throw response.data
- }else{
- list = response.data.body.items
- }
- if(list.length<0){
- throw response.data
- }
- let book_info = list[0]
- let info = {}
- info.book_name = book_info.name
- info.book_id = book_info.id
- return info;
- }catch(e){
- return null
- }
- }
- module.exports = CMD;
|