Explorar o código

alexa更新状态

tanghongbin %!s(int64=4) %!d(string=hai) anos
pai
achega
c802604ed9
Modificáronse 2 ficheiros con 31 adicións e 1 borrados
  1. 14 0
      Controller/EquipmentManager.py
  2. 17 1
      Controller/EquipmentManagerV3.py

+ 14 - 0
Controller/EquipmentManager.py

@@ -2,6 +2,8 @@ import re
 import time
 import traceback
 import threading
+
+import requests
 import simplejson as json
 from django.utils import timezone
 from Model.models import Device_User, Device_Info, UID_Bucket, UID_Preview, UidSetModel, UidPushModel
@@ -161,6 +163,7 @@ def delUserEquipmentInterface(request):
             dv_qs.delete()
             asy = threading.Thread(target=ModelService.del_eq_info, args=(userID, uid))
             asy.start()
+            notify_alexa_delete(uid)
     except Exception as e:
         errorInfo = traceback.format_exc()
         print('删除数据库记录错误: %s' % errorInfo)
@@ -1038,3 +1041,14 @@ def update_device_shadow(request):
             return JsonResponse(status=200, data={'code': 0, 'msg': 'success', 'data': {}})
     else:
         return JsonResponse(status=200, data={'code': 403, 'msg': 'error etk'})
+
+
+def notify_alexa_delete(UID):
+    url = 'https://www.zositech.xyz/deviceStatus/delete'
+    data = {
+        'UID': UID
+    }
+    try:
+        requests.post(url=url, data=data, timeout=1)
+    except Exception as e:
+        print(repr(e))

+ 17 - 1
Controller/EquipmentManagerV3.py

@@ -2,6 +2,9 @@ import re
 import threading
 import time
 import traceback
+
+import requests
+
 from Controller.CheckUserData import RandomStr
 import oss2, base64
 from django.db.models import Q
@@ -96,6 +99,7 @@ class EquipmentManagerV3(View):
                                                  NickName=NickName, View_Account=View_Account,
                                                  View_Password=View_Password, Type=Type, ChannelIndex=ChannelIndex)
                         userDevice.save()
+                        self.notify_alexa_add(UID, userID, NickName)
                         # redisObj = RedisObject(db=8)
                         # redisObj.del_data(key='uid_qs_' + userID)
                     except Exception as e:
@@ -379,4 +383,16 @@ class EquipmentManagerV3(View):
                 password = password.decode('utf-8')
                 # 去前3位,后3位
                 password = password[3:-3]
-        return password
+        return password
+
+    def notify_alexa_add(self, uid, userID, nickname):
+        url = 'https://www.zositech.xyz/deviceStatus/addOrupdate'
+        data = {
+            'UID': uid,
+            'userID': userID,
+            'uid_nick': nickname
+        }
+        try:
+            requests.post(url, data=data, timeout=1)
+        except Exception as e:
+            print(repr(e))