diff --git a/__pycache__/WXBotService.cpython-312.pyc b/__pycache__/WXBotService.cpython-312.pyc new file mode 100644 index 0000000..2f710e7 Binary files /dev/null and b/__pycache__/WXBotService.cpython-312.pyc differ diff --git a/__pycache__/config.cpython-312.pyc b/__pycache__/config.cpython-312.pyc new file mode 100644 index 0000000..6db8c70 Binary files /dev/null and b/__pycache__/config.cpython-312.pyc differ diff --git a/__pycache__/crud.cpython-312.pyc b/__pycache__/crud.cpython-312.pyc new file mode 100644 index 0000000..b460eda Binary files /dev/null and b/__pycache__/crud.cpython-312.pyc differ diff --git a/__pycache__/database.cpython-312.pyc b/__pycache__/database.cpython-312.pyc new file mode 100644 index 0000000..7ea8681 Binary files /dev/null and b/__pycache__/database.cpython-312.pyc differ diff --git a/__pycache__/main.cpython-312.pyc b/__pycache__/main.cpython-312.pyc new file mode 100644 index 0000000..2274479 Binary files /dev/null and b/__pycache__/main.cpython-312.pyc differ diff --git a/__pycache__/models.cpython-312.pyc b/__pycache__/models.cpython-312.pyc new file mode 100644 index 0000000..9a8fb0e Binary files /dev/null and b/__pycache__/models.cpython-312.pyc differ diff --git a/__pycache__/planet.cpython-312.pyc b/__pycache__/planet.cpython-312.pyc new file mode 100644 index 0000000..971014e Binary files /dev/null and b/__pycache__/planet.cpython-312.pyc differ diff --git a/__pycache__/schemas.cpython-312.pyc b/__pycache__/schemas.cpython-312.pyc new file mode 100644 index 0000000..156f437 Binary files /dev/null and b/__pycache__/schemas.cpython-312.pyc differ diff --git a/crud.py b/crud.py index af462f3..fe3d8c1 100644 --- a/crud.py +++ b/crud.py @@ -21,7 +21,8 @@ def get_users(db: Session, skip: int = 0, limit: int = 100): # 创建用户 # user:schemas.UserCreate -def create_user(db: Session, user:schemas.UserCreate): + # **user +def create_user(db: Session, user:schemas.User): db_user = models.User( wxid=user.wxid, openId=user.openId, diff --git a/main.py b/main.py index ca7325e..005929e 100644 --- a/main.py +++ b/main.py @@ -47,7 +47,7 @@ async def root(): # 创建用户 @app.post("/users/") # schemas.UserCreate决定了swagger文档 -def create_user(user: schemas.UserCreate, db: Session = Depends(get_db)): +def create_user(user: schemas.User, db: Session = Depends(get_db)): db_user = crud.create_user(db, user) if db_user: raise HTTPException(status_code=400, @@ -71,6 +71,7 @@ def read_user(openId, db: Session = Depends(get_db)): return db_user +# 监听机器人http-get消息 @app.get("/wxbot") def helloget(q:dict): data = q @@ -78,11 +79,10 @@ def helloget(q:dict): t.start() return json.dumps({"Code": 0}) +# 监听机器人post日志消息 @app.post("/wxbot") # def hellopost(requestData:schemas.User): def hellopost(requestData:dict): - - # data = request.get_json() print('requestData---',requestData) data = requestData t = threading.Thread(target=kp, args=(data, )) # 通过当前线程开启新的线程去执行 @@ -209,6 +209,13 @@ def kp(event_data): if msg_type == 1: # 1 文本消息/自带表情 kp_log = f'{type_str} 文本消息 内容:{msg}' + # 将好友信息=>保存到数据库 + newFriendDict=WXBotService.get_friend_info(account_wxid, wxid) + print('newFriendDict[data]---',newFriendDict['data']) + # print(type(newFriendDict['data'])) + crud.create_user(db=get_db(),user=json.dumps(newFriendDict['data'])) + + elif msg_type == 3: # 3 图片消息 kp_log = f'{type_str} 图片消息 内容:{filepath}' # 本地dat图片解密 @@ -231,6 +238,7 @@ def kp(event_data): newFriendWxid=xml_msg.get('alias') # 将好友信息=>保存到数据库 newFriendDict=WXBotService.get_friend_info(account_wxid, newFriendWxid) + crud.create_user(db=get_db(),user=newFriendDict) elif msg_type == 42: # 42 名片消息 xml_msg = ET.fromstring(msg) diff --git a/models.py b/models.py index 7bc5a26..ad7138c 100644 --- a/models.py +++ b/models.py @@ -11,6 +11,7 @@ class User(Base): wxid = Column(String) openId = Column(String) sex = Column(String) #性别 + city = Column(String) #城市 country = Column(String) #"CN" province = Column(String) #"Hubei" sourceStr = Column(String) #:"通过朋友验证消息添加" @@ -19,4 +20,13 @@ class User(Base): wxaccount = Column(String) #微信号 remark = Column(String) #备注 smallhead = Column(String) #头像 + # bighead = Column(String) #头像-打 + # labels = Column(String) # + # source = Column(String) #来源 + # generator = Column(String) + # v1 = Column(String) + + + + diff --git a/schemas.py b/schemas.py index d7c3fab..45fb242 100644 --- a/schemas.py +++ b/schemas.py @@ -1,11 +1,7 @@ from pydantic import BaseModel - - - # 用户信息 class UserCreate(BaseModel): - password: str wxid: str openId: str sex: str @@ -22,7 +18,5 @@ class UserCreate(BaseModel): class User(UserCreate): id: int - is_active: bool - class Config: orm_mode = True \ No newline at end of file