|
@@ -0,0 +1,179 @@
|
|
|
+const CMD = {}
|
|
|
+const schedule = require('node-schedule');
|
|
|
+const redis_help = require('../src/use_redis');
|
|
|
+const tools = require('../tools');
|
|
|
+const HttpClient = require('../src/HttpClient');
|
|
|
+const helper = require('../src/helper');
|
|
|
+const { ms } = require('date-fns/locale');
|
|
|
+const moment = require('moment');
|
|
|
+async function notifyMsg(msg) {
|
|
|
+
|
|
|
+ let content = ""
|
|
|
+ if(msg.番茄免费.isFail){
|
|
|
+ content+=`<font color=\"warning\">番茄免费:\nname:${msg.番茄免费.name},sid_tt:${msg.番茄免费.sid_tt}</font>\n>`
|
|
|
+ }
|
|
|
+
|
|
|
+ if(msg.番茄付费.isFail){
|
|
|
+ content+=`<font color=\"warning\">番茄付费:\nname:${msg.番茄付费.name},sid_tt:${msg.番茄付费.sid_tt}</font>\n>`
|
|
|
+ }
|
|
|
+
|
|
|
+ if(msg.阅文.isFail){
|
|
|
+ content+=`<font color=\"warning\">阅文:\nname:${msg.阅文.name},open_sessid:${msg.阅文.open_sessid}</font>\n>`
|
|
|
+ }
|
|
|
+
|
|
|
+ if(content==""){
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ let client = tools.getOneNewClinet()
|
|
|
+ let postData = {
|
|
|
+ "msgtype": "markdown",
|
|
|
+ "markdown": {
|
|
|
+ "content": `${content}`
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let response = await client.post("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=9f0de91d-8eb8-43f6-9901-a549e60a895b",postData)
|
|
|
+}
|
|
|
+
|
|
|
+CMD.test_fq_book_sid_tt = async function(book_id,sid_tt){
|
|
|
+ try{
|
|
|
+ let client =new HttpClient()
|
|
|
+ let response = await client.proxyRequest( helper.getFqRequestOpt(book_id,sid_tt))
|
|
|
+ // console.log("response:",response)
|
|
|
+ if(response['code']!=0){
|
|
|
+ return null
|
|
|
+ }
|
|
|
+ let obj = response['data']
|
|
|
+ return obj['novel_data']
|
|
|
+ }catch(e){
|
|
|
+ // return {"error_book_id":book_id,"error_sid_tt":sid_tt}
|
|
|
+ return null
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+CMD.test_fq_mf_book_sid_tt = async function(book_id,sid_tt){
|
|
|
+ try{
|
|
|
+ let client =new HttpClient()
|
|
|
+ let response = await client.proxyGet( helper.getMfFqRequestOpt(book_id,sid_tt))
|
|
|
+ // console.log("response:",response)
|
|
|
+ if(response['code']!=0){
|
|
|
+ return null
|
|
|
+ }
|
|
|
+ let obj = response['data']
|
|
|
+ return obj['book_info']
|
|
|
+ }catch(e){
|
|
|
+ // return {"error_book_id":book_id,"error_sid_tt":sid_tt}
|
|
|
+ return null
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+async function processTask(){
|
|
|
+
|
|
|
+ let content = {
|
|
|
+ "番茄免费":{
|
|
|
+ "name":"",
|
|
|
+ "sid_tt":"",
|
|
|
+ "isFail":false,
|
|
|
+ "book_id":""
|
|
|
+ },
|
|
|
+ "番茄付费":{
|
|
|
+ "name":"",
|
|
|
+ "sid_tt":"",
|
|
|
+ "isFail":false,
|
|
|
+ "book_id":""
|
|
|
+ },
|
|
|
+ "阅文":{
|
|
|
+ "name":"",
|
|
|
+ "open_sessid":"",
|
|
|
+ "isFail":false,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //1.番茄免费测试
|
|
|
+ let list = await redis_help.getKeyValue("all_fq_mf_key")
|
|
|
+ list = JSON.parse(list)
|
|
|
+ for (let index = 0; index < list.length; index++) {
|
|
|
+ let fq_mf_data = list[index];
|
|
|
+ if(fq_mf_data.canUse==1){
|
|
|
+ let book_info = await CMD.test_fq_mf_book_sid_tt("PI4RDBA5H7E",fq_mf_data.sid_tt)
|
|
|
+ if(book_info==null){
|
|
|
+ book_info = await CMD.test_fq_mf_book_sid_tt("PI4RDBA5H7E",fq_mf_data.sid_tt)
|
|
|
+ if(book_info==null){
|
|
|
+ console.log("番茄免费 fail!")
|
|
|
+ content.番茄免费.name = fq_mf_data.name
|
|
|
+ content.番茄免费.sid_tt = fq_mf_data.sid_tt
|
|
|
+ content.番茄免费.isFail = true
|
|
|
+ }else{
|
|
|
+ content.番茄免费.book_id = book_info["book_id"]
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ content.番茄免费.book_id = book_info["book_id"]
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //2.番茄付费测试
|
|
|
+ list = await redis_help.getKeyValue("all_fq_key")
|
|
|
+ list = JSON.parse(list)
|
|
|
+ for (let index = 0; index < list.length; index++) {
|
|
|
+ let fq_data = list[index];
|
|
|
+ if(fq_data.canUse==1){
|
|
|
+ let book_info = await CMD.test_fq_book_sid_tt("PI43VGRHTX6",fq_data.sid_tt)
|
|
|
+ if(book_info==null){
|
|
|
+ book_info = await CMD.test_fq_book_sid_tt("PI43VGRHTX6",fq_data.sid_tt)
|
|
|
+ if(book_info==null){
|
|
|
+ console.log("番茄付费 fail!")
|
|
|
+ content.番茄付费.name = fq_data.name
|
|
|
+ content.番茄付费.sid_tt = fq_data.sid_tt
|
|
|
+ content.番茄付费.isFail = true
|
|
|
+ }else{
|
|
|
+ content.番茄付费.book_id = book_info["book_id"]
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ content.番茄付费.book_id = book_info["book_id"]
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //3.阅文测试
|
|
|
+ list = await redis_help.getKeyValue("all_yw_key")
|
|
|
+ list = JSON.parse(list)
|
|
|
+ let yw_data = list[0]
|
|
|
+ const old_time = yw_data.create_time;
|
|
|
+ const current_time = moment();
|
|
|
+ const past_time = moment(old_time);
|
|
|
+ // 计算时间差(小时)
|
|
|
+ const diff_hours = current_time.diff(past_time, 'hours');
|
|
|
+ // 判断是否小于7小时
|
|
|
+ const isLessThan7Hours = diff_hours < 7;
|
|
|
+
|
|
|
+ if(isLessThan7Hours){
|
|
|
+
|
|
|
+ }else{
|
|
|
+ console.log("阅文 fail!")
|
|
|
+ //通知小小帅群消息
|
|
|
+ content.阅文.name = yw_data.name
|
|
|
+ content.阅文.open_sessid = yw_data.open_sessid
|
|
|
+ content.阅文.isFail = true
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log(content)
|
|
|
+ await notifyMsg(content)
|
|
|
+}
|
|
|
+
|
|
|
+CMD.init = async function(){
|
|
|
+ redis_help.connect(async (results)=>{
|
|
|
+ if(results){
|
|
|
+ // await processTask();
|
|
|
+ const job = schedule.scheduleJob('0 * * * *', async function() {
|
|
|
+ await processTask();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+CMD.init()
|