瀏覽代碼

Merge branch 'pzb' of http://192.168.136.45:3000/SERVER/AnsjerServer into pzb

pzb 6 年之前
父節點
當前提交
670c454c29

+ 13 - 0
Ansjer/mqtt/__init__.py

@@ -0,0 +1,13 @@
+#!/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: 2019/3/7 9:53
+@Version: python3.6
+@MODIFY DECORD:ansjer dev
+@file: __init__.py.py
+@Contact: chanjunkai@163.com
+"""

+ 58 - 0
Ansjer/mqtt/gcmm.py

@@ -0,0 +1,58 @@
+#!/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: 2019/3/7 10:50
+@Version: python3.6
+@MODIFY DECORD:ansjer dev
+@file: gcmm.py
+@Contact: chanjunkai@163.com
+"""
+import json
+import requests
+
+data = {
+    "key1": "abc",
+    "key2": "def"
+}
+
+json_data = {
+    "collapse_key": "WhatYouWant",
+    "data": data,
+    "delay_while_idle": False,
+    "time_to_live": 3600,
+    "registration_ids": ['eSooD4fAARg:APA91bEPenBPnSn5aXIQk56QdLOQ1Mu3hevHsekP_0eDpg458y2ZMBP6By2rVsGYIoxZrXxvkkptPKUE9CmUygBxaZXABddUWB9FyLlznRFerC7RG9X5PsEOH58xK9_aTUdkT7p6Ocld']
+}
+
+url = 'https://android.googleapis.com/gcm/send'
+serverKey = "AAAAb9YP3rk:APA91bHu8u-CTpcd0g6lKPo0WNVqCi8jZub1cPPbSAY9AucT1HxlF65ZDUko9iG8q2ch17bwu9YWHpK1xI1gHSRXCslLvZlXEmHZC0AG3JKg15XuUvlFKACIajUFV-pOeGRT8tM6-31I"
+
+data = json.dumps(json_data).encode('utf-8')
+headers = {'Content-Type': 'application/json', 'Authorization': 'key=%s' % serverKey}
+req = requests.post(url, data, headers=headers)
+print(req.text)
+exit()
+#################################################
+from gcm import GCM
+
+API_KEY = 'AAAAb9YP3rk:APA91bHu8u-CTpcd0g6lKPo0WNVqCi8jZub1cPPbSAY9AucT1HxlF65ZDUko9iG8q2ch17bwu9YWHpK1xI1gHSRXCslLvZlXEmHZC0AG3JKg15XuUvlFKACIajUFV-pOeGRT8tM6-31I'
+gcm = GCM(API_KEY)
+data = {'param1': 'value1', 'param2': 'value2'}
+
+# Downstream message using JSON request
+reg_ids = ['eSooD4fAARg:APA91bEPenBPnSn5aXIQk56QdLOQ1Mu3hevHsekP_0eDpg458y2ZMBP6By2rVsGYIoxZrXxvkkptPKUE9CmUygBxaZXABddUWB9FyLlznRFerC7RG9X5PsEOH58xK9_aTUdkT7p6Ocld']
+response = gcm.json_request(registration_ids=reg_ids, data=data)
+
+# Downstream message using JSON request with extra arguments
+res = gcm.json_request(
+    registration_ids=reg_ids, data=data,
+    collapse_key='uptoyou', delay_while_idle=True, time_to_live=3600
+)
+
+# Topic Messaging
+topic = 'topic name'
+res = gcm.send_topic_message(topic=topic, data=data)
+print(res)

+ 29 - 0
Ansjer/mqtt/mqtt_client.py

@@ -0,0 +1,29 @@
+#!/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: 2019/3/7 9:43
+@Version: python3.6
+@MODIFY DECORD:ansjer dev
+@file: mqtt_client.py
+@Contact: chanjunkai@163.com
+"""
+import paho.mqtt.client as mqtt
+
+HOST = "192.168.136.45"
+PORT = 1883
+
+
+def test():
+    client = mqtt.Client()
+    client.connect(HOST, PORT, 60)
+    client.publish("chat", "hello chenfulin11111", 2)
+    # client.loop()
+    client.loop_forever()
+
+
+if __name__ == '__main__':
+    test()

+ 30 - 0
Ansjer/mqtt/mqtt_server.py

@@ -0,0 +1,30 @@
+#!/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: 2019/3/7 9:42
+@Version: python3.6
+@MODIFY DECORD:ansjer dev
+@file: mqtt_server.py
+@Contact: chanjunkai@163.com
+"""
+import paho.mqtt.client as mqtt
+
+
+def on_connect(client, userdata, flags, rc):
+    print("Connected with result code " + str(rc))
+    client.subscribe("chat")
+
+
+def on_message(client, userdata, msg):
+    print(msg.topic + " " + ":" + str(msg.payload))
+
+
+client = mqtt.Client()
+client.on_connect = on_connect
+client.on_message = on_message
+client.connect("192.168.136.45", 1883, 60)
+client.loop_forever()

