def tokenChangeHandle(self):
     remove_list = []
     for client in self.callback_address_set:
         try:
             clientInfo = json.loads(client)
         except:
             remove_list.append(client)
             continue
         callback = clientInfo.get('callback')
         method = clientInfo.get('method')
         if method not in ['post', 'get', 'POST', 'GET'
                           ] or callback == None:
             remove_list.append(client)
             continue
         data = {'token': self.token}
         if method == 'get' or method == 'GET':
             result = yield asyncTornadoRequest(callback,
                                                method='GET',
                                                params=data)
         else:
             result = yield asyncTornadoRequest(callback,
                                                method='POST',
                                                body=data)
         if result.get('ret') == 0:
             yield logClient.tornadoInfoLog('token反推成功,{}'.format(callback))
             continue
         else:
             yield logClient.tornadoWarningLog(
                 'token反推失败,{}'.format(callback))
             remove_list.append(client)
     for client in remove_list:
         self.callback_address_set.discard(client)
Beispiel #2
0
 def tokenError(self):
     url = TOKEN_SERVICE_ADDRESS
     data = {'token_error': 1}
     while True:
         result = yield asyncTornadoRequest(url, method='GET', params=data)
         if result.get('ret') == 0:
             token = result.get('token')
             if token != None:
                 self.token = token
                 break
         yield gen.sleep(5)
Beispiel #3
0
 def login(self):
     url = TOKEN_SERVICE_ADDRESS
     data = {'callback': TOKEN_CHANGE_ADDRESS, 'method': 'POST'}
     while True:
         result = yield asyncTornadoRequest(url, method='GET', params=data)
         if result.get('ret') == 0:
             self.token = result.get('token')
             if self.token != None:
                 yield logClient.tornadoInfoLog('登录成功,token:{}'.format(
                     self.token))
                 break
         yield logClient.tornadoWarningLog('登录失败')
         yield gen.sleep(5)
     yield self.updateCallback()
Beispiel #4
0
 def getWeather(self, city_id, city_name):
     url = self.baseUrl + '/api/'
     data = {
         'appid': self.appid,
         'appsecret': self.appsecret,
         'version': 'v6',
         'cityid': city_id,
         'city': city_name,
         'ip': '',
         # 'callback':'http://{}:8016/inkScreenToken/get_token'.format(TEST_SERVER_HOST),
         'vue': 0,
     }
     result = yield asyncTornadoRequest(url=url, method='GET', params=data)
     return result
Beispiel #5
0
 def brushSelfInfo(self,brush_info):
     headers = {
         'content-type': 'application/json',
         'Authorization': 'Bearer ' + self.eslCloudClient.token
     }
     shopGoods = {
         'information': brush_info,
         "storeUuid": self.eslCloudClient.storeCode  # 必填参数 门店编码
     }
     url = self.eslCloudClient.goodBrushUrl
     result = yield asyncTornadoRequest(url, method='POST', headers=headers, body=shopGoods)
     status = result.get('status')
     if status == 200 or status == '200':
         # if DEBUG:
         return True
     else:
         return status
Beispiel #6
0
 def updateLabelTemplate(self,mac,template):
     headers = {
         'content-type': 'application/json',
         'Authorization': 'Bearer ' + self.eslCloudClient.token
     }
     specify = {
         'mac':mac,
         'demoId':template,
         'barcode':self.barcode,
         'storeId':self.eslCloudClient.storeCode
     }
     url = self.eslCloudClient.templateBindUpdate
     result = yield asyncTornadoRequest(url, method='POST', headers=headers, body=specify)
     status = result.get('status')
     if status == 200 or status == '200':
         return True
     else:
         return status
 def login(self):
     body = {'username': self.username, 'password': self.password}
     url = self.loginUrl
     while True:
         result = yield asyncTornadoRequest(url, method='POST', body=body)
         if result.get('errcode') == 200:
             result_body = result.get('body')
             if result_body == None:
                 yield gen.sleep(10)
                 continue
             self.token = result_body.get('token')
             if self.token == None:
                 yield gen.sleep(10)
                 continue
             yield logClient.tornadoInfoLog('登录成功')
             break
         else:
             yield logClient.tornadoWarningLog('登录失败')
     yield self.tokenChangeHandle()
Beispiel #8
0
 def updateCallback(self):
     url = self.updateCallbackUrl
     body = {'pushUrl': CALLBACK_ADDRESS}
     self.headers = {
         'content-type': 'application/json',
         'Authorization': 'Bearer ' + self.token
     }
     while True:
         result = yield asyncTornadoRequest(url,
                                            method='POST',
                                            headers=self.headers,
                                            params=body,
                                            allow_nonstandard_methods=True)
         if result.get('status') == '200' or result.get('status') == 200:
             yield logClient.tornadoInfoLog('设定回调地址成功')
             return
         else:
             yield logClient.tornadoErrorLog('设定回调地址失败')
             yield self.tokenError()
             yield gen.sleep(10)
 def brushLed(self,mac:str,color:int,total:int=1500,period:int=500,interval:int=1000,brigthness:int=5):
     if color == 0:
         real_color = 2
     elif color == 1:
         real_color = 1
     elif color == 2:
         real_color = 3
     else:
         real_color = 2
     STATUS_TO_NAME = {
         0: '空闲中',
         1: '准备中',
         2: '进行中',
     }
     yield logClient.tornadoInfoLog('{}:状态切换为{}'.format(self.name, STATUS_TO_NAME[color]),company=self.company_name)
     headers = {
         'content-type': 'application/json',
         'Authorization': 'Bearer ' + self.eslCloudClient.token
     }
     data = {
         'storeUuid': self.eslCloudClient.storeCode,
         'mac': mac,
         'color': real_color,
         'total': total,
         'period': period,
         'interval': interval,
         'brigthness': brigthness,
     }
     url = self.eslCloudClient.controlLedUrl
     result = yield asyncTornadoRequest(url, method='PUT', headers=headers, params=data, body=data)
     yield logClient.tornadoInfoLog('会议室:{},led控制推送结果:{}'.format(self.name,result),company=self.company_name)
     status = result.get('status')
     if status == 200:
         self.schedule_status = color
         return True
     else:
         yield logClient.tornadoErrorLog('{}的led推送失败'.format(self.name),company=self.company_name)
         yield self.eslCloudClient.tokenError()
         self.ioloop.add_timeout(self.ioloop.time() + 60, self.brushLed, mac, color)
         return False