# -*- coding: utf-8 -*- # !/usr/bin/env python import logging from apps.common.utils import int_to_hex from apps.web.constant import DeviceCmdCode from apps.web.core.adapter.base import SmartBox, SendManager from apps.web.core.exceptions import ServiceException logger = logging.getLogger(__name__) class JiuHengICRechargeBox(SmartBox): def start_device(self, package, openId, attachParas): # todo 简单实现 cardNo = "00000000" cardCst = "0000" cardOpe = "02" payload = { "funCode": "22", "data": cardNo + cardCst + cardOpe } with SendManager(visitor="client") as sender1: result1 = sender1.send( device=self.device, cmd=DeviceCmdCode.OPERATE_DEV_SYNC, payload=payload, timeout=60 ) sender1.rst = result1 cardNoHex = '00000000' balanceHex = int_to_hex(int(float(package['coins']) * 10), lens=4) cardOpe = "01" payload = { "funCode": "22", "data": cardNoHex + balanceHex + cardOpe } with SendManager(visitor="client") as sender: result = sender.send( device=self.device, cmd=DeviceCmdCode.OPERATE_DEV_SYNC, payload=payload, timeout=60 ) sender.rst = result rstCardNo = result['data'][8:16] if rstCardNo == '00000000': raise ServiceException({'result': 2, 'description': u'未检测到充值卡, 请稍后再试'}) return result