+ 3 - 0
Ansjer/test/.cache/v/cache/lastfailed

@@ -0,0 +1,3 @@
+{
+  "mqtt_client.py::test": true
+}

+ 13 - 0
Ansjer/test/util/__init__.py

@@ -0,0 +1,13 @@
+#!/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: 2019/3/7 9:53
+@Version: python3.6
+@MODIFY DECORD:ansjer dev
+@file: __init__.py.py
+@Contact: chanjunkai@163.com
+"""

二進制
Ansjer/test/util/__pycache__/spnsss.cpython-36.pyc


+ 13 - 0
Ansjer/test/util/jpush.py

@@ -0,0 +1,13 @@
+#!/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: 2019/3/6 17:43
+@Version: python3.6
+@MODIFY DECORD:ansjer dev
+@file: jpush.py
+@Contact: chanjunkai@163.com
+"""

+ 37 - 43
Controller/AppInfo.py

@@ -95,46 +95,40 @@ class AppInfo(View):
             data=[appBundleId, appName, systemLanguage, newAppversion, content, app_type, bundleVersion])
         if param_flag is not True:
             return response.json(444)
-
-        try:
-            has_app_info = App_Info.objects.filter(appBundleId=appBundleId)
-        except Exception:
-            errorInfo = traceback.format_exc()
-            print(errorInfo)
-            return response.json(424, {'details': errorInfo})
+        has_app_info = App_Info.objects.filter(appBundleId=appBundleId)
+        if has_app_info.exists():
+            return response.json(174)
         else:
-            if has_app_info.exists():
-                return response.json(174)
+            try:
+                app_Info = App_Info(
+                    appBundleId=appBundleId,
+                    appName=appName,
+                    newAppversion=newAppversion,
+                    systemLanguage=systemLanguage,
+                    content=content,
+                    app_type=app_type,
+                    bundleVersion=bundleVersion,
+                    downloadLink=downloadLink)
+                app_Info.save()
+            except Exception:
+                errorInfo = traceback.format_exc()
+                print(errorInfo)
+                return response.json(500, {'details': errorInfo})
             else:
-                try:
-                    app_Info = App_Info(
-                        appBundleId=appBundleId,
-                        appName=appName,
-                        newAppversion=newAppversion,
-                        systemLanguage=systemLanguage,
-                        content=content,
-                        app_type=app_type,
-                        bundleVersion=bundleVersion,
-                        downloadLink=downloadLink)
-                    app_Info.save()
-                except Exception:
-                    errorInfo = traceback.format_exc()
-                    print(errorInfo)
-                    return response.json(500, {'details': errorInfo})
+                if app_Info.id:
+                    res = {'appBundleId': app_Info.appBundleId,
+                           'appName': app_Info.appName,
+                           'newAppversion': app_Info.newAppversion,
+                           'systemLanguage': app_Info.systemLanguage,
+                           'content': app_Info.content,
+                           'app_type': app_Info.app_type,
+                           'id': app_Info.id,
+                           'downloadLink': downloadLink,
+                           'bundleVersion': app_Info.bundleVersion}
+                    return response.json(0, res)
                 else:
-                    if app_Info.id:
-                        res = {'appBundleId': app_Info.appBundleId,
-                               'appName': app_Info.appName,
-                               'newAppversion': app_Info.newAppversion,
-                               'systemLanguage': app_Info.systemLanguage,
-                               'content': app_Info.content,
-                               'app_type': app_Info.app_type,
-                               'id': app_Info.id,
-                               'downloadLink': downloadLink,
-                               'bundleVersion': app_Info.bundleVersion}
-                        return response.json(0, res)
-                    else:
-                        return response.json(500)
+                    return response.json(500)
+
 
     def query(self, request_dict, userID, response):
         own_perm = ModelService.check_perm(userID=userID, permID=30)
@@ -166,13 +160,10 @@ class AppInfo(View):
         app_type = request_dict.get('app_type', None)
         bundleVersion = request_dict.get('bundleVersion', None)
         downloadLink = request_dict.get('downloadLink', None)
-        param_flag = CommonService.get_param_flag(
-            data=[appBundleId, appName, systemLanguage, newAppversion, content, app_type, bundleVersion,
-                  downloadLink])
-        if param_flag is not True:
+        if not all([appBundleId, appName, systemLanguage, newAppversion, content, app_type, bundleVersion, downloadLink]):
             return response.json(444)
-        app_info = App_Info.objects.get(id=id)
-        if app_info.id:
+        try:
+            app_info = App_Info.objects.get(id=id)
             app_info.appBundleId = appBundleId
             app_info.appName = appName
             app_info.systemLanguage = systemLanguage
