rambo 8 mesiacov pred
rodič
commit
5e2e712d0e

+ 63 - 8
python/mcu/DeviceControl.py

@@ -1012,6 +1012,21 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
             else:
                 return True
 
+    def check_before_action(self):
+        if self.state != 2:
+            print("check_before_action 设备正在运行中~")
+            self.sendSocketMessage(
+                code=1, msg="设备正在运行中", device_status=1
+            )
+            return False
+
+        if self.mcu_move_state != 2:
+            if settings.IS_LIN_SHI_TEST:
+                return True
+            # self.show_info("mcu 非停止状态")
+            self.sendSocketMessage(code=1, msg="mcu 非停止状态", device_status=1)
+        return True
+
     def controlDevice(self, device_name, value):
         '''控制设备移动等'''
         if not self.is_running:
@@ -1081,15 +1096,55 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
             # case "photograph":
             #     self.photograph(goods_art_no=None)
 
-    def run_mcu_config(self,config_list,goods_art_no):
+    async def run_mcu_config(self,config_list,goods_art_no):
         if config_list:
-            config_data = config_list[-1]
-            program_item = ProgramItem(
-                websocket_manager=self.websocket_manager,
-                action_data=config_data, mcu=self, goods_art_no=goods_art_no
-            )
-
-            program_item.run_only_mcu()
+            total_len = len(config_list)
+            for index, action in enumerate(config_list):
+                await asyncio.sleep(0.1)
+                # # config_data = config_list[-1]
+                program_item = ProgramItem(
+                    websocket_manager=self.websocket_manager,
+                    action_data=action,
+                    mcu=self,
+                    goods_art_no=goods_art_no,
+                )
+                # if self.action_state != 1:
+                #     # 异常终止
+                #     print("action异常终止")
+                #     break
+                if not program_item.run(total_len):
+                    self.sendSocketMessage(
+                        code=1,
+                        msg="{} 执行失败~".format(program_item.action_name),
+                        device_status=0,
+                    )
+                    self.to_deal_device(device_name="buzzer", times=3)
+                    break
+                else:
+                    # self.show_info("{}执行完成~".format(action.action_name))
+                    self.sendSocketMessage(
+                        code=0,
+                        msg="{} 执行完成~".format(program_item.action_name),
+                        device_status=2,
+                    )
+
+                # 在第三张图时检查是否有对应图片生成
+                if index == 3:
+                    # if not self.image_process_data.check_photo_is_get():
+                    # self.lineEdit.setText("")
+                    self.sendSocketMessage(
+                            code=1,
+                            msg="未获取到图片数据",
+                            device_status=0,
+                        )
+                    self.action_state = 2
+                    return
+                if index == total_len - 1:
+                    #  最后一个初始化处理
+                    pass
+                    # if action.mode_type != "其他配置":
+                    #     self.lineEdit.setText("")
+                self.action_state = 2
 
 
 async def checkMcuConnection(device_ctrl: DeviceControl):

+ 37 - 31
python/mcu/ProgramItem.py

@@ -4,6 +4,8 @@ import os
 from .BaseClass import BaseClass
 import settings
 import time
+from .capture.module_digicam import DigiCam
+from .capture.module_watch_dog import FileEventHandler
 
 class ProgramItem(BaseClass):
     # program_sign = Signal(dict)
@@ -14,6 +16,10 @@ class ProgramItem(BaseClass):
         # 1 表示等待中,2表示没有等待
         self.wait_state = 2
         self.data = action_data
+        self.capture_one = DigiCam()
+        captrure_folder_path = self.capture_one.getCaptureFolderPath()
+        self.watch_dog = FileEventHandler()
+        self.watch_dog.start_observer(captrure_folder_path)
         print("21 =========ProgramItem=======action_data=====")
         print(action_data)
         self.action_id = self.get_value(action_data, "id")
@@ -229,15 +235,15 @@ class ProgramItem(BaseClass):
                 )
                 time.sleep(0.1)
 
-            if self.mcu.action_state != 1:
-                # 外部终止,停止运行
-                print("外部终止,停止运行")
-                return
+            # if self.mcu.action_state != 1:
+            #     # 外部终止,停止运行
+            #     print("外部终止,停止运行")
+            #     return
 
-            if self.mode_type != "其他配置":
+            # if self.mode_type != "其他配置":
                 # MCU运动是否有停止检查,设定超时时间
