feat: 直接数据库新建用户
This commit is contained in:
BIN
__pycache__/WXBotService.cpython-312.pyc
Normal file
BIN
__pycache__/WXBotService.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/config.cpython-312.pyc
Normal file
BIN
__pycache__/config.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/crud.cpython-312.pyc
Normal file
BIN
__pycache__/crud.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/database.cpython-312.pyc
Normal file
BIN
__pycache__/database.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/main.cpython-312.pyc
Normal file
BIN
__pycache__/main.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/models.cpython-312.pyc
Normal file
BIN
__pycache__/models.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/planet.cpython-312.pyc
Normal file
BIN
__pycache__/planet.cpython-312.pyc
Normal file
Binary file not shown.
BIN
__pycache__/schemas.cpython-312.pyc
Normal file
BIN
__pycache__/schemas.cpython-312.pyc
Normal file
Binary file not shown.
3
crud.py
3
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,
|
||||
|
||||
14
main.py
14
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)
|
||||
|
||||
10
models.py
10
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)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user