chenjunkai 6 years ago
parent
commit
5b6f99e5fd
3 changed files with 215 additions and 79 deletions
  1. 184 16
      Controller/CloudVod.py
  2. 29 62
      Controller/EquipmentManager.py
  3. 2 1
      Controller/VodBucket.py

+ 184 - 16
Controller/CloudVod.py

@@ -92,7 +92,7 @@ class CloudVodView(View):
         elif operation == 'payOK':
             return self.do_pay_ok()
         elif operation == 'payError':
-            return self.do_pay_ok()
+            return self.do_pay_error()
         else:
             token = request_dict.get('token', None)
             # 设备主键uid
@@ -113,24 +113,188 @@ class CloudVodView(View):
             else:
                 return response.json(414)
 
-    def do_pay_ok(self):
+    def do_pay_error(self):
         response = HttpResponse()
         response.status_code = 200
+        # response.content = '''
+        #                        <!DOCTYPE html>
+        #                <html lang="en">
+        #                <head>
+        #                    <meta charset="UTF-8">
+        #                    <title>Title</title>
+        #                </head>
+        #                <body>
+        #                <div class="content"
+        #                     style="text-align:center;overflow: hidden;padding:20% 10% 10% 10%;margin:0 10%;background-color: #fff;box-shadow:0 4px 20px rgba(0,0,0,0.1);word-break: break-all;min-height: 300px">
+        #                    <span style="padding: 10px 20px; font-size: 48px;background-color: #EB6F5A;border-radius:4px;color:#fff;">付款失败</span>
+        #                </div>
+        #                </body>
+        #                </html>
+        #                        '''
+        response.content = '''
+        <!DOCTYPE html>
+<html>
+<head>
+    <title>拦截跳转实现通信</title>
+    <meta charset="UTF-8">
+    <meta name="viewport"
+          content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
+    <script type="text/javascript" src="https://cdn.staticfile.org/jquery/1.12.4/jquery.js"></script>
+
+    <style type="text/css">
+        .btn {
+            background-color: #aaa;
+            height: 40px;
+            display: flex;
+            justify-content: center;
+            align-items: center;
+            color: #444444;
+            text-decoration: none;
+            margin-top: 10px;
+        }
+
+        #response {
+            background: #eeeeee;
+            word-wrap: break-word;
+            display: block;
+            outline: 1px solid #ccc;
+            padding: 5px;
+            margin: 5px;
+        }
+    </style>
+</head>
+<body>
+<p style="color: red">嵌入页区域</p>
+<p>以拦截跳转链接的方式实现</p>
+<input type="text" id="loginInputID">
+<button class="btn" id="login">发起APP登录</button>
+<input type="text" id="shareInputID">
+<button class="btn" id="share">发起社交化分享</button>
+
+<pre id="response"></pre>
+<script>
+
+    /**
+     * 显示响应信息
+     * @param response 响应信心
+     */
+    function showResponse(response) {
+        $('#response').text(response);
+        return response;
+    }
+
+    $(function () {
+        $('#login').click(function () {
+            let loginInputVal = $('#loginInputID').val()
+            alert(loginInputVal)
+            window.location = loginInputVal;
+            //window.location = 'app://login?account=13011112222&password=123456';
+        });
+
+        $('#share').click(function () {
+            let shareInputVal = $('#shareInputID').val()
+            alert(shareInputVal)
+            window.location = shareInputVal
+            //window.location = 'app://share?title=分享的标题&desc=分享的描述'
+        });
+    });
+</script>
+</body>
+</html>
+
+        '''
+        return response
+
+    def do_pay_ok(self):
+        response = HttpResponse()
+        # response.status_code = 200
+        # response.content = '''
+        #                 <!DOCTYPE html>
+        #         <html lang="en">
+        #         <head>
+        #             <meta charset="UTF-8">
+        #             <title>Title</title>
+        #         </head>
+        #         <body>
+        #         <div class="content"
+        #              style="text-align:center;overflow: hidden;padding:20% 10% 10% 10%;margin:0 10%;background-color: #fff;box-shadow:0 4px 20px rgba(0,0,0,0.1);word-break: break-all;min-height: 300px">
+        #             <span style="padding: 10px 20px; font-size: 48px;background-color: #EB6F5A;border-radius:4px;color:#fff;">付款成功</span>
+        #         </div>
+        #         </body>
+        #         </html>
+        #                 '''
         response.content = '''
-                        <!DOCTYPE html>
-                <html lang="en">
-                <head>
-                    <meta charset="UTF-8">
-                    <title>Title</title>
-                </head>
-                <body>
-                <div class="content"
-                     style="text-align:center;overflow: hidden;padding:20% 10% 10% 10%;margin:0 10%;background-color: #fff;box-shadow:0 4px 20px rgba(0,0,0,0.1);word-break: break-all;min-height: 300px">
-                    <span style="padding: 10px 20px; font-size: 48px;background-color: #EB6F5A;border-radius:4px;color:#fff;">付款成功</span>
-                </div>
-                </body>
-                </html>
-                        '''
+                <!DOCTYPE html>
+        <html>
+        <head>
+            <title>拦截跳转实现通信</title>
+            <meta charset="UTF-8">
+            <meta name="viewport"
+                  content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
+            <script type="text/javascript" src="https://cdn.staticfile.org/jquery/1.12.4/jquery.js"></script>
+
+            <style type="text/css">
+                .btn {
+                    background-color: #aaa;
+                    height: 40px;
+                    display: flex;
+                    justify-content: center;
+                    align-items: center;
+                    color: #444444;
+                    text-decoration: none;
+                    margin-top: 10px;
+                }
+
+                #response {
+                    background: #eeeeee;
+                    word-wrap: break-word;
+                    display: block;
+                    outline: 1px solid #ccc;
+                    padding: 5px;
+                    margin: 5px;
+                }
+            </style>
+        </head>
+        <body>
+        <p style="color: red">嵌入页区域</p>
+        <p>以拦截跳转链接的方式实现</p>
+        <input type="text" id="loginInputID">
+        <button class="btn" id="login">发起APP登录</button>
+        <input type="text" id="shareInputID">
+        <button class="btn" id="share">发起社交化分享</button>
+
+        <pre id="response"></pre>
+        <script>
+
+            /**
+             * 显示响应信息
+             * @param response 响应信心
+             */
+            function showResponse(response) {
+                $('#response').text(response);
+                return response;
+            }
+
+            $(function () {
+                $('#login').click(function () {
+                    let loginInputVal = $('#loginInputID').val()
+                    alert(loginInputVal)
+                    window.location = loginInputVal;
+                    //window.location = 'app://login?account=13011112222&password=123456';
+                });
+
+                $('#share').click(function () {
+                    let shareInputVal = $('#shareInputID').val()
+                    alert(shareInputVal)
+                    window.location = shareInputVal
+                    //window.location = 'app://share?title=分享的标题&desc=分享的描述'
+                });
+            });
+        </script>
+        </body>
+        </html>
+
+                '''
         return response
 
     # next
@@ -343,6 +507,8 @@ class CloudVodView(View):
         PayerID = request_dict.get('PayerID', None)
         orderID = request_dict.get('orderID', None)
         if not paymentId or not PayerID or not orderID:
+            red_url = "{SERVER_DOMAIN}cloudVod/payError".format(SERVER_DOMAIN=SERVER_DOMAIN)
+            return HttpResponseRedirect(red_url)
             return response.json(444, 'paymentId,PayerID,orderID')
         paypalrestsdk.configure({
             "mode": "sandbox",  # sandbox or live
@@ -354,6 +520,8 @@ class CloudVodView(View):
         payres = payment.execute({"payer_id": PayerID})
         print(payres)
         if not payres:
+            red_url = "{SERVER_DOMAIN}cloudVod/payError".format(SERVER_DOMAIN=SERVER_DOMAIN)
+            return HttpResponseRedirect(red_url)
             print(payment.error)  # Error Hash
             return response.json(10, payment.error)
         print("Payment execute successfully")

+ 29 - 62
Controller/EquipmentManager.py

@@ -95,34 +95,6 @@ def delUserEquipment(userID, id, response):
                 return response.json(113)
 
 
-def modifyUserEquipment(userID, deviceContent, id, response):
-    try:
-        deviceValid = Device_Info.objects.filter(userID_id=userID, id=id)
-    except Exception as e:
-        errorInfo = traceback.format_exc()
-        print('查询数据库错误: %s' % errorInfo)
-        return response.json(500, repr(e))
-    else:
-        if deviceValid:
-            deviceData = json.loads(deviceContent)
-            try:
-                Device_Info.objects.filter(userID_id=userID, id=id).update(**deviceData)
-            except Exception as e:
-                errorInfo = traceback.format_exc()
-                print('修改设备信息错误: %s ' % errorInfo)
-                return response.json(177, repr(e))
-            else:
-                qs = Device_Info.objects.filter(userID_id=userID, id=id)
-                res = CommonService.qs_to_dict(qs)
-                return response.json(0, res)
-        else:
-            UserValid = Device_User.objects.filter(userID=userID)
-            if UserValid.exists():
-                return response.json(172)
-            else:
-                return response.json(113)
-
-
 def showAllUserEquipment(userID, response):
     try:
         userValid = Device_User.objects.filter(userID=userID).order_by('-data_joined')
@@ -214,30 +186,8 @@ def queryUserEquipmentInterface(request, *callback_args,
     if tko.code != 0:
         return response.json(tko.code)
     userID = tko.userID
-    # if userID is not None:
-    #     deviceValid = Device_Info.objects.filter(userID_id=userID)
-    #     # print(deviceValid)
-    #     res = CommonService.qs_to_dict(deviceValid)
-    #     datas = res['datas']
-    #     uid_list = []
-    #     for q in datas:
-    #         uid_list.append(q['fields']['UID'])
-    #     dmqs = Device_Meal.objects.filter(uid__in=uid_list).\
-    #         values('rank', 'status', 'channel', 'end_time', 'rank__title','uid')
-    #     dmlt = CommonService.qs_to_list(dmqs)
-    #     # print(uid_list)
-    #     res = []
-    #     for p in datas:
-    #         p['fields']['vod'] = []
-    #         for dm in dmlt:
-    #             if p['fields']['UID'] == dm['uid']:
-    #                 p['fields']['vod'].append(dm)
-    #         res.append(p)
-    #     print(res)
-    #     return response.json(0, {'datas':res})
     if userID is not None:
         deviceValid = Device_Info.objects.filter(userID_id=userID)
-        # print(deviceValid)
         res = CommonService.qs_to_dict(deviceValid)
         datas = res['datas']
         uid_list = []
@@ -347,20 +297,37 @@ def modifyUserEquipmentInterface(request, *callback_args,
     token = request_dict.get('token', None)
     deviceContent = request_dict.get('content', None)
     id = request_dict.get('id', None)
-    if token is not None and deviceContent is not None and id is not None:
-        tko = TokenObject(token)
-        tko.valid()
-        response.lang = tko.lang
-        if tko.code == 0:
-            userID = tko.userID
-            if userID is not None:
-                return modifyUserEquipment(userID, deviceContent, id, response)
+    if not deviceContent or not id:
+        return response.json(444, 'content,id')
+    tko = TokenObject(token)
+    tko.valid()
+    response.lang = tko.lang
+    if tko.code != 0:
+        return response.json(tko.code)
+    userID = tko.userID
+    if userID is None:
+        return response.json(309)
+    try:
+        deviceValid = Device_Info.objects.filter(userID_id=userID, id=id)
+    except Exception as e:
+        return response.json(500, repr(e))
+    else:
+        if deviceValid.exists():
+            deviceData = json.loads(deviceContent)
+            try:
+                Device_Info.objects.filter(userID_id=userID, id=id).update(**deviceData)
+            except Exception as e:
+                return response.json(177, repr(e))
             else:
-                return response.json(309)
+                qs = Device_Info.objects.filter(userID_id=userID, id=id)
+                res = CommonService.qs_to_dict(qs)
+                return response.json(0, res)
         else:
-            return response.json(tko.code)
-    else:
-        return response.json(444, 'token,content,id')
+            UserValid = Device_User.objects.filter(userID=userID)
+            if UserValid.exists():
+                return response.json(172)
+            else:
+                return response.json(113)
 
 
 @csrf_exempt

+ 2 - 1
Controller/VodBucket.py

@@ -187,7 +187,8 @@ class UidBucketView(View):
                 UID_Bucket.objects.create(uid=uid, channel=channel, bucket_id=bucketId, endTime=endTime)
         except Exception as e:
             return response.json(10, repr(e))
-        return response.json(0, {'endTime': endTime})
+        else:
+            return response.json(0, {'endTime': endTime})
 
     def do_query(self, request_dict, response):
         page = int(request_dict.get('page', None))