diff --git a/b/ali/jiajie_get_token_redirect.dspy b/b/ali/jiajie_get_token_redirect.dspy index 47e0c75..1a3e680 100644 --- a/b/ali/jiajie_get_token_redirect.dspy +++ b/b/ali/jiajie_get_token_redirect.dspy @@ -4,7 +4,7 @@ async def jiajie_get_token_redirect(ns={}): :return: """ # target_host = 'https://testing.vstecscloud.shop' - target_host = 'https://aliyun.kaiyuancloud.cn' + target_host = 'https://aliyun.opencomputing.cn' if ns.get('userid'): userid = ns.get('userid') @@ -39,7 +39,7 @@ async def jiajie_get_token_redirect(ns={}): # 发送HTTP请求 url = "%s/api/blade-auth/oauth/token" % target_host - if 'kaiyuancloud' in target_host: + if 'opencomputing' in target_host: tenantid = '502332' else: tenantid = '024060' diff --git a/b/ali/jiajie_sync_user.dspy b/b/ali/jiajie_sync_user.dspy index 487ffc0..d0fd294 100644 --- a/b/ali/jiajie_sync_user.dspy +++ b/b/ali/jiajie_sync_user.dspy @@ -15,7 +15,7 @@ async def jiajie_sync_user(ns={}): 'msg': '用户还未登录' } # target_host = 'https://testing.vstecscloud.shop' - target_host = 'https://aliyun.kaiyuancloud.cn' + 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}) @@ -71,7 +71,7 @@ async def jiajie_sync_user(ns={}): else: return { 'status': False, - 'msg': f"请求失败,状态码: {result.get('code')},响应内容: {result.get('msg')}" + 'msg': f"用户手机号:{phone}, 请求失败,状态码: {result.get('code')},响应内容: {result.get('msg')}" } ret = await jiajie_sync_user(params_kw) diff --git a/b/customer/registerUser.dspy b/b/customer/registerUser.dspy index 9c78a74..3f98667 100644 --- a/b/customer/registerUser.dspy +++ b/b/customer/registerUser.dspy @@ -29,10 +29,20 @@ async def registerUser(ns): if len(ns.get('password')) < 6: return {'status': False, 'msg': '密码必须6位数以上'} + if not ns.get('codeid'): + return {'status': False, 'msg': '验证码ID不能为空'} + if ns.get('codeid'): - type += 1 code = await sor.R('validatecode', {'id': ns.get('codeid'), 'vcode': ns.get('vcode')}) - if len(code) < 1: + # 验证码五分钟内才有效 create_at是字符串 格式是"2025-11-05 16:00:19" + if code: + create_at = code[0]['create_at'] + now = datetime.datetime.now() + create_at_dt = datetime.datetime.strptime(create_at, "%Y-%m-%d %H:%M:%S") + if (now - create_at_dt).seconds > 500: + return {'status': False, 'msg': '验证码过期'} + + else: return {'status': False, 'msg': '验证码不正确'} #通过邀请码注册 @@ -160,8 +170,8 @@ async def registerUser(ns): await openCustomerAccounts(sor, org[0]['id'], org_id) return {'status': True, 'msg': '注册成功'} except Exception as error: - raise error - return {'status': False, 'msg': '注册失败'} + # raise error + return {'status': False, 'msg': '注册失败, %s' % str(error)} ret = await registerUser(params_kw) diff --git a/b/product/baidu_resource_query.dspy b/b/product/baidu_resource_query.dspy new file mode 100644 index 0000000..9343160 --- /dev/null +++ b/b/product/baidu_resource_query.dspy @@ -0,0 +1,82 @@ +async def baidu_resource_query(ns={}): + """ + 用户资源查询 + :param ns: + :return: + """ + if ns.get('userid'): + userid = ns.get('userid') + else: + userid = await get_user() + db = DBPools() + async with db.sqlorContext('kboss') as sor: + baiduids = await sor.R('baidu_users', {'user_id': userid}) + if baiduids: + baiduid = baiduids[0]['baidu_id'] + else: + return { + 'status': False, + 'msg': 'User not synchronized' + } + ns['queryAccountId'] = baiduid + ns['pageSize'] = 200 + method = 'POST' + ns_format = '&'.join(['%s=%s' % (k, v) for k, v in ns.items()]) + url = 'https://billing.baidubce.com/v1/resource/query?%s' % ns_format + header = { + "Host": "billing.baidubce.com" + } + header = await get_auth_header(method=method, url=url, header=header) + async with aiohttp_client.request( + method=method, + url=url, + headers=header, + json=ns) as res: + result = await res.json() + return {'1': result} + + result_new = [] + for i in result['result']: + if i.get('status') != 'STOPPED': + result_new.append(i) + + result['result'] = result_new + + return { + 'status': True, + 'msg': 'get resource success', + 'data': result + } + +async def resource_overview(ns={}): + if ns.get('userid'): + userid = ns.get('userid') + else: + userid = await get_user() + init_data = [ + {'id': 1, 'name': '云服务器', 'count': 0, 'unit': '实例'}, + {'id': 2, 'name': '私有网络', 'count': 0, 'unit': 'VPC'}, + {'id': 3, 'name': '负载均衡', 'count': 0, 'unit': '负载均衡'}, + {'id': 4, 'name': '弹性块存储', 'count': 0, 'unit': '云盘'}, + {'id': 5, 'name': 'NAT网关', 'count': 0, 'unit': '实例'}, + {'id': 6, 'name': 'VPN连接', 'count': 0, 'unit': 'VPN网关'}, + ] + baidu_resource_data = await baidu_resource_query({'userid': userid}) + print(baidu_resource_data) + if baidu_resource_data and baidu_resource_data.get('data') and baidu_resource_data['data'].get('result'): + for baidu_resource in baidu_resource_data['data']['result']: + if baidu_resource.get('serviceType') == 'CDS' and baidu_resource['status'] == 'RUNNING': + init_data[3]['count'] += 1 + elif baidu_resource.get('serviceType') == 'EIP' and baidu_resource['status'] == 'RUNNING': + init_data[1]['count'] += 1 + elif (baidu_resource.get('serviceType') == 'BCC' or baidu_resource.get('serviceType') == 'LS') and baidu_resource['status'] == 'RUNNING': + init_data[0]['count'] += 1 + + return { + 'status': True, + 'msg': 'get resource success', + 'data': init_data + } + +ret = await baidu_resource_query(params_kw) +return ret \ No newline at end of file diff --git a/b/product/get_firstpage_net_detail.dspy b/b/product/get_firstpage_net_detail.dspy index 6e759e3..d605fec 100644 --- a/b/product/get_firstpage_net_detail.dspy +++ b/b/product/get_firstpage_net_detail.dspy @@ -1113,7 +1113,7 @@ detailDataLJS = { { "title": "NVIDIA-4090-48G", "description": "High-performance GPU server with powerful computing capabilities, suitable for AI training, deep learning, etc.", - "price": "8000", + "price": "8800", "pre_price": None, "price_unit": "台/月", "discount": None, @@ -1207,7 +1207,7 @@ detailDataLJS = { { "title": "NVIDIA-4090", "description": "High-performance GPU server with powerful computing capabilities, suitable for AI training, deep learning, etc.", - "price": "6500", + "price": "7200", "pre_price": None, "price_unit": "台/月", "discount": None, diff --git a/b/user/mobilecode.dspy b/b/user/mobilecode.dspy index 783802e..2967639 100644 --- a/b/user/mobilecode.dspy +++ b/b/user/mobilecode.dspy @@ -1,26 +1,67 @@ async def mobilecode(ns): - """登录发送短信验证码""" + """发送短信验证码,支持注册和登录筛选""" db = DBPools() async with db.sqlorContext('kboss') as sor: - type = 0 - ns['del_flg'] = '0' - userreacs = await sor.R('users', ns) - if len(userreacs) >= 1: - type += 1 - else: - userreacs = await sor.R('users', {'mobile': ns['username'], 'del_flg': '0'}) - if len(userreacs) >= 1: - type += 1 - if type >= 1: - code = await generate_vcode() - nss = await send_vcode(userreacs[0]['mobile'], '用户注册登录验证', {'SMSvCode': code.get('vcode')}) - # return {'1':nss} - if nss: - return {'status': True, 'msg': '发送成功', 'codeid': code.get('id')} + # 获取操作类型:register 或 login + action_type = ns.get('action_type') # register 或 login + + if not action_type: + return {'status': False, 'msg': '操作类型action_type不能为空'} + + # 通过手机号查找用户 + mobile = ns.get('mobile') + if not mobile: + return {'status': False, 'msg': '手机号不能为空'} + + userreacs = await sor.R('users', {'mobile': mobile, 'del_flg': '0'}) + + # 注册逻辑:检查手机号是否已存在 + if action_type == 'register': + if len(userreacs) >= 1: + return {'status': False, 'msg': '手机号已注册,请直接登录'} else: - return {'status': False, 'msg': '发送失败'} + # 注册时手机号不存在,可以发送验证码 + code = await generate_vcode() + nss = await send_vcode(mobile, '用户注册登录验证', {'SMSvCode': code.get('vcode')}) + if nss['status']: + return {'status': True, 'msg': '注册验证码发送成功', 'codeid': code.get('id')} + else: + return {'status': False, 'msg': '发送失败'} + + # 登录逻辑:检查手机号是否存在 + elif action_type == 'login': + if len(userreacs) >= 1: + # 登录时手机号存在,可以发送验证码 + code = await generate_vcode() + nss = await send_vcode(userreacs[0]['mobile'], '用户注册登录验证', {'SMSvCode': code.get('vcode')}) + if nss['status']: + return {'status': True, 'msg': '登录验证码发送成功', 'codeid': code.get('id')} + else: + return {'status': False, 'msg': '发送失败'} + else: + return {'status': False, 'action': 'redirect', 'msg': '用户未注册, 请到注册页面注册'} + + # 原有逻辑:如果没有指定action_type,保持原有逻辑 else: - return {'status': False, 'action': 'redirect', 'msg': '用户未注册, 请到注册页面注册'} + type = 0 + ns['del_flg'] = '0' + userreacs = await sor.R('users', ns) + if len(userreacs) >= 1: + type += 1 + else: + userreacs = await sor.R('users', {'mobile': ns['username'], 'del_flg': '0'}) + if len(userreacs) >= 1: + type += 1 + if type >= 1: + code = await generate_vcode() + nss = await send_vcode(userreacs[0]['mobile'], '用户注册登录验证', {'SMSvCode': code.get('vcode')}) + # return {'1':nss} + if nss: + return {'status': True, 'msg': '发送成功', 'codeid': code.get('id')} + else: + return {'status': False, 'msg': '发送失败'} + else: + return {'status': False, 'action': 'redirect', 'msg': '用户未注册, 请到注册页面注册'} ret = await mobilecode(params_kw)