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):
|
def saveWxidInfo(account_wxid, wxid, openId=None, h5openid=None):
|
||||||
print('wxid',wxid)
|
print('wxid', wxid)
|
||||||
print('openId',openId)
|
print('openId', openId)
|
||||||
print('h5openid',h5openid)
|
print('h5openid', h5openid)
|
||||||
|
|
||||||
allFriend = WXBotService.get_address_list(account_wxid)
|
allFriend = WXBotService.get_address_list(account_wxid)
|
||||||
for friendItem in allFriend['data']["contactList"]:
|
for friendItem in allFriend['data']["contactList"]:
|
||||||
if friendItem['wxid'] == wxid:
|
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)
|
db_user = crud.get_user_by_wxid(db=SessionLocal(), wxid=wxid)
|
||||||
if db_user:
|
if db_user:
|
||||||
print("wxid already registered")
|
print("wxid already registered")
|
||||||
print("开始更新数据表")
|
if friendItem['openId'] and friendItem['h5openid']:
|
||||||
crud.update_user_field(db=SessionLocal(),wxid=wxid,openId=openId,h5openid=h5openid)
|
print('用户数据openid和h5id都存在,无需更新')
|
||||||
|
else:
|
||||||
|
print("开始更新数据表")
|
||||||
|
crud.update_user_field(db=SessionLocal(),
|
||||||
|
wxid=wxid,
|
||||||
|
openId=openId,
|
||||||
|
h5openid=h5openid)
|
||||||
# 更新数据
|
# 更新数据
|
||||||
# return db_user
|
# return db_user
|
||||||
else:
|
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
|
return new_user
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user