async def jiajie_sync_user(ns={}): """ {'code': 200, 'success': True, 'data': {'userId': '1934862636731187202', 'userName': '68510cdfd558b975a05dc1a5'}, 'msg': '操作成功'} :param ns: :return: """ if ns.get('userid'): userid = ns.get('userid') else: userid = await get_user() if not userid: return { 'status': False, 'msg': '用户还未登录' } # target_host = 'https://testing.vstecscloud.shop' target_host = 'https://aliyun.opencomputing.cn' db = DBPools() async with db.sqlorContext('kboss') as sor: exits_user = await sor.R('weishijiajie_users', {'user_id': userid}) if exits_user: return { 'status': True, 'msg': 'Synchronized users' } userinfos = await sor.R('users', {'id': userid}) phone = userinfos[0]['mobile'] email = userinfos[0]['email'] name = userinfos[0]['username'] # 构造请求数据 筛选条件: 手机号/邮箱 request_data = { "password": "weishijiajiekyy", "phone": phone, "email": email, "realname": name } # 数字信封加密 json_string = json.dumps(request_data) encrypted_result = await KaiYyEnDecryptUtil.encrypt_by_digital_envelope(json_string) # 发送HTTP请求 url = '%s/api/blade-user/syncinfo/user/v1' % target_host method = 'POST' header = { "AESKey": encrypted_result["AESKey"] } async with aiohttp_client.request( method=method, url=url, headers=header, data=encrypted_result["data"].encode("utf-8")) as res: result = await res.json() # 处理响应 if result.get('success'): # 正确同步 存库 sync_info = { 'id': uuid(), 'user_id': userid, 'jiajie_userid': result['data']['userId'], 'jiajie_username': result['data']['userName'] } await sor.C('weishijiajie_users', sync_info) return { 'status': True, 'msg': 'sync user success' } else: return { 'status': False, 'msg': f"用户手机号:{phone}, 请求失败,状态码: {result.get('code')},响应内容: {result.get('msg')}" } ret = await jiajie_sync_user(params_kw) return ret