예제 #1
0
파일: recharge.py 프로젝트: 128340haha/pile
    def post(self):
        code = self.get_argument('code','') 
        openid = self.get_secure_cookie('openid')
    #    openid = 'oXq4Lt-ob9EmU2AITP8Cz6Ur-bac'
        user = usermodel(self)
        info = user.userbind(openid)
        card = user.cardinfo(info['id'])
        charge = chargemodel(self)
        order_info = charge.search_order( code,info['id'] )
        #当前电桩详情
        device_info = charge.device_info( code )
        if device_info and device_info['status'] == 2:
            #订单状态为充电中
            if order_info:
                code = order_info['code']
                kind = int(code[0:4]) + 0xC000
                no = int(code[4:])
                #获取访问的地址
                _socket = SOCKETClient(setting['from_address'], setting['from_port'],False)
                packed_data = _socket.get_data(kind,no)
                respone = _socket.handle_send( packed_data )
                ip,port = _socket.find_ip( respone )
                if not ip:
                    #地址获取失败
                    self.finish('5')
                    return  

                #发起soket去通知电桩 停止充电
                datas = [ card['cardtype'], card['cardid'] ]
                _send = SOCKETClient(ip, port)

                s = struct.Struct('<HI')
                packed_data = s.pack(*datas)
                new_datas = [ord(x) for x in packed_data]
                set_data = _send.set_data(kind,no,0x9,0x0,new_datas)
                try:
                    respone = _send.handle_send( set_data )
                except:
                    #访问超时
                    self.finish('4')
                    return
                
            #    print [hex(ord(x)) for x in respone] 

                if ord(respone[9]) == 0xc4:
                    #离线
                    self.finish('0')
                else:
                    #正常完成
                    self.finish('1')
            else:
                #充电已经完成
                self.finish('2')
        else:
            #电桩非工作中
            self.finish('3')
예제 #2
0
파일: recharge.py 프로젝트: 128340haha/pile
    def post(self):
        code = self.get_argument('code','')
        if code:
            kind = int(code[0:4]) + 0xC000
            no = int(code[4:])
            #获取访问的地址
            _socket = SOCKETClient(setting['from_address'], setting['from_port'],False)
            packed_data = _socket.get_data(kind,no)
            try:
                respone = _socket.handle_send( packed_data )
            except:
                self.finish('3')
                return
            ip,port = _socket.find_ip( respone )
            if not ip:
                #获取地址失败
                self.finish('2')
                return  
            
            #发起soket去通知电桩,带上设备码和用户id以及怎么充
            datas = [ 4,param['token'],price*100,card['cardno'],card['cardtype'],card['cardid'],balance*100,param['money']*100,0,param['mini'],0,param['elec']*100,0 ]
            _send = SOCKETClient(ip, port) 

            s = struct.Struct('<BBHIHIIIIHHII')
            packed_data = s.pack(*datas)
            #ns = struct.Struct('%dB' %s.size)
            #new_datas = ns.unpack(packed_data) 
            new_datas = [ord(x) for x in packed_data]
            set_data = _send.set_data(kind,no,0x2,0x1,new_datas)
            try:
                respone = _send.handle_send( set_data )
            except:
                self.tips( self.finish('4') )
                return
        #    print [hex(ord(x)) for x in respone] 
            #测试数据
            param = {'elec':15,'pay':3.4,'acttime':37}
            self.finish(json.dumps(param))
        else:
            self.finish('0')
예제 #3
0
파일: recharge.py 프로젝트: 128340haha/pile
    def post(self):
        openid = self.get_secure_cookie('openid')
        #openid = 'oXq4LtyH8lET2u6iTuvxnWJGxr68'
        user = usermodel(self)
        info = user.userbind(openid)
        card = user.cardinfo(info['id'])
        choose = self.get_argument('choose','') 
        code = self.get_argument('code','') 
        value = self.get_argument(choose+'_input','')
        valid = validate()
        valid.Add( code,'设备码', ['NoEmpty','Isdigit','IsLegalAccounts'], 12, 12 )
        valid.Add( choose,'充值方式', ['NoEmpty'] )
        if not valid._CheckMate():
            #跳转去相关页面
            self.tips( 0, apimsg.notice(400), 'back', valid._Message() )
            return 
        charge = chargemodel(self)
        #钱包余钱
        balance = charge.getpackage(info['id'])

        #验证充值参数
        param = check_value( choose, value, balance )
        if not param:
            self.tips( 0, apimsg.notice(400) )
            return

        if not card:
            self.tips( 0, apimsg.notice(304) )
            return

        price = charge.newPrice( time.time() )
        if not price or price < 0.5:
            self.tips( 0, apimsg.notice(211) )
            return

        #获取电桩状态 待机的话就开工
        status = charge.check_status( code )
        if status > 1:
            self.tips( 0, apimsg.notice(status) )
            return

        #订单唯一性
        only = charge.only_order(info['id'])
        if not only:
            self.tips( 0, apimsg.notice(217) )
            return
        
        thistime = int(time.time())
        
        #写入订单表
        #order = charge.make_order(info['id'],code,thistime)
        #if not order:
        #    self.tips( 0, apimsg.notice(216) )
        #    return

        #电桩设备码
        kind = int(code[0:4]) + 0xC000
        no = int(code[4:])
        #获取访问的地址
        _socket = SOCKETClient(setting['from_address'], setting['from_port'],False)
        packed_data = _socket.get_data(kind,no)
        try:
            respone = _socket.handle_send( packed_data )
        except:
            self.tips( 0, apimsg.notice(219) )
            return
        ip,port = _socket.find_ip( respone )
        if not ip:
            self.tips( 0, apimsg.notice(215) )
            return  

        #发起soket去通知电桩,带上设备码和用户id以及怎么充
        datas = [ 4,param['token'],price*100,card['cardno'],card['cardtype'],card['cardid'],balance*100,param['money']*100,0,param['mini'],0,param['elec']*100,0 ]
        _send = SOCKETClient(ip, port) 

        s = struct.Struct('<BBHIHIIIIHHII')
        packed_data = s.pack(*datas)
        #ns = struct.Struct('%dB' %s.size)
        #new_datas = ns.unpack(packed_data) 
        new_datas = [ord(x) for x in packed_data]
        set_data = _send.set_data(kind,no,0x2,0x1,new_datas)
        try:
            respone = _send.handle_send( set_data )
        except:
            self.tips( 0, apimsg.notice(219) )
            return
    #    print [hex(ord(x)) for x in respone] 
        #异步
        #asyncore.loop()

        if ord(respone[9]) == 0xc4:
            self.tips( 0, apimsg.notice(219) )
        else:    
            params = urllib.urlencode({'thistime':thistime,'choose':choose,'value':value,'code':code}) 
            url = "/charging?%s" %(params)
            self.redirect( url ) 
