update
This commit is contained in:
parent
63a1d4d1f0
commit
9293263505
38
b/cntoai/get_deerer_header.dspy
Normal file
38
b/cntoai/get_deerer_header.dspy
Normal file
@ -0,0 +1,38 @@
|
||||
async def get_deerer_header(ns={}):
|
||||
from appPublic.aes import aes_decode_b64, aes_encode_b64
|
||||
if not ns.get('userid'):
|
||||
userid = await get_user()
|
||||
else:
|
||||
userid = ns.get('userid')
|
||||
if not userid:
|
||||
return {
|
||||
'status': False,
|
||||
'msg': '请传递用户ID'
|
||||
}
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('kboss') as sor:
|
||||
records = await sor.R('user_api_keys', {'userid': userid})
|
||||
if not records:
|
||||
return {
|
||||
'status': False,
|
||||
'msg': '未找到匹配的用户'
|
||||
}
|
||||
apikey = records[0]['opc_apikey']
|
||||
appid = records[0]['appid']
|
||||
sk = records[0]['secretkey']
|
||||
if not apikey or not appid or not sk:
|
||||
return {
|
||||
'status': False,
|
||||
'msg': '没有找到匹配的用户'
|
||||
}
|
||||
tim = time.time()
|
||||
txt = f'{tim}:{apikey}'
|
||||
cyber = aes_encode_b64(sk, txt)
|
||||
return {
|
||||
'status': True,
|
||||
'data': f'Deerer {appid}-:-{cyber}'
|
||||
}
|
||||
|
||||
|
||||
ret = await get_deerer_header(params_kw)
|
||||
return ret
|
||||
@ -1,5 +1,11 @@
|
||||
async def sync_cn_ai_user(userid=None, orgid=None, username=None, name=None, email=None):
|
||||
import aiohttp
|
||||
|
||||
debug(f"sync_cn_ai_user同步用户: {userid}, {orgid}, {username}, {name}, {email}")
|
||||
already_sync_user_key = '2i68AZ81di_q5f8AySDrJ'
|
||||
already_sync_user_dappid = 'cndemo'
|
||||
|
||||
|
||||
# 目标URL
|
||||
url = "https://ai.atvoe.com/rbac/usersync"
|
||||
# url = 'https://ai.atvoe.com/tmp/env.dspy'
|
||||
@ -7,13 +13,13 @@ async def sync_cn_ai_user(userid=None, orgid=None, username=None, name=None, ema
|
||||
# 请求头
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "Bearer " + "2i68AZ81di_q5f8AySDrJ"
|
||||
"Authorization": "Bearer %s" % already_sync_user_key
|
||||
}
|
||||
|
||||
# 请求体数据
|
||||
payload = {
|
||||
"action": "single",
|
||||
"dappid": "cndemo",
|
||||
"dappid": already_sync_user_dappid,
|
||||
"user": {
|
||||
"id": userid,
|
||||
"orgid": orgid,
|
||||
@ -30,11 +36,11 @@ async def sync_cn_ai_user(userid=None, orgid=None, username=None, name=None, ema
|
||||
# 发送POST请求
|
||||
async with session.post(url, headers=headers, data=json.dumps(payload)) as response:
|
||||
# 打印响应状态码
|
||||
print(f"状态码: {response.status}")
|
||||
debug(f"sync_cn_ai_user状态码: {response.status}")
|
||||
result_sysnc = await response.json()
|
||||
|
||||
if not result_sysnc.get('status') == 'success':
|
||||
print(f"同步用户失败")
|
||||
debug(f"sync_cn_ai_user同步用户失败: {result_sysnc}")
|
||||
return {
|
||||
'status': False
|
||||
}
|
||||
@ -44,9 +50,12 @@ async def sync_cn_ai_user(userid=None, orgid=None, username=None, name=None, ema
|
||||
# user_api_keys表格 userid/opc_apikey
|
||||
# 首先判断apikey是否存在
|
||||
apikey = result_sysnc['data'][0].get('apikey')
|
||||
appid = result_sysnc['data'][0].get('appid')
|
||||
secretkey = result_sysnc['data'][0].get('secretkey')
|
||||
|
||||
records = await sor.R('user_api_keys', {'opc_apikey': apikey})
|
||||
if records:
|
||||
print(f"用户{payload['user']['id']}已存在")
|
||||
debug(f"sync_cn_ai_user用户{payload['user']['id']}已存在")
|
||||
return {
|
||||
'status': False,
|
||||
'msg': '用户opc_apikey已存在'
|
||||
@ -54,19 +63,22 @@ async def sync_cn_ai_user(userid=None, orgid=None, username=None, name=None, ema
|
||||
await sor.C('user_api_keys', {
|
||||
'userid': userid,
|
||||
'opc_apikey': apikey,
|
||||
'appid': appid,
|
||||
'secretkey': secretkey,
|
||||
'expire_time': None,
|
||||
})
|
||||
|
||||
debug(f"sync_cn_ai_user用户{payload['user']['id']}同步成功")
|
||||
return {
|
||||
'status': True,
|
||||
'msg': '用户同步成功'
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
print(f"同步用户失败: {e}")
|
||||
debug(f"sync_cn_ai_user{userid}同步用户失败: {e}")
|
||||
return {
|
||||
'status': False,
|
||||
'msg': f"同步用户失败: {e}"
|
||||
'msg': f"sync_cn_ai_user{userid}同步用户失败: {e}"
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -40,6 +40,7 @@ from appPublic.jsonConfig import getConfig
|
||||
from appPublic.i18n import getI18N
|
||||
from appPublic.timeUtils import strdate_add
|
||||
from appPublic.rc4 import unpassword, password
|
||||
from appPublic.aes import aes_decode_b64, aes_encode_b64
|
||||
|
||||
|
||||
from ahserver.filedownload import path_encode
|
||||
@ -217,6 +218,8 @@ if __name__ == '__main__':
|
||||
g.KaiYyEnDecryptUtil = KaiYyEnDecryptUtil
|
||||
g.async_post = async_post
|
||||
g.jsonpath = jsonpath
|
||||
g.aes_decode_b64 = aes_decode_b64
|
||||
g.aes_encode_b64 = aes_encode_b64
|
||||
|
||||
i18n = getI18N(path=workdir)
|
||||
info(f'gadget version={__version__}')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user