Payment failure
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ @Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved. @AUTHOR: ASJRD018 @NAME: AnsjerFormal @software: PyCharm @DATE: 2018/12/5 9:30 @Version: python3.6 @MODIFY DECORD:ansjer dev @file: cloudstorage.py @Contact: chanjunkai@163.com """ import json import time import urllib import boto3 import oss2 import paypalrestsdk import threading import calendar import datetime from aliyunsdkcore import client from aliyunsdksts.request.v20150401 import AssumeRoleRequest from boto3.session import Session from django.http import JsonResponse, HttpResponseRedirect, HttpResponse from django.views.generic.base import View from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, OSS_ROLE_ARN, SERVER_DOMAIN, PAYPAL_CRD, \ SERVER_DOMAIN_SSL from Model.models import Device_Info, Order_Model, Store_Meal, VodHlsModel, OssCrdModel, UID_Bucket, StsCrdModel, \ ExperienceContextModel, Pay_Type, CDKcontextModel from Object.AliPayObject import AliPayObject from Object.ResponseObject import ResponseObject from Object.TokenObject import TokenObject from Object.UidTokenObject import UidTokenObject from Service.CommonService import CommonService from Object.m3u8generate import PlaylistGenerator from Object.WechatPayObject import WechatPayObject from django.db.models import Q SERVER_DOMAIN = 'http://test.dvema.com/' ''' 生成订单 http://test.dvema.com/cloudstorage/createpayorder?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySUQiOiIxNTY3NzU4MjE4NjE5MTM4MDAxMzgwMDAiLCJleHAiOjE1ODk1MjM0OTIsIm1fY29kZSI6IjEyMzQxMzI0MzIxNCIsImxhbmciOiJlbiIsInVzZXIiOiIxMzExOTY1NzcxMyJ9.e2NdhJtbXrDngZTSmOX_52Y-oxyfUEXjZD_qNxg6VrU&uid=VVDHCVBYDKFMJRWA111A&channel=1&pay_type=0&commodity_code=aws_us_vod_7_val_30 开启开关 http://test.dvema.com/cloudstorage/changevodstatus?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySUQiOiIxNTY3NzU4MjE4NjE5MTM4MDAxMzgwMDAiLCJleHAiOjE1ODk1MjM0OTIsIm1fY29kZSI6IjEyMzQxMzI0MzIxNCIsImxhbmciOiJlbiIsInVzZXIiOiIxMzExOTY1NzcxMyJ9.e2NdhJtbXrDngZTSmOX_52Y-oxyfUEXjZD_qNxg6VrU&uid=VVDHCVBYDKFMJRWA111A&channel=1&status=1 # 获取播放列表 http://localhost:8077/cloudstorage/queryvodlist?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySUQiOiIxNTY3NzU4MjE4NjE5MTM4MDAxMzgwMDAiLCJleHAiOjE1ODk1MjM0OTIsIm1fY29kZSI6IjEyMzQxMzI0MzIxNCIsImxhbmciOiJlbiIsInVzZXIiOiIxMzExOTY1NzcxMyJ9.e2NdhJtbXrDngZTSmOX_52Y-oxyfUEXjZD_qNxg6VrU&uid=VVDHCVBYDKFMJRWA111A&startTime=1&endTime=1954687458&channel=1 # 存储视频列表信息 http://test.dvema.com/cloudstorage/storeplaylist?uidToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJWVkRIQ1ZCWURLRk1KUldBMTExQSIsImNoYW5uZWwiOiIxIn0.eGwi5QKyrXi4WSKRbrUG7iFTChv_Utec2hSnqZkDKt8&time=1586940120&sec=20&fg=10 # 获取订单列表 http://localhost:8077/cloudstorage/queryorder?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySUQiOiIxNTY3NzU4MjE4NjE5MTM4MDAxMzgwMDAiLCJsYW5nIjoiZW4iLCJ1c2VyIjoiMTMxMTk2NTc3MTMiLCJtX2NvZGUiOiIxMjM0MTMyNDMyMTQiLCJleHAiOjE1ODk1OTIyNzh9.u211DHiMKg-pqhXv4b2yR__eNyOcSwBZCyPUGjsxFLU&page=1&line=10&uid=VVDHCVBYDKFMJRWA111A # commoditylist http://test.dvema.com/cloudstorage/commoditylist?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySUQiOiIxNTY3NzU4MjE4NjE5MTM4MDAxMzgwMDAiLCJleHAiOjE1ODk1MjM0OTIsIm1fY29kZSI6IjEyMzQxMzI0MzIxNCIsImxhbmciOiJlbiIsInVzZXIiOiIxMzExOTY1NzcxMyJ9.e2NdhJtbXrDngZTSmOX_52Y-oxyfUEXjZD_qNxg6VrU ''' # 设备信息添加 class CloudStorageView(View): def get(self, request, *args, **kwargs): request.encoding = 'utf-8' operation = kwargs.get('operation') return self.validation(request.GET, request, operation) def post(self, request, *args, **kwargs): request.encoding = 'utf-8' operation = kwargs.get('operation') return self.validation(request.POST, request, operation) def validation(self, request_dict, request, operation): response = ResponseObject() if operation is None: return response.json(444, 'error path') elif operation == 'testpaly.m3u8': return self.do_test_play_m3u8(request_dict, response) elif operation == 'dopaypalcallback': return self.do_pay_by_paypal_callback(request_dict, response) elif operation == 'doalicallback': return self.do_pay_by_ali_callback(request) elif operation == 'dowechatnotify': return self.do_pay_by_wechat_callback(request_dict,response) elif operation == 'getsignsts': ip = CommonService.get_ip_address(request) return self.do_get_sign_sts(request_dict, ip, response) # return self.do_get_sign_sts_test(request_dict, ip, response) elif operation == 'storeplaylist': return self.do_store_playlist(request_dict, response) elif operation == 'signplaym3u8': return self.do_sign_play_m3u8(request_dict, response) elif operation == 'payOK': return self.do_pay_ok(request_dict) else: token = request_dict.get('token', None) # 设备主键uid tko = TokenObject(token) response.lang = tko.lang if tko.code != 0: return response.json(tko.code) userID = tko.userID if operation == 'createpayorder': return self.do_create_pay_order(request_dict, userID, response) elif operation == 'changevodstatus': return self.do_change_vod_status(request_dict, userID, response) elif operation == 'queryvodlist': return self.do_query_vod_list(request_dict, userID, response) elif operation == 'commoditylist': return self.do_commodity_list(request_dict, userID, response) elif operation == 'queryorder': return self.do_query_order(request_dict, userID, response) elif operation == 'experienceorder': return self.do_experience_order(request_dict, userID, response) elif operation == 'experiencereset': return self.do_experience_reset(request_dict, userID, response) elif operation == 'deletevodlist': return self.deleteVodList(request_dict, response) elif operation == 'devicecommodity': return self.device_commodity(request_dict, response) elif operation == 'switchdevicecommodity': return self.switch_device_commodity(request_dict, response) else: return response.json(414) def do_test_play_m3u8(self, request_dict, response): playlist_entries = [ { 'name': 'https://azvod1.s3-ap-northeast-1.amazonaws.com/test/output000.ts', 'duration': 10, }, { 'name': 'https://azvod1.s3-ap-northeast-1.amazonaws.com/test/output000.ts', 'duration': 10, }, { 'name': 'https://azvod1.s3-ap-northeast-1.amazonaws.com/test/output000.ts', 'duration': 10, }, ] playlist = PlaylistGenerator(playlist_entries).generate() # return HttpResponse(playlist) # response = HttpResponse(playlist, content_type="application/octet-stream") response = HttpResponse(playlist, content_type="application/vnd.apple.mpegurl") return response def do_query_order(self, request_dict, userID, response): status = request_dict.get('status', None) page = int(request_dict.get('page', None)) line = int(request_dict.get('line', None)) uid = request_dict.get('uid', None) order_qs = Order_Model.objects.filter(userID_id=userID) if status: order_qs = order_qs.filter(status=status) # 筛选指定设备id的订单 if uid: order_qs = order_qs.filter(UID=uid) if not order_qs.exists(): return response.json(173) # return response.json(10, '订单不存在') count = order_qs.count() order_ql = order_qs[(page - 1) * line:page * line]. \ values("orderID", "UID", "channel", "desc", "price", "currency", "addTime", "updTime", "endTime", "pay_url", "payType", "status", "commodity_type", "commodity_code") order_list = list(order_ql) data = [] nowTime = int(time.time()) # 这里需要进行优化 uid_list = [] for od in order_list: uid_list.append(od['UID']) didqs = Device_Info.objects.filter(userID_id=userID, UID__in=uid_list). \ values('id', 'UID', 'Type') for d in order_list: if d['status'] == 0: if d['addTime'] + 3600 < nowTime: d['status'] = 3 for did in didqs: if d['UID'] == did['UID']: d['did'] = did['id'] d['Type'] = did['Type'] data.append(d) return response.json(0, {'data': data, 'count': count}) def do_commodity_list(self, request_dict, userID, response): mold = request_dict.get('mold', None) uid = request_dict.get('uid', None) qs = Store_Meal.objects eq = ExperienceContextModel.objects.filter(uid=uid,experience_type=0).values('id') # userqs = Device_User.objects.filter(userID=userID).values('is_experience') if mold: qs = qs.filter(bucket__mold=mold) else: qs = qs.all() if eq: qs=qs.filter(~Q(pay_type='10')) else: qs = qs.filter(pay_type='10') qs=qs.filter(~Q(pay_type='11')) #过滤不显示激活码套餐 qs = qs.values("id", "title", "content", "price","day", "currency", "bucket__storeDay", "bucket__bucket", "bucket__area","commodity_code", "commodity_type", "is_discounts", "virtual_price", "expire", "discount_price", "discount_content") if qs.exists(): ql = list(qs) from operator import itemgetter from itertools import groupby ql.sort(key=itemgetter('bucket__area')) res = [] for area, items in groupby(ql, key=itemgetter('bucket__area')): items_list = list(items) for key, val in enumerate(items_list): pay_types = Pay_Type.objects.filter(store_meal=items_list[key]['id']).values("id","payment") items_list[key]['pay_type'] = list(pay_types) res_c = {'area': area, 'items': items_list} res.append(res_c) result = { 'meals': res, 'extra': { 'cloud_banner': 'https://www.dvema.com/web/images/cloud_cn_banner.png', 'cloud_en_baner': 'https://www.dvema.com/web/images/cloud_en_banner.png' } } return response.json(0, result) else: return response.json(0) def do_sign_play_m3u8(self, request_dict, response): uid = request_dict.get('uid', None) channel = request_dict.get('channel', None) storeTime = request_dict.get('time', None) now_time = int(time.time()) vh_qs = VodHlsModel.objects.filter(uid=uid, channel=channel, time=storeTime, endTime__gte=now_time). \ values("sec", "fg", "bucket__bucket", "bucket__endpoint", "bucket__region", "bucket__mold") if not vh_qs.exists(): return response.json(11,'不存在.') sec = vh_qs[0]['sec'] fg = vh_qs[0]['fg'] bucket__region = vh_qs[0]['bucket__region'] bucket_name = vh_qs[0]['bucket__bucket'] print(bucket__region) print(bucket_name) aws_access_key_id = 'AKIA2E67UIMD45Y3HL53' aws_secret_access_key = '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' session = Session( aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, region_name=bucket__region ) ''' http://test.dvema.com/cloudstorage/signplaym3u8?uid=VVDHCVBYDKFMJRWA111A&channel=1&time=1586940120&sign=tktktktk ''' conn = session.client('s3') playlist_entries = [] # for i in range(fg): # thumbspng = '{uid}/vod{channel}/{time}/ts{i}.ts'. \ # format(uid=uid, channel=channel, time=storeTime, i=i) # response_url = conn.generate_presigned_url( # 'get_object', # Params={ # 'Bucket': bucket_name, # 'Key': thumbspng # }, # ExpiresIn=3600 # ) # # m3u8 = '{uid}/vod{channel}/{time}/{time}.m3u8'. \ # # format(uid=uid, channel=channel, time=vod['time']) # playlist_entries.append({ # 'name': response_url, # 'duration': sec, # }) for i in range(7): shift = (i+1)*4 duration = (fg >> shift) & 0xf if duration > 0: tsFile = '{uid}/vod{channel}/{time}/ts{i}.ts'. \ format(uid=uid, channel=channel, time=storeTime, i=i) response_url = conn.generate_presigned_url( 'get_object', Params={ 'Bucket': bucket_name, 'Key': tsFile }, ExpiresIn=3600 ) # m3u8 = '{uid}/vod{channel}/{time}/{time}.m3u8'. \ # format(uid=uid, channel=channel, time=vod['time']) playlist_entries.append({ 'name': response_url, 'duration': duration, }) playlist = PlaylistGenerator(playlist_entries).generate() response = HttpResponse(playlist) response['Content-Type'] = 'application/octet-stream' response['Content-Disposition'] = 'attachment;filename="play.m3u8"' return response # response = HttpResponse(playlist, content_type="application/vnd.apple.mpegurl") # response = HttpResponse(playlist, content_type="application/octet-stream") # return response def do_get_sign_sts(self, request_dict, ip, response): uidToken = request_dict.get('uidToken', None) utko = UidTokenObject(uidToken) if utko.flag is False: return response.json(444, 'uidToken') uid = utko.UID channel = utko.channel print(channel) print(uid) now_time = int(time.time()) ubqs = UID_Bucket.objects.filter(uid=uid, channel=channel, endTime__gte=now_time). \ values("bucket__mold", "bucket__bucket", "bucket__endpoint", "bucket__region", "endTime").order_by('endTime') print('-------------bucket') print(ubqs) if ubqs.exists(): if ubqs[0]["bucket__mold"] == 0: # 阿里云 oss sts oc_qs = OssCrdModel.objects.filter(uid=uid, channel=channel). \ values("addTime", "data") if oc_qs.exists(): endTime = int(oc_qs[0]["addTime"]) + 3500 if endTime > now_time: print(endTime) print(now_time) res = json.loads(oc_qs[0]["data"]) return JsonResponse(status=200, data=res) # 套餐id storage = '{uid}/vod{channel}/'.format(uid=uid, channel=channel) bucket_name = ubqs[0]['bucket__bucket'] endpoint = ubqs[0]['bucket__endpoint'] access_key_id = OSS_STS_ACCESS_KEY access_key_secret = OSS_STS_ACCESS_SECRET region_id = ubqs[0]['bucket__region'] role_arn = OSS_ROLE_ARN clt = client.AcsClient(access_key_id, access_key_secret, region_id) req = AssumeRoleRequest.AssumeRoleRequest() # 设置返回值格式为JSON。 req.set_accept_format('json') req.set_RoleArn(role_arn) req.set_RoleSessionName(uid + '_' + channel) req.set_DurationSeconds(3600) Resource_access = "acs:oss:*:*:{bucket_name}/{uid_channel}*". \ format(bucket_name=bucket_name, uid_channel=storage) print(Resource_access) policys = { "Version": "1", "Statement": [ { "Action": ["oss:PutObject", "oss:DeleteObject", ], "Resource": [Resource_access], "Effect": "Allow", "Condition": { "IpAddress": {"acs:SourceIp": ip} # "IpAddress": {"acs:SourceIp": "120.237.157.184"} # "IpAddress": {"acs:SourceIp": "*"} } } ] } req.set_Policy(Policy=json.dumps(policys)) body = clt.do_action(req) # 使用RAM账号的AccessKeyId和AccessKeySecret向STS申请临时token。 token = json.loads(body.decode('utf-8')) print(token) res = { 'AccessKeyId': token['Credentials']['AccessKeyId'], 'AccessKeySecret': token['Credentials']['AccessKeySecret'], 'SecurityToken': token['Credentials']['SecurityToken'], 'Expiration': token['Credentials']['Expiration'], 'expire': '3600', 'endpoint': endpoint, 'bucket_name': bucket_name, 'arn': token['AssumedRoleUser']['Arn'], 'code': 0, 'storage': storage, 'endTime': ubqs[0]['endTime'], 'ip': ip} if oc_qs.exists(): oc_qs.update(data=json.dumps(res), addTime=now_time) else: OssCrdModel.objects.create \ (uid=uid, channel=channel, data=json.dumps(res), addTime=now_time) return JsonResponse(status=200, data=res) elif ubqs[0]["bucket__mold"] == 1: # 亚马逊 s3 sts sts_qs = StsCrdModel.objects.filter(uid=uid, channel=channel). \ values("addTime", "data") if sts_qs.exists(): endTime = int(sts_qs[0]["addTime"]) + 3500 if endTime > now_time: print(endTime) print(now_time) res = json.loads(sts_qs[0]["data"]) return JsonResponse(status=200, data=res) # 套餐id storage = '{uid}/vod{channel}/'.format(uid=uid, channel=channel) bucket_name = ubqs[0]['bucket__bucket'] endpoint = ubqs[0]['bucket__endpoint'] region_id = ubqs[0]['bucket__region'] ############### REGION_NAME = region_id boto3_sts = boto3.client( 'sts', aws_access_key_id='AKIA2E67UIMD45Y3HL53', aws_secret_access_key='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', region_name=REGION_NAME ) print('--------2--test') print(REGION_NAME) Policy = { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "s3:*", "Resource": ["arn:aws:s3:::{bucket_name}/{uid_channel}*". format(bucket_name=bucket_name,uid_channel=storage)] } ] } print(Policy) response = boto3_sts.get_federation_token( Name='{role_name}'.format(role_name=uid + '_' + str(channel)), Policy=json.dumps(Policy), DurationSeconds=7200 ) ############### res = { 'AccessKeyId': response['Credentials']['AccessKeyId'], 'AccessKeySecret': response['Credentials']['SecretAccessKey'], 'SessionToken': response['Credentials']['SessionToken'], 'Expiration': response['Credentials']['Expiration'], 'expire': '3600', 'endpoint': endpoint, 'bucket_name': bucket_name, 'arn': response['FederatedUser']['Arn'], 'code': 0, 'storage': storage, 'endTime': ubqs[0]['endTime'], 'ip': ip, } if sts_qs.exists(): sts_qs.update(data=json.dumps(res,default=str), addTime=now_time) else: StsCrdModel.objects.create(uid=uid, channel=channel, data=json.dumps(res, default=str), addTime=now_time, type=1) return JsonResponse(status=200, data=res) else: res = {'code': 404, 'msg': 'data not exists!'} return HttpResponse(json.dumps(res, ensure_ascii=False),content_type="application/json,charset=utf-8") res = {'code': 405, 'msg': 'Not purchased or expired!'} return HttpResponse(json.dumps(res, ensure_ascii=False),content_type="application/json,charset=utf-8") def do_query_vod_list(self, request_dict, userID, response): startTime = int(request_dict.get('startTime', None)) endTime = int(request_dict.get('endTime', None)) uid = request_dict.get('uid', None) channel = request_dict.get('channel', None) dv_qs = Device_Info.objects.filter(UID=uid, userID_id=userID, isShare=False) if not dv_qs.exists(): return response.json(12) now_time = int(time.time()) bv_qs = UID_Bucket.objects.filter(uid=uid,channel=channel, endTime__gte=now_time).order_by('endTime') if not bv_qs.exists(): return response.json(10008) vh_qs = VodHlsModel.objects.filter \ ( uid=uid, channel=channel, time__range=(startTime, endTime), endTime__gte=now_time). \ values("id", "time", "sec", "bucket__bucket", "fg", "bucket__endpoint", "bucket__region", "bucket__mold") vod_play_list = [] print(int(time.time())) for vod in vh_qs: bucket__mold = vod["bucket__mold"] bucket_name = vod["bucket__bucket"] endpoint = vod["bucket__endpoint"] bucket__region = vod["bucket__region"] if bucket__mold == 0: auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET) bucket = oss2.Bucket(auth, endpoint, bucket_name) m3u8 = '{uid}/vod{channel}/{time}/{time}.m3u8'. \ format(uid=uid, channel=channel, time=vod['time']) ts = '{uid}/vod{channel}/{time}/ts0.ts'. \ format(uid=uid, channel=channel, time=vod['time']) url = bucket.sign_url('GET', m3u8, 3600, params={'x-oss-process': 'hls/sign'}) urllst = url.split('?') url_start = urllib.parse.unquote(urllst[0]) url_end = urllst[1] vod_play_url = '{url_start}?{url_end}'. \ format(url_start=url_start, url_end=url_end) thumb = bucket.sign_url('GET', ts, 3600, params={'x-oss-process': 'video/snapshot,t_10000,m_fast,w_300'}) vod_play_list.append({'name': vod['time'], 'sign_url': vod_play_url, 'thumb': thumb, 'sec': vod['sec'], 'vod_id': vod['id']}) elif bucket__mold == 1: # aws_access_key_id = 'AKIA2E67UIMD45Y3HL53' # aws_secret_access_key = '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' # session = Session( # aws_access_key_id=aws_access_key_id, # aws_secret_access_key=aws_secret_access_key, # region_name=bucket__region # ) # conn = session.client('s3') # thumbspng = '{uid}/vod{channel}/{time}/Thumb.jpeg'. \ # format(uid=uid, channel=channel, time=vod['time']) # response_url = conn.generate_presigned_url( # 'get_object', # Params={ # 'Bucket': bucket_name, # 'Key': thumbspng # }, # ExpiresIn=3600 # ) # thumb_url = response_url # format(uid=uid, channel=channel, time=vod['time']) vod_url = '{server_domain}/cloudstorage/signplaym3u8?' \ 'uid={uid}&channel={channel}&time={time}&sign=tktktktk'. \ format(server_domain=SERVER_DOMAIN,uid=uid, channel=channel, time=vod['time']) ts_num = vod['fg'] & 0xf vod_play_list.append({ 'name': vod['time'], 'sign_url': vod_url, # 'thumb': thumb_url, 'sec': vod['sec'], 'ts_num' : ts_num, 'vod_id': vod['id'] }), return response.json(0, vod_play_list) def do_store_playlist(self, request_dict, response): uidToken = request_dict.get('uidToken', None) storeTime = request_dict.get('time', None) sec = request_dict.get('sec', None) fg = request_dict.get('fg', None) utko = UidTokenObject(uidToken) if utko.flag is False: return response.json(444, 'uidToken') if not uidToken or not storeTime or not sec: return response.json(0) pass UID = utko.UID channel = utko.channel print('UID:') print(UID) print('channel:') print(channel) now_time = int(time.time()) ubqs = UID_Bucket.objects.filter(uid=UID, channel=channel, is_use=1, endTime__gte=now_time). \ values("bucket__mold", "bucket__bucket", "bucket__endpoint", "bucket__region", "status", "bucket__storeDay", "bucket__id").order_by('endTime') if ubqs.exists(): ub_qs_data = ubqs[0] store_day = ub_qs_data['bucket__storeDay'] bucket_id = ub_qs_data['bucket__id'] end_time = int(storeTime) + store_day * 86400 if ub_qs_data['status'] == 1: if ub_qs_data["bucket__mold"] == 0: oss_crd_qs = OssCrdModel.objects.filter(uid=UID, channel=channel) if oss_crd_qs.exists(): VodHlsModel.objects.create( uid=UID, channel=channel, time=storeTime, endTime=end_time, bucket_id=bucket_id, sec=sec, ) res = {'code': 0, 'msg': '存储成功'} return HttpResponse(json.dumps(res, ensure_ascii=False), content_type="application/json,charset=utf-8") else: res = {'code': 404, 'msg': '设备未购买'} return HttpResponse(json.dumps(res, ensure_ascii=False), content_type="application/json,charset=utf-8") elif ub_qs_data['bucket__mold'] == 1: sts_qs = StsCrdModel.objects.filter(uid=UID, channel=channel, type=1). \ values("addTime", "data") if sts_qs.exists(): VodHlsModel.objects.create( uid=UID, channel=channel, time=storeTime, endTime=end_time, bucket_id=bucket_id, fg=fg, sec=sec, ) res = {'code': 0, 'msg': '存储成功'} return HttpResponse(json.dumps(res, ensure_ascii=False), content_type="application/json,charset=utf-8") else: res = {'code': 404, 'msg': '设备未购买'} return HttpResponse(json.dumps(res, ensure_ascii=False), content_type="application/json,charset=utf-8") else: res = {'code': 404, 'msg': '设备未开启'} return HttpResponse(json.dumps(res, ensure_ascii=False), content_type="application/json,charset=utf-8") else: res = {'code': 404, 'msg': '设备未购买'} return HttpResponse(json.dumps(res, ensure_ascii=False), content_type="application/json,charset=utf-8") # def do_change_vod_status(self, request_dict, userID, response): # uid = request_dict.get('uid', None) # status = request_dict.get('status', None) # channel = request_dict.get('channel', None) # if all([uid, status, channel]): # dv_qs = Device_Info.objects.filter(UID=uid, userID_id=userID, isShare=False, isExist=1) # if dv_qs.exists(): # now_time = int(time.time()) # ub_qs = UID_Bucket.objects.filter(uid=uid, channel=channel, endTime__gte=now_time) # if ub_qs.exists(): # ub_qs.status = status # ub_qs.save() # if status == 0: # return response.json(0) # else: # utko = UidTokenObject() # utko.generate(data={'uid': uid, 'channel': channel}) # uidTK = utko.token # uidTkUrl = "{SERVER_DOMAIN}cloudstorage/getsignsts?uidToken={uidToken}". \ # format(uidToken=uidTK, SERVER_DOMAIN=SERVER_DOMAIN) # storeHlsUrl = "{SERVER_DOMAIN}cloudstorage/storeplaylist?uidToken={uidToken}". \ # format(uidToken=uidTK, SERVER_DOMAIN=SERVER_DOMAIN) # return response.json(0, {'uidTkUrl': uidTkUrl, 'storeHlsUrl': storeHlsUrl}) # else: # return response.json(10, '未购买') # else: # return response.json(12) # else: # return response.json(444, 'uid,status,channel') def do_change_vod_status(self, request_dict, userID, response): uid = request_dict.get('uid', None) status = request_dict.get('status', None) channel = request_dict.get('channel', None) if not uid or not status or not channel: return response.json(444, 'uid,status,channel') dvqs = Device_Info.objects.filter(UID=uid, userID_id=userID, isShare=False) if not dvqs.exists(): return response.json(12) ubqs = UID_Bucket.objects.filter(channel=channel, uid=uid).order_by('endTime') print(ubqs) exit() if not ubqs.exists(): return response.json(10, '未购买') now_time = int(time.time()) if now_time > ubqs[0].endTime: return response.json(10008) ubqs.update(status=status) if status == 0: return response.json(0) utko = UidTokenObject() utko.generate(data={'uid': uid, 'channel': channel}) uidTkUrl = "{SERVER_DOMAIN}cloudstorage/getsignsts?uidToken={uidToken}". \ format(uidToken=utko.token, SERVER_DOMAIN=SERVER_DOMAIN) storeHlsUrl = "{SERVER_DOMAIN}cloudstorage/storeplaylist?uidToken={uidToken}". \ format(uidToken=utko.token, SERVER_DOMAIN=SERVER_DOMAIN) return response.json(0, {'uidTkUrl': uidTkUrl, 'storeHlsUrl': storeHlsUrl}) def do_pay_error(self): response = HttpResponse() response.content = '''
Payment failure
'''+showtitle+'''