diff --git a/XiaoZhi/xiaozhi-esp32-server/main/xiaozhi-server/plugins_func/functions/apply_car.py b/XiaoZhi/xiaozhi-esp32-server/main/xiaozhi-server/plugins_func/functions/apply_car.py new file mode 100644 index 00000000..35c43f7a --- /dev/null +++ b/XiaoZhi/xiaozhi-esp32-server/main/xiaozhi-server/plugins_func/functions/apply_car.py @@ -0,0 +1,129 @@ +import requests +from bs4 import BeautifulSoup +from config.logger import setup_logging +from plugins_func.register import register_function, ToolType, ActionResponse, Action +import json +import base64 +import urllib.parse + +TAG = __name__ +logger = setup_logging() + +APPLY_CAR_FUNCTION_DESC = { + "type": "function", + "function": { + "name": "apply_car", + "description": ( + "申请用车,用户需要提供车辆名称、出发地、目的地、出发时间和用车事由" + # "需要根据用户提供的车辆名称,获取对应的车牌号和车id" + # "如果用户提供的车辆名称为:奥迪,对应的车牌号为:吉JQ1919,对应的车id为:1" + # "如果用户提供的车辆名称为:奔驰,对应的车牌号为:吉ABN778,对应的车id为:2" + # "如果用户没有具体的车辆名称,默认使用车辆名称为:奥迪,对应的车牌号为:吉JQ1919,对应的车id为:1" + "如果用户没有提供具体的车辆名称,默认使用车辆名称为:奥迪" + "如果用户没有提供具体的用车事由,需要进行分析得出用车事由" + ), + "parameters": { + "type": "object", + "properties": { + "car_name": { + "type": "string", + "description": "车辆名称" + }, + "car_no": { + "type": "string", + "description": "车牌号" + }, + "car_id": { + "type": "string", + "description": "车id" + }, + "departure_place": { + "type": "string", + "description": "出发地" + }, + "destination_place": { + "type": "string", + "description": "目的地" + }, + "use_car_reason": { + "type": "string", + "description": "用车事由" + }, + "lang": { + "type": "string", + "description": "返回用户使用的语言code,例如zh_CN/zh_HK/en_US/ja_JP等,默认zh_CN" + } + }, + "required": ["lang"] + } + } +} + +HEADERS = { + 'User-Agent': ( + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 ' + '(KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36' + ) +} + +@register_function('apply_car', APPLY_CAR_FUNCTION_DESC, ToolType.SYSTEM_CTL) +def apply_car(conn, car_name: str = None, car_no: str = None, car_id: str = None, departure_place: str = None, destination_place: str = None, use_car_reason: str = None, lang: str = "zh_CN"): + # 设置默认车辆信息 + if car_name is None: + car_name = "奥迪" + if departure_place is None: + departure_place = "单位" + + # 根据车辆名称设置车牌号和车ID + car_mapping = { + "奥迪": {"car_no": "吉JQ1919", "car_id": "1"}, + "奔驰": {"car_no": "吉ABN778", "car_id": "2"} + } + + if car_name in car_mapping: + car_info = car_mapping[car_name] + car_no = car_info["car_no"] + car_id = car_info["car_id"] + + if use_car_reason is None: + use_car_reason = "外出" + + print("车辆名称:"+car_name) + print("车牌号:"+car_no) + print("车id:"+car_id) + print("出发地:"+departure_place) + print("目的地:"+destination_place) + print("用车事由:"+use_car_reason) + + + report = "车辆申请成功" + + try: + url = "https://www.edusoa.com/dsideal_yy/ypt/intellioa/carManage/carApply/saveCarApply" + + payload = f'org_id=900008135&person_id=546097&identity_id=5&car_id={car_id}&car_name={car_name}&car_no={car_no}&car_no_type=3&driving_type=1&user_person_id=546097&user_dept_id=900008155&begin_datetime=2025-04-17%2016%3A00&end_datetime=2025-04-17%2016%3A00&departure_place={departure_place}&departure_place_coordinate=125.388035%2C43.776103&destination_place={destination_place}&destination_place_coordinate=125.324812%2C43.911474&use_car_reason={use_car_reason}&rule_id=1&rule_type=20&next_level_id=1&next_person_id=546097&next_person_name=%E8%AE%B8%E5%A6%8D%E5%A6%8D' + headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:137.0) Gecko/20100101 Firefox/137.0', + 'Content-Type': 'application/x-www-form-urlencoded', + 'Cookie': 'HWWAFSESID=9e32376ecea1f188cd; HWWAFSESTIME=1744869321310; identity_id=5; person_id=546097; token=ae368e8a2633498a0217c67510668754' + } + + response = requests.request("POST", url, headers=headers, data=payload) + + print(response.text) + + response_data = json.loads(response.text) + + if response_data.get("code") == 4011: + print(response_data.get("code")) + report = "此时间范围该车已被申请,请更换车辆或时间" + report += ( + "(只回复此时间范围该车已被申请,请更换车辆或时间;其他信息禁止回复)" + ) + except: + report = "申请车辆服务异常,请稍后再试" + report += ( + f"(只回复申请车辆服务异常,请稍后再试,其他信息无需回复)" + ) + print(report) + return ActionResponse(Action.REQLLM, report, None) \ No newline at end of file diff --git a/XiaoZhi/xiaozhi-esp32-server/main/xiaozhi-server/plugins_func/functions/send_notice.py b/XiaoZhi/xiaozhi-esp32-server/main/xiaozhi-server/plugins_func/functions/send_notice.py new file mode 100644 index 00000000..a6afef6c --- /dev/null +++ b/XiaoZhi/xiaozhi-esp32-server/main/xiaozhi-server/plugins_func/functions/send_notice.py @@ -0,0 +1,83 @@ +import requests +from bs4 import BeautifulSoup +from config.logger import setup_logging +from plugins_func.register import register_function, ToolType, ActionResponse, Action +import json +import base64 +import urllib.parse + +TAG = __name__ +logger = setup_logging() + +SEND_NOTICE_FUNCTION_DESC = { + "type": "function", + "function": { + "name": "send_notice", + "description": ( + "用户发送通知,用户需要提供通知标题和通知内容" + "如果用户没有提供具体的通知标题,需要进行分析得出通知标题" + "注意时间的格式,例如:16:00,决不能是1600" + ), + "parameters": { + "type": "object", + "properties": { + "title": { + "type": "string", + "description": "通知标题" + }, + "content": { + "type": "string", + "description": "通知内容" + }, + "lang": { + "type": "string", + "description": "返回用户使用的语言code,例如zh_CN/zh_HK/en_US/ja_JP等,默认zh_CN" + } + }, + "required": ["lang"] + } + } +} + +HEADERS = { + 'User-Agent': ( + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 ' + '(KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36' + ) +} + +@register_function('send_notice', SEND_NOTICE_FUNCTION_DESC, ToolType.SYSTEM_CTL) +def send_notice(conn, title: str = None, content: str = None, lang: str = "zh_CN"): + print("通知标题:"+title) + print("通知内容:"+content) + + # 对中文内容进行BASE64编码 + title_base64 = base64.b64encode(title.encode('utf-8')).decode('utf-8') + content_base64 = base64.b64encode(content.encode('utf-8')).decode('utf-8') + + # 对BASE64结果进行URL编码 + title_urlencoded = urllib.parse.quote(title_base64) + content_urlencoded = urllib.parse.quote(content_base64) + + url = "https://www.edusoa.com/dsideal_yy/new_notice/kjAddNotice" + + payload = f'notice_content=通知¬ice_title=通知¬iceJson=%7B%22notice_title%22%3A%22{title_urlencoded}%22%2C%22notice_content%22%3A%22{content_urlencoded}%22%2C%22notice_level%22%3A%221%22%2C%22thumb_id%22%3A%22%22%2C%22notice_receipt%22%3A0%2C%22notice_public%22%3A0%2C%22sender_bureau_id%22%3A900008135%2C%22sender_person_id%22%3A%22546097%22%2C%22send_status%22%3A1%2C%22bureau_list%22%3A%5B900008135%5D%2C%22org_list%22%3A%5B%5D%2C%22person_list%22%3A%5B%5D%2C%22group_list%22%3A%5B%5D%2C%22attachments%22%3A%5B%5D%7D¬iceSourceJson=333' + headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:137.0) Gecko/20100101 Firefox/137.0', + 'Content-Type': 'application/x-www-form-urlencoded', + 'Cookie': 'HWWAFSESID=9e32376ecea1f188cd; HWWAFSESTIME=1744869321310; identity_id=5; person_id=546097; token=ae368e8a2633498a0217c67510668754' + } + + response = requests.request("POST", url, headers=headers, data=payload) + + print(response.text) + + report= f"您的通知已成功发送!" + + report += ( + f"(只回复您的通知已成功发送即可,其他信息无需回复)" + ) + + + + return ActionResponse(Action.REQLLM, report, None) \ No newline at end of file diff --git a/XiaoZhi/文档/演示文档.txt b/XiaoZhi/文档/演示文档.txt new file mode 100644 index 00000000..b99a6b1f --- /dev/null +++ b/XiaoZhi/文档/演示文档.txt @@ -0,0 +1,11 @@ +用户名:xuyanyan6 +密码:Xyy199191 + +https://www.edusoa.com +个人空间(新)-慧办公-日常办公 + +(1)通知管理-发布通知: +我要发送一个停电通知,内容为本周三上午8点至下午16点进行停电作业,请提前关闭电器设备电源。 + +(2)新公车管理-车辆申请-历史记录: +我要申请用车,明天从单位出发去净月潭玩。 \ No newline at end of file