def push_to_client(self, location): """Push information to weixin and wspush. """ #NOTE: use timestamp first. If it does not work, use gps_time. if location.get('timestamp',''): timestamp = location['timestamp'] else: timestamp = location['gps_time'] flag = self.check_timestamp(int(timestamp)) if not flag: return tid = location['dev_id'] terminal = QueryHelper.get_terminal_info(tid, self.db, self.redis) body = dict(tid=tid, category=location['category'], type=location['type'], timestamp=timestamp, gps_time=location['gps_time'], latitude=location.get('lat',0), longitude=location.get('lon',0), clatitude=location.get('cLat',0), clongitude=location.get('cLon',0), name=location['name'] if location.get('name',None) is not None else '', degree=location.get('degree',0), speed=location.get('speed',0), locate_error=location.get('locate_error',0), region_id=location.get('region_id',-1), # for terminal alias=terminal.get('alias'), gps=terminal.get('gps'), gsm=terminal.get('gsm'), pbat=terminal.get('pbat')) WSPushHelper.pushS5(tid, body, self.db, self.redis) WeixinPushHelper.push(tid, body, self.db, self.redis)
def post(self): """Acquire push account through uid @uid: user uid """ status = ErrorCode.SUCCESS try: data = DotDict(json_decode(self.request.body)) tid = data.tid s_type = data.s_type if data.get("category", None): category = int(data.get("category")) else: category = 1 logging.info("[UWEB] Test wspush request: %s.", data) except Exception as e: status = ErrorCode.ILLEGAL_DATA_FORMAT logging.exception("[UWEB] Invalid data format. body: %s, Exception: %s", self.request.body, e.args) self.write_ret(status) return try: # user = self.db.get("select owner_mobile") user = QueryHelper.get_user_by_tid(tid, self.db) uid = user.owner_mobile if s_type == "S3": WSPushHelper.pushS3(tid, self.db, self.redis) elif s_type == "S4": WSPushHelper.pushS4(tid, self.db, self.redis) elif s_type == "S5": body = dict( tid=tid, category=category, pbat=100, type=1, timestamp=int(time.time()), longitude=419004000, latitude=143676000, clongitude=419004000, clatitude=143676000, name="test name", speed=111, degree=203, gsm=0, locate_error=100, gps=25, alias="111", region_id=11, ) WSPushHelper.pushS5(tid, body, self.db, self.redis) elif s_type == "S6": WSPushHelper.pushS6(tid, self.db, self.redis) elif s_type == "S7": WSPushHelper.pushS7(tid, self.db, self.redis) elif s_type == "S8": acc_message = 1 WSPushHelper.pushS8(tid, acc_message, self.db, self.redis) self.write_ret(status=status) except Exception as e: logging.exception("[UWEB] WSPushHandler get push account failed, Exception:%s", e.args) status = ErrorCode.SERVER_BUSY self.write_ret(status)