{"contents":"# -*- coding: utf-8 -*-#\n# -------------------------------------------------------------------------------\n# Name: contacts.py\n# Description: 联系人相关接口\n# -------------------------------------------------------------------------------\nfrom typing import List\n\nfrom fastapi import APIRouter, Body\n\nfrom wxdump_linux.db import DBHandler\nfrom ..response import ReJson\nfrom ..decorators import error9999\nfrom ..config import gc\n\ncontacts_router = APIRouter()\n\n\n@contacts_router.api_route('/is_init', methods=[\"GET\", 'POST'])\n@error9999\ndef is_init():\n \"\"\"\n 是否初始化\n :return:\n \"\"\"\n local_wxids = gc.get_local_wxids()\n if len(local_wxids) \u003e 1:\n return ReJson(0, True)\n return ReJson(0, False)\n\n\n@contacts_router.api_route('/mywxid', methods=[\"GET\", 'POST'])\n@error9999\ndef mywxid():\n \"\"\"\n 获取我的微信id\n :return:\n \"\"\"\n my_wxid = gc.get_conf(gc.at, \"last\")\n if not my_wxid: return ReJson(1001, body=\"my_wxid is required\")\n return ReJson(0, {\"my_wxid\": my_wxid})\n\n\n@contacts_router.api_route('/user_session_list', methods=[\"GET\", 'POST'])\n@error9999\ndef user_session_list():\n \"\"\"\n 获取联系人列表\n :return:\n \"\"\"\n my_wxid = gc.get_conf(gc.at, \"last\")\n if not my_wxid: return ReJson(1001, body=\"my_wxid is required\")\n db_config = gc.get_conf(my_wxid, \"db_config\")\n db = DBHandler(db_config, my_wxid=my_wxid)\n ret = db.get_session_list()\n return ReJson(0, list(ret.values()))\n\n\n@contacts_router.api_route('/user_labels_dict', methods=[\"GET\", 'POST'])\n@error9999\ndef user_labels_dict():\n \"\"\"\n 获取标签字典\n :return:\n \"\"\"\n my_wxid = gc.get_conf(gc.at, \"last\")\n if not my_wxid: return ReJson(1001, body=\"my_wxid is required\")\n db_config = gc.get_conf(my_wxid, \"db_config\")\n db = DBHandler(db_config, my_wxid=my_wxid)\n user_labels_dict = db.get_labels()\n return ReJson(0, user_labels_dict)\n\n\n@contacts_router.post('/user_list')\n@error9999\ndef user_list(word: str = Body(\"\", embed=True), wxids: List[str] = Body(None), labels: List[str] = Body(None)):\n \"\"\"\n 获取联系人列表,可用于搜索\n :return:\n \"\"\"\n if isinstance(wxids, str) and wxids == '' or wxids is None: wxids = []\n if isinstance(labels, str) and labels == '' or labels is None: labels = []\n\n my_wxid = gc.get_conf(gc.at, \"last\")\n if not my_wxid: return ReJson(1001, body=\"my_wxid is required\")\n db_config = gc.get_conf(my_wxid, \"db_config\")\n db = DBHandler(db_config, my_wxid=my_wxid)\n users = db.get_user(word=word, wxids=wxids, labels=labels)\n return ReJson(0, users)\n","is_binary":false,"path":"wxdump_linux/api/routes/contacts.py","ref":""}