@@ -182,6 +173,9 @@ class AppInfo(View):
             app_info.bundleVersion = bundleVersion
             app_info.downloadLink = downloadLink
             app_info.save()
+        except Exception as e:
+            return response.json(404,repr(e))
+        else:
             return response.json(0, {'update_id': app_info.id, 'update_time': str(app_info.update_time)})
 
     def delete(self, request_dict, userID, response):

+ 49 - 25
Controller/Test.py

@@ -22,37 +22,61 @@ import json
 from alipay import AliPay
 import time
 
+
 # 测试接口sdk
 class Test(View):
 
     def get(self, request, *args, **kwargs):
+        import json
+        import requests
+
+        data = {
+            "key1": "abc",
+            "key2": "def"
+        }
+
+        json_data = {
+            "collapse_key": "WhatYouWant",
+            "data": data,
+            "delay_while_idle": False,
+            "time_to_live": 3600,
+            "registration_ids": [
+                'eSooD4fAARg:APA91bEPenBPnSn5aXIQk56QdLOQ1Mu3hevHsekP_0eDpg458y2ZMBP6By2rVsGYIoxZrXxvkkptPKUE9CmUygBxaZXABddUWB9FyLlznRFerC7RG9X5PsEOH58xK9_aTUdkT7p6Ocld']
+        }
+
+        url = 'https://android.googleapis.com/gcm/send'
+        serverKey = "AAAAb9YP3rk:APA91bHu8u-CTpcd0g6lKPo0WNVqCi8jZub1cPPbSAY9AucT1HxlF65ZDUko9iG8q2ch17bwu9YWHpK1xI1gHSRXCslLvZlXEmHZC0AG3JKg15XuUvlFKACIajUFV-pOeGRT8tM6-31I"
+
+        data = json.dumps(json_data).encode('utf-8')
+        headers = {'Content-Type': 'application/json', 'Authorization': 'key=%s' % serverKey}
+        req = requests.post(url, data, headers=headers)
         response = ResponseObject()
 
-        app_private_key_string = open(BASE_DIR + '/Controller/alipay_private_2048.pem').read()
-        alipay_public_key_string = open(BASE_DIR + '/Controller/alipay_public_2048.pem').read()
-        orderID = int(time.time()) + int(time.time())
-        alipay = AliPay(
-            appid="2016092200569234",
-            app_notify_url=None,  # the default notify path
-            app_private_key_string=app_private_key_string,
-            # alipay public key, do not use your own public key!
-            alipay_public_key_string=alipay_public_key_string,
-            sign_type="RSA2",  # RSA or RSA2
-            debug=False  # False by default
-        )
-        order_string = alipay.api_alipay_trade_wap_pay(
-            out_trade_no=str(orderID),
-            total_amount=0.01,
-            subject="实用性充气式玩具",
-            return_url="http://192.168.136.40:8077/",
-            notify_url="http://test.dvema.com:8077/Test"  # this is optional
-        )
-        print(order_string)
-        from django.http import HttpResponseRedirect
-        # return response.json(0,"https://openapi.alipay.com/gateway.do? + {order_string}".format(order_string=order_string))
-        print(order_string)
-        return HttpResponseRedirect("https://openapi.alipaydev.com/gateway.do?" + order_string)
-        return HttpResponseRedirect("https://openapi.alipay.com/gateway.do?" + order_string)
+        return response.json(0)
+
+    def jgPush(self, request):
+        response = ResponseObject()
+        devToken = request.GET.get('devToken', '')
+        app_key = request.GET.get('app_key', '')
+        master_secret = request.GET.get('master_secret', '')
+        import jpush as jpush
+
+        # 此处换成各自的app_key和master_secret
+        _jpush = jpush.JPush(app_key, master_secret)
+        push = _jpush.create_push()
+        # if you set the logging level to "DEBUG",it will show the debug logging.
+        _jpush.set_logging("DEBUG")
+        # push.audience = jpush.all_
+        push.audience = jpush.registration_id(devToken)
+
+        push.notification = jpush.notification(alert="hello python jpush api")
+        push.platform = jpush.all_
+        try:
+            res = push.send()
+        except Exception as e:
+            print("Exception")
+            return response.json(10, repr(e))
+        return response.json(0)
 
     def post(self, request, *args, **kwargs):
         response = ResponseObject()

+ 1 - 0
Object/AWS/SesClassObject.py

@@ -11,6 +11,7 @@ from email.mime.base import MIMEBase
 from email.mime.application import MIMEApplication
 from email.header import Header
 
+
 class SesClassObject:
    def __init__(self, *args, **kwargs):
         self.access_id = AWS_SES_ACCESS_ID

+ 2 - 1
requirements.txt

@@ -19,4 +19,5 @@ xmltodict
 var_dump
 django-middleware-global-request
 oss2
-aliyun-python-sdk-sts
+aliyun-python-sdk-sts
+jpush