-                if self.check_mcu_move_is_stop() is False:
-                    return
+                # if self.check_mcu_move_is_stop() is False:
+                #     return
 
             # print("{} 检查停止时间1:{}".format(self.action_name, time.time() - start_time))
             if self.is_led:
@@ -246,28 +252,28 @@ class ProgramItem(BaseClass):
                 self.mcu.to_deal_device(device_name="laser_position", value=0)
 
             if self.shoe_overturn:
-                if self.mcu.action_state != 1:
-                    return
+                # if self.mcu.action_state != 1:
+                #     return
                 self.mcu.to_deal_device(device_name="overturn_steering")
                 # time.sleep(0.1)
             if self.camera_height is not None:
-                if self.mcu.action_state != 1:
-                    return
+                # if self.mcu.action_state != 1:
+                #     return
                 self.mcu.to_device_move(
                     device_name="camera_high_motor", value=self.camera_height
                 )
                 # time.sleep(0.1)
             if self.camera_angle is not None:
-                if self.mcu.action_state != 1:
-                    return
+                # if self.mcu.action_state != 1:
+                #     return
                 self.mcu.to_device_move(
                     device_name="camera_steering", value=self.camera_angle
                 )
                 # time.sleep(0.1)
 
             if self.turntable_position is not None:
-                if self.mcu.action_state != 1:
-                    return
+                # if self.mcu.action_state != 1:
+                #     return
                 self.mcu.to_device_move(
                     device_name="turntable_position_motor",
                     value=self.turntable_position,
@@ -275,21 +281,21 @@ class ProgramItem(BaseClass):
                 # time.sleep(0.1)
 
             if self.turntable_angle is not None:
-                if self.mcu.action_state != 1:
-                    return
+                # if self.mcu.action_state != 1:
+                #     return
                 self.mcu.to_device_move(
                     device_name="turntable_steering", value=self.turntable_angle
                 )
                 # time.sleep(0.1)
 
             # MCU运动是否有停止检查,设定超时时间
-            if self.mcu.action_state != 1:
-                return
+            # if self.mcu.action_state != 1:
+            #     return
             if self.mode_type != "其他配置":
                 time.sleep(1.2)
-                if self.check_mcu_move_is_stop(re_check=True) is False:
-                    print("MCU检测运动未停止,自动退出,   提前退出")
-                    return
+                # if self.check_mcu_move_is_stop(re_check=True) is False:
+                #     print("MCU检测运动未停止,自动退出,   提前退出")
+                #     return
                 # print("{} 检查停止时间2:{}".format(self.action_name, time.time() - start_time))
 
         if self.delay_time:
@@ -306,8 +312,8 @@ class ProgramItem(BaseClass):
         #             except:
         #                 pass
 
-        if self.mcu.action_state != 1:
-            return
+        # if self.mcu.action_state != 1:
+        #     return
         # print("{} 检查停止时间4:{}".format(self.action_name, time.time() - start_time))
         # if self.is_wait:
         #     self.windows.playsound.tips_type = "wait"
@@ -318,9 +324,9 @@ class ProgramItem(BaseClass):
         #     self.windows.event.wait()
         #     self.windows.event.clear()
         #     self.wait_state = 2
-        #     if self.mcu.action_state != 1:
-        #         print("==={},中途退出".format(self.action_name))
-        #         return
+        # if self.mcu.action_state != 1:
+        #     print("==={},中途退出".format(self.action_name))
+        #     return
         #     self.next_step.hide()
 
         # print("self.is_photograph", self.is_photograph)
@@ -331,10 +337,10 @@ class ProgramItem(BaseClass):
             # 用于临时拍照计数
             # self.windows.add_goods_images_count(self.goods_art_no)
 
-            # if self.af_times > 0:
-            #     self.windows.capture_one.photograph(is_af=True)
-            # else:
-            #     self.windows.capture_one.photograph(is_af=False)
+            if self.af_times > 0:
+                self.capture_one.photograph(is_af=True)
+            else:
+                self.capture_one.photograph(is_af=False)
 
             self.last_photograph_time = time.time()  # 记录最近一次拍照时间
 

+ 0 - 0
python/mcu/capture/__init__.py


+ 185 - 0
python/mcu/capture/capture_basic_mode.py

@@ -0,0 +1,185 @@
+import time
+import settings
+from sys import platform as sys_platform
+from utils.utils_func import httpGetHandler
+from PIL import Image
+from io import BytesIO
+import requests
+
+if settings.IS_TEST:
+    import piexif
+    from PIL import Image
+    import threading
+
+
+class CaptureBasic():
+    # program_sign = Signal(dict)0
+    base_host = "http://localhost:5513"
+    _get_image_index = 0
+    _get_folder_index = 0
+    is_first_init = 0
+
+    def __init__(self):
+        # self.window = window
+        # 状态 1 进行中 2 已停止
+        self.state = 2
+        # 总拍照数量
+        self.total_num = 0
+        # 是否获取照片
+        self.is_get_photo = False
+        # self.keyboard = Controller()
+        self.hwnd = None
+    def getPreviewImage(self)->Image:
+        '''获取预览图'''
+        yzmdata = requests.get(self.base_host + "/preview.jpg")
+        tempIm = BytesIO(yzmdata.content)
+        im = Image.open(tempIm)
+        return im
+
+    def getCaptureFolderPath(self) -> Image:
+        """获取预览图"""
+        response = httpGetHandler(
+            url=self.base_host,
+            params={"slc": "get", "param1": "session.folder"},
+            headers={},
+        )
+        return response.text
+
+    def run_capture_action(self,command):
+        '''执行capture动作'''
+        response = httpGetHandler(url=self.base_host, params={"CMD":command},headers={})
+        return response
+    # def photograph(self):
+    #     """
+    #     Args:
+    #         data:
+    #         info_show: 信息输出
+    #         image_deal_mode:0 表示左脚,1表示右脚
+    #     Returns:
+    #     """
+    #     print("142----------------------------photograph")
+    #     # 执行拍照
+    #     if not self.hwnd:
+    #         return False, {"flag": "{} 未打开".format(settings.CaptureSoftwareName)}
+    #     if self.state == 1:
+    #         print("当前有未完成的任务")
+    #         return False, {"flag": "当前有未完成的任务"}
+    #     print("开始拍照")
+    #     self.state = 1
+    #     if not self.set_foreground_window():
+    #         return False, {"flag": "no {}".format(settings.CaptureSoftwareName)}
+    #     time.sleep(0.1)
+    #     # 自动对焦
+    #     self.auto_focus()
+    #     # self.send_win32_key(self.hwnd, key_1=win32con.VK_CONTROL, key_2=win32con.VK_F2)
+
+    #     if settings.IS_TEST:
+    #         # print("56-----测试拍照")
+    #         threading.Thread(target=self.test_add_photo, args=()).start()
+    #     # self.program_sign.emit({"type": "add_to_photo_todo_list",
+    #     #                         "data": data})
+    #     time.sleep(float(settings.PhotographSeconds))
+
+    # def test_add_photo(self):
+    #     def copy_file(srcfile, dstpath, dstfile):  # 复制函数
+    #         if not os.path.isfile(srcfile):
+    #             # print("%s not exist!" % (srcfile))
+    #             return
+    #         else:
+    #             if int(os.path.getsize(srcfile) / 1024) < 10:
+    #                 return
+    #             # fpath, fname = os.path.split(srcfile)  # 分离文件名和路径
+    #             if not os.path.exists(dstpath):
+    #                 os.makedirs(dstpath)  # 创建路径
+    #             shutil.copy(srcfile, dstfile)  # 复制文件
+
+    #     print("模拟拍照  test_add_photo")
+    #     time.sleep(0.9)
+    #     s = time.time()
+    #     source_path = r"{}\PhotoImageDir\test_source".format(os.getcwd())
+    #     check_path(source_path)
+
+    #     # 整理所有测试源照片
+    #     images_path_list = []
+    #     folder_list = get_folder(source_path)
+    #     for folder_dict in folder_list:
+    #         folder_path = folder_dict["folder_path"]
+    #         _pics = [x["file_path"] for x in get_images(folder_path)]
+    #         if _pics:
+    #             images_path_list.append(_pics)
+
+    #     if len(images_path_list) <= CaptureBasic._get_folder_index:
+    #         CaptureBasic._get_folder_index = 0
+    #         CaptureBasic._get_image_index = 0
+    #     srcfile = images_path_list[CaptureBasic._get_folder_index][CaptureBasic._get_image_index]
+
+    #     # 新文件夹
+    #     CaptureBasic._get_image_index += 1
+    #     if len(images_path_list[CaptureBasic._get_folder_index]) <= CaptureBasic._get_image_index:
+    #         CaptureBasic._get_folder_index += 1
+    #         CaptureBasic._get_image_index = 0
+
+    #     # print("pic:", srcfile)
+    #     e = os.path.splitext(os.path.split(srcfile)[1])[1]
+
+    #     # 修改图片时间
+    #     if e != ".CR2":
+    #         _time = time.strftime("%Y:%m:%d %H:%M:%S", time.localtime(time.time()))
+    #         exif_ifd = {piexif.ExifIFD.DateTimeOriginal: _time}
+    #         exif_dict = {"Exif": exif_ifd}
+    #         exif_bytes = piexif.dump(exif_dict)
+    #         im = Image.open(srcfile)
+    #         im.save(srcfile, exif=exif_bytes)
+
+    #     dst_path = settings.PhotoOutputDir
+    #     # dst_path = "{}/data".format(os.getcwd())
+    #     e = os.path.splitext(srcfile)[-1]
+    #     new_name = "~{}{}".format(int(time.time() * 10), e)
+    #     dst_file = "{}/{}".format(dst_path, new_name)
+    #     print("测试数据   dst_file", dst_file)
+    #     copy_file(srcfile, dst_path, dst_file)
+    #     # print("修改图片耗时:{}".format(time.time() - s))
+
+    def auto_focus(self):
+        # 执行拍照
+        time.sleep(0.2)
+        self.run_capture_action("LiveView_Focus")
+
+    def last_images(self):
+        if not self.hwnd:
+            return
+        # win32gui.SetForegroundWindow(self.hwnd)
+        # self.keyboard.press(Key.ctrl)
+        # self.keyboard.press(Key.left)
+        # self.keyboard.release(Key.left)
+        # self.keyboard.release(Key.ctrl)
+
+    def next_images(self):
+        # 执行拍照
+        if not self.hwnd:
+            return
+        # win32gui.SetForegroundWindow(self.hwnd)
+        # self.keyboard.press(Key.ctrl)
+        # self.keyboard.press(Key.right)
+        # self.keyboard.release(Key.right)
+        # self.keyboard.release(Key.ctrl)
+
+    def test_1(self):
+        if not self.hwnd:
+            return
+        # 执行照片全选与导出
+        # win32gui.SetForegroundWindow(self.hwnd)
+        # self.keyboard.press(Key.ctrl)
+        # self.keyboard.press("a")
+        # self.keyboard.release("a")
+        # self.keyboard.release(Key.ctrl)
+        # time.sleep(1)
+        # # 照片导出
+        # self.keyboard.press(Key.ctrl)
+        # self.keyboard.press("d")
+        # self.keyboard.release("d")
+        # self.keyboard.release(Key.ctrl)
+if __name__ == "__main__":
+    cap = CaptureBasic()
+    cap.auto_focus()
+    print("cccc")

+ 50 - 0
python/mcu/capture/module_digicam.py

@@ -0,0 +1,50 @@
+"""
+使用digiCamControl进行处理
+1、使用cmd命令检查相机是否有链接电脑
+2、句柄检查digiCamControl软件是否有打开
+3、注意没有单独对焦的命令,不对焦拍摄的话取另外一个控制命令
+4、确保输出的内容在指定文件夹
+
+"""
+import os.path
+import subprocess
+import time
+import settings
+# import win32api, win32gui, win32con
+# import win32process
+# from pynput.keyboard import Key, Controller
+from .capture_basic_mode import CaptureBasic
+import threading
+from .module_watch_dog import FileEventHandler
+
+# from win32gui import EnumWindows, GetWindowText
+
+
+class DigiCam(CaptureBasic):
+
+    def __init__(self):
+        super().__init__()
+        # self.get_capture_one_hwnd()
+        # self.install_path = settings.DigicamInstallPath
+        self.is_first_init = 0
+        # if self.install_path:
+        #     threading.Thread(target=self.check_and_open_software, args=()).start()
+    # 拍照
+    def photograph(self, is_af=True):
+        """
+        Args:
+            data:
+            info_show: 信息输出
+            image_deal_mode:0 表示左脚,1表示右脚
+        Returns:
+        """
+        print("55----------------------DigiCam------photograph")
+        # 执行拍照
+        time.sleep(0.1)
+        # 自动对焦
+        if is_af:
+            self.auto_focus()
+            self.run_capture_action("Capture")
+        else:
+            self.run_capture_action("Capture")
+        time.sleep(float(settings.PhotographSeconds))

+ 161 - 0
python/mcu/capture/module_watch_dog.py

@@ -0,0 +1,161 @@
+from watchdog.events import FileSystemEventHandler
+from watchdog.observers import Observer
+import settings
+import time
+import os
+from utils.utils_func import get_folder, check_path
+import datetime
+from utils.SingletonType import SingletonType
+
+
+class FileEventHandler(FileSystemEventHandler, metaclass=SingletonType):
+    instance = None
+    init_flag = None
+
+    def __init__(self):
+        # if self.init_flag:
+        #     return
+        # else:
+        #     self.init_flag = True
+        super().__init__()
+        # self.window = window
+        FileSystemEventHandler.__init__(self)
+        self.receive_photo_data = []
+        # 以下为测试用途
+        self._get_image_index = -1
+        self.observer = None
+        self.last_create_time = datetime.datetime.now()
+
+    def start_observer(self,path):
+        print("图片保存目录:", path)
+        if path == None or path == "":
+            return
+        self.observer = Observer()
+
+        watch_path = self.check_and_get_real_dir(path)
+        if watch_path:
+            self.observer.schedule(self, watch_path, recursive=True)  # recursive 遍历目录
+            self.observer.start()
+            print("开启开门狗目录监听")
+        else:
+            print("路径错误不存在")
+
+    def check_and_get_real_dir(self, watch_path):
+        """
+        逻辑:
+        1、检查当前路径如包含Originals 则定位到对应Originals的父级目录
+        2、如没有Originals,则认定为一个普通目录(且子文件夹没有Originals),否则定位到父级目录
+        3、根据父级目录,获取当天应该创建的拍摄子目录,如没有则自动创建并定位
+        """
+        if not os.path.exists(watch_path):
+            return None
+
+        if "Originals" in watch_path:
+            root_path = watch_path.split("Originals", 1)[0]
+        else:
+            if "Originals" in [x["folder_name"] for x in get_folder(watch_path)]:
+                root_path = watch_path
+            else:
+                return watch_path
+
+        # 检查并创建日期
+        now = datetime.datetime.now()
+        year = now.year
+        month = now.month
+        day = now.day
+        path = r"{root_path}\Originals\{year}\{month}\{day}".format(root_path=root_path, year=year, month=month, day=day)
+        check_path(path)
+        print("watch_path:",path)
+        return path
+
+    def on_moved(self, event):
+        # if event.is_directory:
+        #     print("directory moved from {0} to {1}".format(event.src_path, event.dest_path))
+        # else:
+        #     print("file moved from {0} to {1}".format(event.src_path, event.dest_path))
+        #     if os.path.split(event.dest_path)[0] == settings.PhotoOutputDir:
+        #         print("1111111")
+        pass
+
+    def on_created(self, event):
+        if not event.is_directory:
+            file_path = event.src_path
+            print("file created:{0}".format(file_path))
+            self.receive_photo_data.append(file_path)
+            # self.get_photo_info(file_path)
+            # self.window.data_sign.emit({"_type": "photo_number_music_play"})
+
+            try:
+                take_time = time.time()
+                self.send_log("获取文件file_path:{}".format(file_path))
+                create_time = datetime.datetime.fromtimestamp(os.path.getctime(file_path))
+                # print("获取文件create_time:{}".format(create_time))
+                self.get_photo_info(raw_path=file_path, create_time=create_time, take_time=take_time)
+                self.send_log("获取文件create_time:{}".format(create_time))
+            except BaseException as e:
+                print("获取文件create_time失败", e)
+                self.send_log("获取文件处理失败{}".format(e))
+
+    def send_log(self, text):
+        print(text)
+
+    def get_photo_info(self, raw_path, create_time, take_time):
+        # 看门狗监听到系统有图片生成后,自动进行图片对应
+        f_path = os.path.split(raw_path)[0]
+
+        print("raw_path:", raw_path)
+        # take_time = time.time()  # 创建图片时间,默认为拍照时间
+        time.sleep(0.2)  # 等待原始图片文件写入
+
+        # 查找真实的图片路径名称
+        f = False
+        if f:
+            if not os.path.exists(raw_path):
+                print("不存在", raw_path)
+                for file in os.listdir(f_path):
+                    file_path = os.path.join(f_path, file)
+                    # 判断是否为文件
+                    if os.path.isfile(file_path):
+                        # 获取文件创建时间
+                        create_time = datetime.datetime.fromtimestamp(os.path.getctime(file_path))
+                        # 更新最早时间
+                        if create_time > self.last_create_time:
+                            self.last_create_time = create_time
+                            raw_path = file_path
+
+        # last_file_size = os.path.getsize(raw_path)
+        # k = 30
+        # # 检查文件是否有写入完成
+        # flag = False
+        # while k:
+        #     k -= 1
+        #     if k == 0:
+        #         break
+        #     _file_size = os.path.getsize(raw_path)
+        #     if last_file_size == _file_size:
+        #         flag = True
+        #         break
+        #     else:
+        #         last_file_size = _file_size
+        #     time.sleep(0.1)
+        # if not flag:
+        #     return
+        # 调用父程序,执行报错图片命令
+        # self.window.show_img_on_photo_todo_list_sign(raw_path=raw_path, take_time=take_time)
+
+    def stop(self):
+        # 结束监听
+        if self.observer is not None:
+            self.observer.stop()
+            print("结束监听")
+            del self.observer
+
+    def __new__(cls, *args, **kwargs):
+        """如果当前没有实例时,调用父类__new__方法,生成示例,有则返回保存的内存地址。"""
+        if not cls.instance:
+            cls.instance = super().__new__(cls)
+        return cls.instance
+
+    def __del__(self):
+        self.stop()
+        print("结束监听,进程关闭")

+ 1 - 1
python/settings.py

@@ -17,7 +17,7 @@ MACHINE_LEVEL = "二档"
 IS_TEST = False
 IS_MCU = True
 IS_LIN_SHI_TEST = False
-
+PhotographSeconds = float(0.3)  # 拍照停留时间
 def moveSpeed(level: str = None):
     config = {
         "一档": {

+ 80 - 2
python/utils/utils_func.py

@@ -1,8 +1,8 @@
-
 import os
 from hashlib import sha256, md5
 from datetime import datetime
 import requests
+from natsort import ns, natsorted
 
 def get_md5(file_path):
     data_md5 = None
@@ -58,4 +58,82 @@ def check_path(_path):
         # 创建多级目录
         os.makedirs(_path, exist_ok=True)
         # os.mkdir(_path)
-    return True
+    return True
+
+
+# from module.view_control.MineQWidget import MineQWidget
+def list_dir(path):
+    listdir = os.listdir(path)
+    return natsorted(listdir, alg=ns.PATH)
+
+
+def get_folder(path):
+    folder_list = []
+    for _file in list_dir(path):
+        file_path = "{}/{}".format(path, _file)
+        if os.path.isdir(file_path):
+            folder_list.append(
+                {
+                    "folder_path": file_path,
+                    "folder_name": _file,
+                    "root_path": path,
+                    "label": "待处理",  # 是否需要继续处理
+                }
+            )
+    return folder_list
+
+
+def get_images(path):
+    _Type = [".png", ".PNG", ".jpg", ".JPG", ".gif", ".GIF", ".jpge", ".JPGE", ".CR2"]
+    image_list = []  # 过滤非图片数据
+    for _file in list_dir(path):
+        file_name, e = os.path.splitext(_file)
+        file_path = "{}/{}".format(path, _file)
+        if os.path.isdir(file_path):
+            continue
+        if e in _Type and "mask" not in file_name:
+            image_list.append(
+                {
+                    "file_path": file_path,
+                    "file_name": file_name,
+                    "file": _file,
+                    "root_path": path,
+                    "e": e,
+                }
+            )
+    return image_list
+
+
+def httpGetHandler(url, params=None, headers=None):
+    """
+        发送GET请求
+        :param endpoint: 请求的端点
+        :param params: 查询参数
+        :param headers: 请求头
+        :return: 响应对象
+        """
+    try:
+        response = requests.get(url, params=params, headers=headers)
+        response.raise_for_status()  # 如果响应状态码不是200,抛出异常
+        return response
+    except requests.exceptions.RequestException as e:
+        print(f"GET请求失败: {e}")
+        return None
+
+
+def httpPosthandler(url, data=None, json=None, headers=None):
+    """
+        发送POST请求
+        :param endpoint: 请求的端点
+        :param data: 表单数据
+        :param json: JSON数据
+        :param headers: 请求头
+        :return: 响应对象
+        """
+    try:
+        response = requests.post(url, data=data, json=json, headers=headers)
+        response.raise_for_status()  # 如果响应状态码不是200,抛出异常
+        return response
+    except requests.exceptions.RequestException as e:
+        print(f"POST请求失败: {e}")
+        return None