鲁浩 9 kuukautta sitten
vanhempi
säilyke
6da17c0df7

+ 11 - 2
server/flaskProject/app.py

@@ -1,6 +1,7 @@
 import os
 from flask import Flask, request
 from MoneyRecord import MoneyRecord
+from task import TikTask
 from user import User
 import logging
 from logging.handlers import TimedRotatingFileHandler
@@ -28,6 +29,12 @@ def money_action(action):
     return r
 
 
+@app.route('/task/<action>', methods=['POST'])
+def tik_task_action(action):
+    data = request.get_json()
+    r = TikTask(action=action, data=data, logger=logger).tik_task_router()
+    return r
+
 class CustomLogger:
     def __init__(self, log_file):
         self.log_file = log_file
@@ -64,6 +71,8 @@ day = current_date.day
 # 将年月日格式化为字符串
 formatted_date = current_date.strftime("%Y-%m-%d")
 logger = CustomLogger(f'{os.path.dirname(__file__)}/logs/{formatted_date}.log')
+
+
 # logger = CustomLogger(f'/Users/jasonphd/Desktop/gogs/JasonPhdWork/server/flaskProject/logs{formatted_date}.log')
 # logger = CustomLogger(f'/root/api_server/JasonPhdWork/app/logs/{formatted_date}.log')
 
@@ -72,9 +81,9 @@ logger = CustomLogger(f'{os.path.dirname(__file__)}/logs/{formatted_date}.log')
 @app.before_request
 def log_request_info():
     data = request.get_json()
-    data["intime"] = int (time.time())
+    data["intime"] = int(time.time())
     logger.log(f"url:{request.url} params:{data} method:{request.method} ip:{request.remote_addr}")
 
 
 if __name__ == '__main__':
-    app.run(host='0.0.0.0',port=5005)
+    app.run(host='0.0.0.0', port=5005)

+ 1 - 0
server/flaskProject/needsign.json

@@ -0,0 +1 @@
+{"needsign_morning": true, "needsign_night": true, "intime": 1711702879}

+ 67 - 0
server/flaskProject/task.py

@@ -0,0 +1,67 @@
+from data import MySQLTool
+import hashlib
+import uuid
+import TokenUtils
+from returnTemp import get_template, get_error_message
+import json
+from datetime import datetime
+
+class TikTask:
+    def __init__(self, action, data, logger):
+        self.action = action
+        self.data = data
+        self.logger = logger
+
+    def tik_task_router(self):
+        if self.action == "create":
+            return self.create()
+        elif self.action == "status":
+            return self.status()
+        elif self.action == "signcheck":
+            return self.signcheck()
+        elif self.action == "signset":
+            return self.signset()    
+        else:
+            return self.test()
+
+    def create(self):
+        print("---create---")
+        return create(self.data)
+
+    def status(self):
+        print("---status----")
+        return status(self.data)
+
+    def signcheck(self):
+        print("---signcheck----")
+        return signcheck()
+    
+    def signset(self):
+        print("---signset----")
+        return signset(self.data)
+    
+    def test(self):
+        return self.data
+
+def signcheck():
+    with open('needsign.json') as json_file:
+        r = json.load(json_file)
+    return r
+
+def signset(data):
+    with open('needsign.json', 'w') as json_file:
+         json.dump(data, json_file)
+         
+    with open('needsign.json') as json_file:
+        r = json.load(json_file)
+        now = datetime.now()
+        formatted_time = now.strftime("%Y-%m-%d %H:%M:%S")
+        r["changetime"] = formatted_time
+    return r
+
+def create(data):
+    return data
+
+
+def status(data):
+    return data

+ 0 - 3
server/flaskProject/user.py

@@ -152,11 +152,8 @@ mysql_tool = MySQLTool(host='localhost', user='root', password='wyt615115@', dat
 def login(data):
     logintype = data["login_type"]
     if logintype == "1":
-        print("111")
         return accountLogin(data)
     elif logintype == "2":
-        print("222")
         return wechatLogin(data)
-
     else:
         print("3333")