update
This commit is contained in:
35
utils.py
35
utils.py
@@ -25,29 +25,36 @@ from pydantic import BaseModel
|
||||
|
||||
|
||||
# 保存好友信息
|
||||
def saveWxidInfo(account_wxid, wxid,openId=None,h5openid=None):
|
||||
print('wxid',wxid)
|
||||
print('openId',openId)
|
||||
print('h5openid',h5openid)
|
||||
|
||||
def saveWxidInfo(account_wxid, wxid, openId=None, h5openid=None):
|
||||
print('wxid', wxid)
|
||||
print('openId', openId)
|
||||
print('h5openid', h5openid)
|
||||
|
||||
allFriend = WXBotService.get_address_list(account_wxid)
|
||||
for friendItem in allFriend['data']["contactList"]:
|
||||
if friendItem['wxid'] == wxid:
|
||||
# 存储小程序openid
|
||||
if openId:
|
||||
friendItem['openId'] = openId
|
||||
if h5openid:
|
||||
friendItem['h5openid'] = h5openid
|
||||
friendItemObj = models.User(**friendItem)
|
||||
db_user = crud.get_user_by_wxid(db=SessionLocal(), wxid=wxid)
|
||||
if db_user:
|
||||
print("wxid already registered")
|
||||
print("开始更新数据表")
|
||||
crud.update_user_field(db=SessionLocal(),wxid=wxid,openId=openId,h5openid=h5openid)
|
||||
if friendItem['openId'] and friendItem['h5openid']:
|
||||
print('用户数据openid和h5id都存在,无需更新')
|
||||
else:
|
||||
print("开始更新数据表")
|
||||
crud.update_user_field(db=SessionLocal(),
|
||||
wxid=wxid,
|
||||
openId=openId,
|
||||
h5openid=h5openid)
|
||||
# 更新数据
|
||||
# return db_user
|
||||
else:
|
||||
new_user=crud.create_user(db=SessionLocal(), user=friendItemObj)
|
||||
# 存储小程序openid
|
||||
if openId:
|
||||
friendItem['openId'] = openId
|
||||
if h5openid:
|
||||
friendItem['h5openid'] = h5openid
|
||||
friendItemObj = models.User(**friendItem)
|
||||
new_user = crud.create_user(db=SessionLocal(),
|
||||
user=friendItemObj)
|
||||
return new_user
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user