diff --git a/dingxin_toolbox_drf/settings.py b/dingxin_toolbox_drf/settings.py index 4b35bdb..89a5cc2 100644 --- a/dingxin_toolbox_drf/settings.py +++ b/dingxin_toolbox_drf/settings.py @@ -36,7 +36,14 @@ CONFIG = { "PASSWORD": "cine123456", "NAME": "dingxin_toolbox", }, - 'REDIS_IP': '172.16.1.168' + 'REDIS_IP': '172.16.1.168', + 'ECARD_DB': { + "HOST": '172.16.3.53', + "PORT": 3306, + "USER": "test", + "PASSWORD": "cine123456", + "NAME": "fws_dgp_card_db", + } }, 'prd': { 'SERVER_IP': '172.16.1.63', @@ -48,7 +55,14 @@ CONFIG = { "PASSWORD": "Cine123456", "NAME": "dingxin_toolbox", }, - 'REDIS_IP': '172.16.1.63' + 'REDIS_IP': '172.16.1.63', + 'ECARD_DB': { + "HOST": '172.16.3.53', + "PORT": 3306, + "USER": "test", + "PASSWORD": "cine123456", + "NAME": "fws_dgp_card_db", + } } } diff --git a/dspt_api/migrations/0014_ecapi_order.py b/dspt_api/migrations/0014_ecapi_order.py new file mode 100644 index 0000000..3e62bbc --- /dev/null +++ b/dspt_api/migrations/0014_ecapi_order.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.7 on 2024-08-29 00:30 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dspt_api', '0013_alter_ecapiparams_description'), + ] + + operations = [ + migrations.AddField( + model_name='ecapi', + name='order', + field=models.IntegerField(default=9999, verbose_name='显示顺序'), + ), + ] diff --git a/dspt_api/models.py b/dspt_api/models.py index b2419da..9b0531c 100644 --- a/dspt_api/models.py +++ b/dspt_api/models.py @@ -39,6 +39,7 @@ class EcApi(models.Model): description = models.CharField(verbose_name='接口描述', max_length=50, null=False) path = models.CharField(verbose_name='接口地址', max_length=50, null=False) type = models.CharField(verbose_name='会员非会员', max_length=20, default='', null=False) # 会员 member 非会员 nonmember + order = models.IntegerField(verbose_name='显示顺序', default=9999) def __str__(self): return self.description diff --git a/dspt_api/urls.py b/dspt_api/urls.py index 1078e75..1ac22a8 100644 --- a/dspt_api/urls.py +++ b/dspt_api/urls.py @@ -1,9 +1,6 @@ from dspt_api import views from django.urls import path - - - urlpatterns = [ path('get_channel', views.EcChannelViewSet.as_view({'get': 'list'}), name='get_ec_channel'), path('get_env', views.EcEnvViewSet.as_view({'get': 'list'}), name='get_ec_env'), @@ -13,7 +10,7 @@ urlpatterns = [ path('get_request_log', views.EcRequestLogViewSet.as_view({'get': 'list'}), name='get_ec_request_log'), path('get_api_group', views.EcApiGroupViewSet.as_view({'get': 'list'}), name='get_ec_api_group'), path('get_params_by_type', views.get_api_params_by_api_type), - path('get_url', views.general_api_url), + path('get_url', views.general_api_url), path('send_request', views.send_request), path('get_suggest_params', views.get_suggest_params_by_api), path('get_suggest_params_timestamp', views.get_suggest_params_timestamp_by_api), diff --git a/dspt_api/util/api/ecard_detail.py b/dspt_api/util/api/ecard_detail.py new file mode 100644 index 0000000..be2c71e --- /dev/null +++ b/dspt_api/util/api/ecard_detail.py @@ -0,0 +1,46 @@ +import time +from dspt_api.util.general.handle_redis import get_data_from_redis + + +class ApiEcardDetail: + def __init__(self, **kwargs): + self.member_type = kwargs.get('member_type') + self.api = kwargs.get('api') + self.ip = kwargs.get('ip') + + def get_suggestion(self): + _now = int(time.time() * 1000) + # ecard_number + request_api_ec_1 = {'name': '3.4.4 获取联名卡详情', 'path': 'ecard/detail'} + redis_key_api_ec_1 = f'dspt_api_{self.ip}_{self.member_type}_{request_api_ec_1["path"]}' + request_api_ec_2 = {'name': '3.4.2 联名卡开卡', 'path': 'ecard/regist'} + redis_key_api_ec_2 = f'dspt_api_{self.ip}_{self.member_type}_{request_api_ec_2["path"]}' + result_ec_1, _format_ec_1, redis_data_ec_1, _timestamp_ec_1 = get_data_from_redis(redis_key_api_ec_1) + result_ec_2, _format_ec_2, redis_data_ec_2, _timestamp_ec_2 = get_data_from_redis(redis_key_api_ec_2) + ecard_number_result = False + ecard_number = False + if result_ec_2: + print('redis_data_ec_2', redis_data_ec_2) + ecard_number_ec_2 = {'param': 'ecard_number', 'value': redis_data_ec_2['ecardNumber'], + 'is_checked': True, 'result': True, + 'timestamp': _timestamp_ec_2} + ecard_number = ecard_number_ec_2 + ecard_number_result = True + if result_ec_1: + ecard_number_ec_1 = {'param': 'ecard_number', 'value': redis_data_ec_1['ecardNumber'], + 'is_checked': True, 'result': True, + 'timestamp': _timestamp_ec_1} + ecard_number = ecard_number_ec_1 + ecard_number_result = True + if result_ec_1 and result_ec_2: + ecard_number = ecard_number_ec_1 if _timestamp_ec_1 >= _timestamp_ec_2 else ecard_number_ec_2 + + if ecard_number_result: + return [ecard_number] + else: + return [{'param': 'ecard_number', 'value': redis_data_ec_1 + request_api_ec_1["name"], 'is_checked': True, + 'result': True, + 'timestamp': _now},] + + def get_timestamp(self): + return int(time.time() * 1000) diff --git a/dspt_api/util/api/ecard_order_detail.py b/dspt_api/util/api/ecard_order_detail.py new file mode 100644 index 0000000..86f5ff0 --- /dev/null +++ b/dspt_api/util/api/ecard_order_detail.py @@ -0,0 +1,59 @@ +import time +from django_redis import get_redis_connection +from dspt_api.util.general.handle_redis import get_data_from_redis + + +class ApiEcardOrderDetail: + def __init__(self, **kwargs): + self.member_type = kwargs.get('member_type') + self.api = kwargs.get('api') + self.ip = kwargs.get('ip') + + def get_suggestion(self): + _now = int(time.time() * 1000) + # partner_order_no + request_renew = {'name': '3.4.3 联名卡续卡', 'path': 'ecard/renew'} + redis_key_renew_order_num = f'dspt_api_{self.ip}_{self.member_type}_{request_renew["path"]}_order_num' + redis_key_renew = f'dspt_api_{self.ip}_{self.member_type}_{request_renew["path"]}' + + request_regist = {'name': '3.4.2 联名卡开卡', 'path': 'ecard/regist'} + redis_key_regist_order_num = f'dspt_api_{self.ip}_{self.member_type}_{request_regist["path"]}_order_num' + redis_key_regist = f'dspt_api_{self.ip}_{self.member_type}_{request_regist["path"]}' + + result_renew, _format__renew, redis_data_renew, _timestamp_renew = get_data_from_redis(redis_key_renew) + result_regist, _format_regist, redis_data_regist, _timestamp_regist = get_data_from_redis(redis_key_regist) + + redis_conn = get_redis_connection() + order_num_renew = redis_conn.get(redis_key_renew_order_num) + print('order_num_renew', order_num_renew) + order_num_regist = redis_conn.get(redis_key_regist_order_num) + print('order_num_regist', order_num_regist) + + order_num_result = [ + {'param': 'partner_order_no', 'value': '请手动输入参数!', 'is_checked': True, 'result': True, + 'timestamp': _now}, + {'param': 'order_type', 'value': '请手动输入参数!', 'is_checked': True, 'result': True, 'timestamp': _now}] + + if order_num_regist: + order_num_result_regist = [ + {'param': 'partner_order_no', 'value': str(order_num_regist, encoding='utf-8'), 'is_checked': True, + 'result': True, 'timestamp': _now}, + {'param': 'order_type', 'value': '1', 'is_checked': True, 'result': True, 'timestamp': _now}] + if order_num_renew: + order_num_result_renew = [ + {'param': 'partner_order_no', 'value': str(order_num_renew, encoding='utf-8'), 'is_checked': True, + 'result': True, + 'timestamp': _now}, + {'param': 'order_type', 'value': '2', 'is_checked': True, 'result': True, 'timestamp': _now}] + + if order_num_renew: + order_num_result = order_num_result_renew + if order_num_regist: + order_num_result = order_num_result_regist + if order_num_renew and order_num_regist: + order_num_result = order_num_result_regist if _timestamp_regist > _timestamp_renew else order_num_result_renew + + return order_num_result + + def get_timestamp(self): + return int(time.time() * 1000) diff --git a/dspt_api/util/api/ecard_refund.py b/dspt_api/util/api/ecard_refund.py new file mode 100644 index 0000000..075da0b --- /dev/null +++ b/dspt_api/util/api/ecard_refund.py @@ -0,0 +1,65 @@ +import time +from django_redis import get_redis_connection +from dspt_api.util.general.get_order_num import general_order_num +from dspt_api.util.general.handle_redis import get_data_from_redis + + +class ApiEcardRefund: + def __init__(self, **kwargs): + self.member_type = kwargs.get('member_type') + self.api = kwargs.get('api') + self.ip = kwargs.get('ip') + + def get_suggestion(self): + # partner_order_no + order_num = general_order_num('REF', self.api, self.member_type, self.ip) + # source_order_no + _now = int(time.time() * 1000) + request_renew = {'name': '3.4.3 联名卡续卡', 'path': 'ecard/renew'} + redis_key_renew_order_num = f'dspt_api_{self.ip}_{self.member_type}_{request_renew["path"]}_order_num' + redis_key_renew = f'dspt_api_{self.ip}_{self.member_type}_{request_renew["path"]}' + + request_regist = {'name': '3.4.2 联名卡开卡', 'path': 'ecard/regist'} + redis_key_regist_order_num = f'dspt_api_{self.ip}_{self.member_type}_{request_regist["path"]}_order_num' + redis_key_regist = f'dspt_api_{self.ip}_{self.member_type}_{request_regist["path"]}' + + result_renew, _format__renew, redis_data_renew, _timestamp_renew = get_data_from_redis(redis_key_renew) + result_regist, _format_regist, redis_data_regist, _timestamp_regist = get_data_from_redis(redis_key_regist) + + redis_conn = get_redis_connection() + order_num_renew = redis_conn.get(redis_key_renew_order_num) + print('order_num_renew', order_num_renew) + order_num_regist = redis_conn.get(redis_key_regist_order_num) + print('order_num_regist', order_num_regist) + + order_num_result = [ + {'param': 'source_order_no', 'value': '请手动输入参数!', 'is_checked': True, 'result': True, + 'timestamp': _now}, + {'param': 'partner_order_no', 'value': order_num, 'is_checked': True, 'result': True, + 'timestamp': int(time.time() * 1000)}] + + if order_num_regist: + order_num_result_regist = [ + {'param': 'source_order_no', 'value': str(order_num_regist, encoding='utf-8'), 'is_checked': True, + 'result': True, 'timestamp': _now}, + {'param': 'partner_order_no', 'value': order_num, 'is_checked': True, 'result': True, + 'timestamp': int(time.time() * 1000)}] + if order_num_renew: + order_num_result_renew = [ + {'param': 'source_order_no', 'value': str(order_num_renew, encoding='utf-8'), 'is_checked': True, + 'result': True, + 'timestamp': _now}, + {'param': 'partner_order_no', 'value': order_num, 'is_checked': True, 'result': True, + 'timestamp': int(time.time() * 1000)}] + + if order_num_renew: + order_num_result = order_num_result_renew + if order_num_regist: + order_num_result = order_num_result_regist + if order_num_renew and order_num_regist: + order_num_result = order_num_result_regist if _timestamp_regist > _timestamp_renew else order_num_result_renew + + return order_num_result + + def get_timestamp(self): + return int(time.time() * 1000) diff --git a/dspt_api/util/api/ecard_regist.py b/dspt_api/util/api/ecard_regist.py new file mode 100644 index 0000000..16a157f --- /dev/null +++ b/dspt_api/util/api/ecard_regist.py @@ -0,0 +1,43 @@ +from dspt_api.util.general.handle_redis import get_data_from_redis +from dspt_api.util.general.get_order_num import general_order_num +import time +import random + + +class ApiEcardRegist: + def __init__(self, **kwargs): + self.member_type = kwargs.get('member_type') + self.api = kwargs.get('api') + self.ip = kwargs.get('ip') + + def get_suggestion(self): + request_api = {'name': '3.4.1 获取联名卡等级', 'path': 'ecard/ecard-levels'} + redis_key_api = f'dspt_api_{self.ip}_{self.member_type}_{request_api["path"]}' + result, _format, redis_data, _timestamp = get_data_from_redis(redis_key_api) + if result: + level_data = random.choice(redis_data) + level_no = level_data['ecardLevelNo'] + fee = level_data['registerFee'] + order_num = general_order_num('REG', self.api, self.member_type, self.ip) + return [ + {'param': 'mobile', 'value': 18688886666, 'is_checked': True, 'result': True, 'timestamp': _timestamp}, + {'param': 'register_fee', 'value': fee, 'is_checked': True, 'result': True, 'timestamp': _timestamp}, + {'param': 'ecard_level_no', 'value': level_no, 'is_checked': True, 'result': True, + 'timestamp': _timestamp}, + {'param': 'partner_order_no', 'value': order_num, 'is_checked': True, 'result': True, + 'timestamp': _timestamp}] + else: + # 返回推荐参数应该包含参数名,参数值,和是否勾选的状态 + return [ + {'param': 'mobile', 'value': 18688886666, 'is_checked': True, 'result': True, 'timestamp': _timestamp}, + {'param': 'register_fee', 'value': redis_data + request_api["name"], 'is_checked': True, 'result': True, + 'timestamp': _timestamp}, + {'param': 'ecard_level_no', 'value': redis_data + request_api["name"], 'is_checked': True, + 'result': True, + 'timestamp': _timestamp}, + {'param': 'partner_order_no', 'value': '', 'is_checked': True, 'result': True, + 'timestamp': _timestamp} + ] + + def get_timestamp(self): + return int(time.time() * 1000) diff --git a/dspt_api/util/api/ecard_renew.py b/dspt_api/util/api/ecard_renew.py new file mode 100644 index 0000000..6f36783 --- /dev/null +++ b/dspt_api/util/api/ecard_renew.py @@ -0,0 +1,87 @@ +import random +import time +import pymysql +from pymysql.cursors import DictCursor +from dingxin_toolbox_drf.settings import CONFIG +from env import ENV +from dspt_api.util.general.get_order_num import general_order_num +from dspt_api.util.general.handle_redis import get_data_from_redis + + +class ApiEcardRenew: + def __init__(self, **kwargs): + self.member_type = kwargs.get('member_type') + self.api = kwargs.get('api') + self.ip = kwargs.get('ip') + + def get_suggestion(self): + _now = int(time.time() * 1000) + # ecard_number + request_api_ec_1 = {'name': '3.4.4 获取联名卡详情', 'path': 'ecard/detail'} + redis_key_api_ec_1 = f'dspt_api_{self.ip}_{self.member_type}_{request_api_ec_1["path"]}' + request_api_ec_2 = {'name': '3.4.2 联名卡开卡', 'path': 'ecard/regist'} + redis_key_api_ec_2 = f'dspt_api_{self.ip}_{self.member_type}_{request_api_ec_2["path"]}' + result_ec_1, _format_ec_1, redis_data_ec_1, _timestamp_ec_1 = get_data_from_redis(redis_key_api_ec_1) + result_ec_2, _format_ec_2, redis_data_ec_2, _timestamp_ec_2 = get_data_from_redis(redis_key_api_ec_2) + ecard_number_result = False + ecard_number = False + if result_ec_2: + print('redis_data_ec_2', redis_data_ec_2) + ecard_number_ec_2 = {'param': 'ecard_number', 'value': redis_data_ec_2['ecardNumber'], + 'is_checked': True, 'result': True, + 'timestamp': _timestamp_ec_2} + ecard_number = ecard_number_ec_2 + ecard_number_result = True + if result_ec_1: + ecard_number_ec_1 = {'param': 'ecard_number', 'value': redis_data_ec_1['ecardNumber'], + 'is_checked': True, 'result': True, + 'timestamp': _timestamp_ec_1} + ecard_number = ecard_number_ec_1 + ecard_number_result = True + if result_ec_1 and result_ec_2: + ecard_number = ecard_number_ec_1 if _timestamp_ec_1 >= _timestamp_ec_2 else ecard_number_ec_2 + + # renew_fee + result_renew_fee = False + if ecard_number is not False: + ecard_server = { + 'host': CONFIG[ENV]['ECARD_DB']['HOST'], + 'user': CONFIG[ENV]['ECARD_DB']['USER'], + 'password': CONFIG[ENV]['ECARD_DB']['PASSWORD'], + 'port': CONFIG[ENV]['ECARD_DB']['PORT'], + 'database': CONFIG[ENV]['ECARD_DB']['NAME'], + } + ecard_conn = pymysql.Connect(**ecard_server) + ecard_cursor = ecard_conn.cursor(DictCursor) + sql = 'SELECT renew_fee FROM fws_dgp_card_db.card_level WHERE card_level_no = (SELECT card_level_no FROM fws_dgp_card_db.card WHERE card_num = %s);' + ecard_cursor.execute(sql, (ecard_number['value'],)) + fee = ecard_cursor.fetchone()['renew_fee'] + if fee is not None: + renew_fee = {'param': 'renew_fee', 'value': fee, + 'is_checked': True, 'result': True, + 'timestamp': _now} + result_renew_fee = True + else: + renew_fee = {'param': 'renew_fee', 'value': '此卡级别不能续卡', + 'is_checked': True, 'result': True, + 'timestamp': _now} + result_renew_fee = True + + # partner_order_no + order_num = general_order_num('REN', self.api, self.member_type, self.ip) + partner_order_no = {'param': 'partner_order_no', 'value': order_num, 'is_checked': True, 'result': True, + 'timestamp': _now} + + if ecard_number_result and result_renew_fee: + return [ecard_number, renew_fee, partner_order_no] + else: + return [{'param': 'ecard_number', 'value': redis_data_ec_1 + request_api_ec_1["name"], 'is_checked': True, + 'result': True, + 'timestamp': _now}, + {'param': 'renew_fee', 'value': '请手动输入参数!', 'is_checked': True, 'result': True, + 'timestamp': _now}, + partner_order_no + ] + + def get_timestamp(self): + return int(time.time() * 1000) diff --git a/dspt_api/util/general/get_order_num.py b/dspt_api/util/general/get_order_num.py new file mode 100644 index 0000000..dcb3ba1 --- /dev/null +++ b/dspt_api/util/general/get_order_num.py @@ -0,0 +1,17 @@ +import time +import random +from django_redis import get_redis_connection + + +def general_order_num(prefix, api, api_type, ip): + # 生成新的order_num + _now = str(int(time.time() * 1000)) + _rand = str(random.randint(100, 999)) + order_num = prefix + _now + _rand + # 注册redis写入order_num + redis_conn = get_redis_connection() + redis_key = f'dspt_api_{ip}_{api_type}_{api}_order_num' + if redis_conn.get(redis_key): + redis_conn.delete(redis_key) + redis_conn.set(redis_key, order_num, 10 * 60 * 60) + return order_num diff --git a/dspt_api/util/general/handle_redis.py b/dspt_api/util/general/handle_redis.py index 254099f..c1dde79 100644 --- a/dspt_api/util/general/handle_redis.py +++ b/dspt_api/util/general/handle_redis.py @@ -29,8 +29,8 @@ def get_data_from_redis(redis_key): if str(resp_result) == '1': resp_data = resp['res']['data'] if str(resp_result) != '1': - return False, redis_data['format'], '请检查接口返回值或手动输入参数:' + return False, redis_data['format'], '请检查接口返回值或手动输入参数:', 0 if len(resp_data) == 0: - return False, redis_data['format'], '接口返回数据为空,请手动输入参数:' + return False, redis_data['format'], '接口返回数据为空,请手动输入参数:', 0 return True, redis_data['format'], resp_data, redis_data['timestamp'] return False, 'json', '请手动输入参数,或先请求接口:', 0 diff --git a/dspt_api/util/general/handle_xml_resp.py b/dspt_api/util/general/handle_xml_resp.py index 80f6c5d..228dd0b 100644 --- a/dspt_api/util/general/handle_xml_resp.py +++ b/dspt_api/util/general/handle_xml_resp.py @@ -16,9 +16,9 @@ class HandleXmlResp: if isinstance(value, dict): if len(value.keys()) == 1: _key = list(value.keys())[0] - if _key == 'item' and isinstance(value[_key], list): + if _key in ['item', 'cate'] and isinstance(value[_key], list): new_data[key] = self.format_data(value[_key]) - if _key == 'item' and isinstance(value[_key], dict): + if _key in ['item', 'cate'] and isinstance(value[_key], dict): new_data[key] = [self.format_data(value[_key])] else: new_data[key] = self.format_data(value) diff --git a/dspt_api/util/handle_goods.py b/dspt_api/util/handle_goods.py new file mode 100644 index 0000000..6ed7d45 --- /dev/null +++ b/dspt_api/util/handle_goods.py @@ -0,0 +1,6 @@ +def format_goods(_data): + goods_list = [] + for cate in _data['res']['data']: + for g in cate['goods']: + goods_list.append(g) + return {'res': {'status': _data['res']['status'], 'data': goods_list}} diff --git a/dspt_api/util/insert_api_to_db.py b/dspt_api/util/insert_api_to_db.py index 0e622d7..16eb808 100644 --- a/dspt_api/util/insert_api_to_db.py +++ b/dspt_api/util/insert_api_to_db.py @@ -1,100 +1,100 @@ -import pymysql -from pymysql.cursors import DictCursor - -db_config = { - 'host': 'home.rogersun.cn', - 'database': 'dingxin_toolbox', - 'user': 'dingxin', - 'password': 'cine123456', - 'port': 3306, -} - -db_conn = pymysql.Connect(**db_config) -db_cursor = db_conn.cursor(DictCursor) - -api_data = { - 'desc': '3.5.4 发卡明细对账', - 'path': 'cinema/send-card-bill', - 'type': 'member', -} - -params_data = [ - { - 'param': 'format', - 'description': '返回数据格式:xml或json', - 'value': 'json', - 'is_checked': 1, - 'is_request': 1, - }, - { - 'param': 'pid', - 'description': '合作商id', - 'value': None, - 'is_checked': 1, - 'is_request': 1, - }, -{ - 'param': 'cid', - 'description': '影院ID', - 'value': None, - 'is_checked': 1, - 'is_request': 1, - }, -{ - 'param': 'start_date', - 'description': '对账开始日期 示例 2016-03-01', - 'value': None, - 'is_checked': 1, - 'is_request': 1, - }, -{ - 'param': 'end_date', - 'description': '对账结束日期 示例 2016-03-01', - 'value': None, - 'is_checked': 1, - 'is_request': 1, - }, -{ - 'param': 'start_order_time', - 'description': '查询订单开始时间,如:2016-03-01 00:00:00 首次调用不传,默认为{start_date 00:00:00},之后调用按返回字段startOrderTime进行调用该时间只能在start_date与end_date范围内', - 'value': None, - 'is_checked': 0, - 'is_request': 0, - }, -{ - 'param': 'page_len', - 'description': '每次获取订单数,默认1000。范围:大于等于1000,小于等于2000。', - 'value': None, - 'is_checked': 0, - 'is_request': 0, - }, -] -params_data.append({ - 'param': '_sig', - 'description': '接口签名', - 'value': None, - 'is_checked': 1, - 'is_request': 1, -}) - -api_sql = """ -insert into dingxin_toolbox.ec_api (id, description, path, type) -values (NULL, %s, %s, %s); -""" - -r = db_cursor.execute(api_sql, (api_data['desc'], api_data['path'], api_data['type'])) -db_conn.commit() - -get_id = """select id from dingxin_toolbox.ec_api where path = %s;""" -r1 = db_cursor.execute(get_id, (api_data['path'],)) -api_id = db_cursor.fetchone()['id'] -print(api_id) - -param_sql = """insert into dingxin_toolbox.ec_api_params (id, api_id, param, description, value, is_checked, is_request) -values (NULL, %s, %s, %s, %s, %s, %s);""" - -for param in params_data: - print(param) - r2 = db_cursor.execute(param_sql, ( - api_id, param['param'], param['description'], param['value'], param['is_checked'], param['is_request'])) -db_conn.commit() +# import pymysql +# from pymysql.cursors import DictCursor +# +# db_config = { +# 'host': 'home.rogersun.cn', +# 'database': 'dingxin_toolbox', +# 'user': 'dingxin', +# 'password': 'cine123456', +# 'port': 3306, +# } +# +# db_conn = pymysql.Connect(**db_config) +# db_cursor = db_conn.cursor(DictCursor) +# +# api_data = { +# 'desc': '3.5.4 发卡明细对账', +# 'path': 'cinema/send-card-bill', +# 'type': 'member', +# } +# +# params_data = [ +# { +# 'param': 'format', +# 'description': '返回数据格式:xml或json', +# 'value': 'json', +# 'is_checked': 1, +# 'is_request': 1, +# }, +# { +# 'param': 'pid', +# 'description': '合作商id', +# 'value': None, +# 'is_checked': 1, +# 'is_request': 1, +# }, +# { +# 'param': 'cid', +# 'description': '影院ID', +# 'value': None, +# 'is_checked': 1, +# 'is_request': 1, +# }, +# { +# 'param': 'start_date', +# 'description': '对账开始日期 示例 2016-03-01', +# 'value': None, +# 'is_checked': 1, +# 'is_request': 1, +# }, +# { +# 'param': 'end_date', +# 'description': '对账结束日期 示例 2016-03-01', +# 'value': None, +# 'is_checked': 1, +# 'is_request': 1, +# }, +# { +# 'param': 'start_order_time', +# 'description': '查询订单开始时间,如:2016-03-01 00:00:00 首次调用不传,默认为{start_date 00:00:00},之后调用按返回字段startOrderTime进行调用该时间只能在start_date与end_date范围内', +# 'value': None, +# 'is_checked': 0, +# 'is_request': 0, +# }, +# { +# 'param': 'page_len', +# 'description': '每次获取订单数,默认1000。范围:大于等于1000,小于等于2000。', +# 'value': None, +# 'is_checked': 0, +# 'is_request': 0, +# }, +# ] +# params_data.append({ +# 'param': '_sig', +# 'description': '接口签名', +# 'value': None, +# 'is_checked': 1, +# 'is_request': 1, +# }) +# +# api_sql = """ +# insert into dingxin_toolbox.ec_api (id, description, path, type) +# values (NULL, %s, %s, %s); +# """ +# +# r = db_cursor.execute(api_sql, (api_data['desc'], api_data['path'], api_data['type'])) +# db_conn.commit() +# +# get_id = """select id from dingxin_toolbox.ec_api where path = %s;""" +# r1 = db_cursor.execute(get_id, (api_data['path'],)) +# api_id = db_cursor.fetchone()['id'] +# print(api_id) +# +# param_sql = """insert into dingxin_toolbox.ec_api_params (id, api_id, param, description, value, is_checked, is_request) +# values (NULL, %s, %s, %s, %s, %s, %s);""" +# +# for param in params_data: +# print(param) +# r2 = db_cursor.execute(param_sql, ( +# api_id, param['param'], param['description'], param['value'], param['is_checked'], param['is_request'])) +# db_conn.commit() diff --git a/dspt_api/util/random_params.py b/dspt_api/util/random_params.py index 79ceffd..707a400 100644 --- a/dspt_api/util/random_params.py +++ b/dspt_api/util/random_params.py @@ -4,12 +4,11 @@ import time from django_redis import get_redis_connection -RANDOM_DATA_API_LIST = ['cinema/plays', 'play/seat-status'] +RANDOM_DATA_API_LIST = ['cinema/plays', 'play/seat-status', 'cinema/goods', 'ecard/ecard-levels'] def random_params(_user_info, _handle_data): if _user_info["api"] in RANDOM_DATA_API_LIST: - print('_user_info', _user_info) - print('_handle_data', _handle_data) + redis_key_api = f'dspt_api_{_user_info["user_ip"]}_{_user_info["member_type"]}_{_user_info["api"]}_random' redis_conn = get_redis_connection() if redis_conn.get(redis_key_api): @@ -22,6 +21,8 @@ def random_params(_user_info, _handle_data): } if _user_info["api"] == 'play/seat-status': _user_data = get_ok_status_seat_list(_handle_data['res']['data']) + if _user_info["api"] == 'ecard/ecard-levels': + _user_data = _handle_data['res']['data']['ecardLevelData'] else: _user_data = _handle_data['res']['data'] if len(_user_data) > 0: @@ -29,7 +30,7 @@ def random_params(_user_info, _handle_data): data['user_data'] = [[random.choice(_user_data)]] else: data['user_data'] = [random.choice(_user_data)] - redis_conn.set(redis_key_api, json.dumps(data)) + redis_conn.set(redis_key_api, json.dumps(data), 10 * 60 * 60) else: redis_conn.delete(redis_key_api) diff --git a/dspt_api/util/suggest_params.py b/dspt_api/util/suggest_params.py index 25d1295..fcc728a 100644 --- a/dspt_api/util/suggest_params.py +++ b/dspt_api/util/suggest_params.py @@ -1,11 +1,16 @@ from dspt_api.util.api.cinema_hall_seats import ApiCinemaHallSeats from dspt_api.util.api.cinema_plays_increment import ApiCinemaPlaysIncrement +from dspt_api.util.api.ecard_refund import ApiEcardRefund +from dspt_api.util.api.ecard_regist import ApiEcardRegist +from dspt_api.util.api.ecard_renew import ApiEcardRenew from dspt_api.util.api.play_info import ApiPlayInfo from dspt_api.util.api.play_seat_status import ApiPlaySeatStatus from dspt_api.util.api.play_period_changed_seats import ApiPlayPeriodChangedSeats from dspt_api.util.api.play_seat_overview import ApiPlaySeatOverview from dspt_api.util.api.cinema_goods_pic import ApiCinemaGoodsPic from dspt_api.util.api.seat_lock import ApiSeatLock +from dspt_api.util.api.ecard_detail import ApiEcardDetail +from dspt_api.util.api.ecard_order_detail import ApiEcardOrderDetail # 通过api来匹配不同的接口文件获取推荐 @@ -38,6 +43,21 @@ def suggest_params(member_type, api, ip): if api == 'seat/lock' and member_type == 'nonmember': print('seat/lock') params = ApiSeatLock(**data).get_suggestion() + if api == 'ecard/regist' and member_type == 'nonmember': + print('ecard/regist') + params = ApiEcardRegist(**data).get_suggestion() + if api == 'ecard/renew' and member_type == 'nonmember': + print('ecard/renew') + params = ApiEcardRenew(**data).get_suggestion() + if api == 'ecard/detail' and member_type == 'nonmember': + print('ecard/detail') + params = ApiEcardDetail(**data).get_suggestion() + if api == 'ecard/order-detail' and member_type == 'nonmember': + print('ecard/order-detail') + params = ApiEcardOrderDetail(**data).get_suggestion() + if api == 'ecard/refund' and member_type == 'nonmember': + print('ecard/refund') + params = ApiEcardRefund(**data).get_suggestion() return params def suggest_params_timestamp(member_type, api, ip): @@ -68,4 +88,19 @@ def suggest_params_timestamp(member_type, api, ip): if api == 'seat/lock' and member_type == 'nonmember': print('seat/lock') _timestamps = ApiSeatLock(**data).get_timestamp() + if api == 'ecard/regist' and member_type == 'nonmember': + print('ecard/regist') + _timestamps = ApiEcardRegist(**data).get_timestamp() + if api == 'ecard/renew' and member_type == 'nonmember': + print('ecard/renew') + _timestamps = ApiEcardRenew(**data).get_timestamp() + if api == 'ecard/detail' and member_type == 'nonmember': + print('ecard/detail') + _timestamps = ApiEcardDetail(**data).get_timestamp() + if api == 'ecard/order-detail' and member_type == 'nonmember': + print('ecard/order-detail') + _timestamps = ApiEcardOrderDetail(**data).get_timestamp() + if api == 'ecard/refund' and member_type == 'nonmember': + print('ecard/refund') + _timestamps = ApiEcardRefund(**data).get_timestamp() return _timestamps \ No newline at end of file diff --git a/dspt_api/views.py b/dspt_api/views.py index bbab863..dbcd5c5 100644 --- a/dspt_api/views.py +++ b/dspt_api/views.py @@ -16,6 +16,7 @@ from django.http.response import JsonResponse, HttpResponse # from rest_framework.response import Response from django.utils import timezone +from dspt_api.util.handle_goods import format_goods from dspt_api.util.random_params import random_params from dspt_api.util.sign import Sign from dspt_api.models import EcChannel, EcEnv, EcApi, EcApiParams, EcCinemaIds, EcRequestLog, EcApiGroup @@ -38,7 +39,7 @@ class EcEnvViewSet(viewsets.ModelViewSet): class EcApiViewSet(viewsets.ModelViewSet): - queryset = EcApi.objects.all() + queryset = EcApi.objects.order_by('order').all() serializer_class = EcApiSerializer filter_backends = (DjangoFilterBackend,) # http://172.16.1.114:8000/ec/get_api?type=nonmember @@ -217,7 +218,9 @@ def send_request(request): if resp_format == 'xml': response_data = format_xml(re.sub(r'>\n?\s+?<', r'>\n<', response.text)) handled_data = HandleXmlResp(response.text).format_xml() - + # 卖品接口特殊处理去掉无用cate一层结构 + if api == 'cinema/goods': + handled_data = format_goods(handled_data) # 记录Redis if redis_conn.exists(redis_key_api): redis_conn.delete(redis_key_api) diff --git a/update/utils/git_util.py b/update/utils/git_util.py index dcf77db..54142e2 100644 --- a/update/utils/git_util.py +++ b/update/utils/git_util.py @@ -1,6 +1,4 @@ from git import Repo - -from dspt_api.util.insert_api_to_db import db_conn, db_cursor from update.models import Release import os import shutil