예제 #4
0
파일: recharge.py 프로젝트: 128340haha/pile
    def post(self):
        openid = self.get_secure_cookie('openid')
    #    openid = 'oXq4LtyH8lET2u6iTuvxnWJGxr68'
        user = usermodel(self)
        info = user.userbind(openid)
        card = user.cardinfo(info['id'])
        choose = self.get_argument('choose','') 
        code = self.get_argument('code','') 
        value = self.get_argument('value','')
        valid = validate()
        valid.Add( code,'设备码', ['NoEmpty','Isdigit','IsLegalAccounts'], 12, 12 )
        valid.Add( choose,'充值方式', ['NoEmpty'] )
        if not valid._CheckMate():
            #跳转去相关页面
            self.finish('5')
            return 
        charge = chargemodel(self)

        #钱包余钱
        balance = charge.getpackage(info['id'])

        #验证充值参数
        param = check_value( choose, value, balance )
        if not param:
            self.finish('5')
            return
        #没有绑定卡
        if not card:
            self.finish('6')
            return

        price = charge.newPrice( time.time() )
        if not price or price < 0.5:
            self.finish('7')
            return
        #设备状态判断
        status = charge.check_status( code )
        if status == 226:
            self.finish('3')
            return
        elif status == 214:
            self.finish('2')
            return
        elif status == 210:
            self.finish('4')
            return    

        #订单唯一性
        only = charge.only_order(info['id'])
        if not only:
            self.finish('8')
            return

        #电桩设备码
        kind = int(code[0:4]) + 0xC000
        no = int(code[4:])
        #获取访问的地址
        _socket = SOCKETClient(setting['from_address'], setting['from_port'],False)
        packed_data = _socket.get_data(kind,no)
        try:
            respone = _socket.handle_send( packed_data )   
        except:
            self.finish('3')
            return
        ip,port = _socket.find_ip( respone )
        if not ip:
            self.finish('4')
            return

        #发送用户信息通知
        message = str(info['nickname']) if info['nickname'] else str(info['username'])
        doll = message.decode('utf-8').encode('gb2312')
        sendmess = []
        key = len(doll)
        #最多发送12字符
        for x in range(0,12):
            if x < key:
                sendmess.append( ord( doll[x] ) )
            else:
                sendmess.append(0)

        #时间
        nowtime = time.localtime() 
        datas = [ nowtime.tm_sec,nowtime.tm_min,nowtime.tm_hour,nowtime.tm_wday,5,0,0,0,0,0] + sendmess + [0]
        _mess = SOCKETClient(ip, port)
        set_mess = _mess.set_data(kind,no,0x2,0x4,datas)
        try:
            respone = _mess.handle_send( set_mess )   
        except:
            self.finish('3')
            return
        #异步
        #asyncore.loop()
    #    print balance
        #发起soket去通知电桩,带上设备码和用户id以及怎么充
        datas = [ 3,param['token'],price*100,card['cardno'],card['cardtype'],card['cardid'],balance*100,param['money']*100,0,param['mini'],0,param['elec']*100,0 ]
        _send = SOCKETClient(ip, port) 
        #数据流格式
        s = struct.Struct('<BBHIHIIIIHHII')
        packed_data = s.pack(*datas)
        #ns = struct.Struct('%dB' %s.size)
        #new_datas = ns.unpack(packed_data) 
        new_datas = [ord(x) for x in packed_data]
        set_data = _send.set_data(kind,no,0x2,0x1,new_datas)
        try:
            respone = _send.handle_send( set_data )
        except:
            self.finish('3')
            return
    #    print [hex(ord(x)) for x in respone] 
        #异步
        #asyncore.loop()

        if ord(respone[9]) == 0xc4:
            self.finish('3')
        else:
            self.finish('1')
예제 #5
0
파일: index.py 프로젝트: 128340haha/pile
 def get(self):
     _socket = SOCKETClient(setting['from_address'], setting['from_port'])
     packed_data = _socket.get_data()
     respone = _socket.handle_send( packed_data )
     ip,port = _socket.find_ip( respone )
     print ip,port