kboss/b/zj/syncUser.dspy
2025-07-16 14:27:17 +08:00

62 lines
1.9 KiB
Plaintext

async def syncUser(ns={}):
"""
:param ns:
:return:
"""
nss = {
'ak': 'c752863753f8',
'sk': 'c6efdbd682084a2f96e7500e5a535449',
'appId': 'cdz-server'
}
ak = nss.get('ak')
sk = nss.get('sk')
appId = nss.get('appId')
if not (ak and sk and appId):
return {
"code":"1",
"msg":"ak or sk or appId is None"
}
timestamp = str(int(time.time() * 1000))
token = str(uuid())
sign = sk + appId + token + timestamp
md5_object = hashlib.md5()
md5_object.update(sign.encode())
sign = md5_object.hexdigest()
db = DBPools()
async with db.sqlorContext('kboss') as sor:
url = 'http://101.36.139.188:8888/cdz-admin/zjapi/v1/userInfo/synData'
header = {
'content-type': 'application/json',
'appId': appId,
'ak': ak,
'timestamp': timestamp,
'token': token,
'sign': sign
}
data = json.loads(ns) if isinstance(ns, str) else ns
res = requests.post(url=url, headers=header, json=data)
res_dict = json.loads(res.text)
if res_dict.get('code') == '0':
try:
status_sql = """update zj_users set sync_status = 1 where orgid = ${orgid}$; """
await sor.sqlExe(status_sql, {'orgid': ns.get('orgid')})
except Exception as e:
return {
'status': False,
'msg': 'sync user is success, but table update is failed'
}
return {
'status': True,
'msg': 'sync user success',
'data': res.text
}
else:
return {
'status': False,
'msg': 'sync user is Failed',
'data': res.text
}
ret = await syncUser(params_kw)
return ret