You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.5 KiB
56 lines
1.5 KiB
4 weeks ago
|
from django_redis import get_redis_connection
|
||
|
from dspt_api.models import EcChannel, EcEnv
|
||
|
from django.db.models import Q
|
||
|
from dspt_api.util.general.sign import Sign
|
||
|
import requests
|
||
|
|
||
|
|
||
|
def get_card(ip, env, pid, cid):
|
||
|
redis_con = get_redis_connection()
|
||
|
redis_key = f"card_{ip}_{env}_{pid}_{cid}"
|
||
|
print('get_card-card_num', redis_key)
|
||
|
if redis_con.exists(redis_key):
|
||
|
card_num = redis_con.get(redis_key)
|
||
|
print('get_card-card_num', card_num)
|
||
|
return str(card_num, encoding='utf-8')
|
||
|
return False
|
||
|
|
||
|
|
||
|
def set_card(ip, env, pid, cid, card):
|
||
|
redis_con = get_redis_connection()
|
||
|
redis_key = f"card_{ip}_{env}_{pid}_{cid}"
|
||
|
if redis_con.exists(redis_key):
|
||
|
redis_con.delete(redis_key)
|
||
|
return redis_con.set(redis_key, card)
|
||
|
|
||
|
|
||
|
def get_card_type(env, pid, cid, card):
|
||
|
params = {
|
||
|
'format': 'json',
|
||
|
'pid': pid,
|
||
|
'cid': cid,
|
||
|
'card': card,
|
||
|
}
|
||
|
|
||
|
try:
|
||
|
base_url = EcEnv.objects.filter(Q(code=env) & Q(type='member')).values('host').first()['host']
|
||
|
except Exception as e:
|
||
|
return False, e
|
||
|
|
||
|
request_url = f"{base_url}/card/detail"
|
||
|
|
||
|
try:
|
||
|
key = EcChannel.objects.filter(Q(pid=pid) & Q(env=env)).values('channel_key').first()['channel_key']
|
||
|
except Exception as e:
|
||
|
return False, e
|
||
|
|
||
|
sign = Sign(key)
|
||
|
req_params = sign.add_sig(params)
|
||
|
|
||
|
response = requests.get(request_url, params=req_params)
|
||
|
|
||
|
if response.json()['res']['status'] != 1:
|
||
|
return False
|
||
|
else:
|
||
|
return response.json()['res']['data']['cardType']
|