def post(self): cardtype = self.get_argument('cardtype','') cardno = self.get_argument('cardno','') nickname = self.get_argument('nickname','') phone = self.get_argument('phone','') balance = self.get_argument('balance','') valid = validate() valid.Add( cardtype,'分类', ['NoEmpty','Isdigit'] ) valid.Add( cardno,'识别码', ['NoEmpty','Isdigit'] ) valid.Add( phone,'手机', ['NoEmpty','Isdigit'],11,11 ) if not valid._CheckMate(): self.finish( self.respone_data( 0, valid._Message() ) ) return user = usermodel(self) username = user.used_name() res = user.register(username=username,password=username,cardno=cardno,cardtype=cardtype) id = user.get_insert_id() if res and id: #更改电话 user.editinfo('phone',phone,username) if nickname: user.editinfo('nickname',nickname,username) card = cardmodel(self) where = "where c.user_id = %s" %id info = card.card_infomation( where ) #新卡充值 ser.purse_edit( id=id, balance=balance ) #返回数据 self.finish( self.respone_data( 1, info ) ) else: self.finish( self.respone_data( 0, apimsg.notice(307) ) )
def post(self): admin = self.get_argument('admin','') password = self.get_argument('password','') id = self.get_argument('id','') act = self.get_argument('act','') valid = validate() if act == 'add': valid.Add( admin,'管理员ID', ['NoEmpty'], 6, 30 ) valid.Add( password,'密码', ['NoEmpty'], 6, 30 ) if not valid._CheckMate(): self.prompt( 0, apimsg.notice(400), 'javascript:history.go(-1)', valid._Message() ) return adm = adminmodel(self) if act == 'add': res = adm.newadmin(admin=admin,password=password) elif act == 'reset': info = adm.adminmain(admin) if info and id: newpass = adm.adminpass(password,info['salt']) res = adm.change_pass(newpass,id) else: self.prompt( 0, apimsg.notice(400), '/admin/admin_list' ) return if res == 1: self.prompt( 1, apimsg.notice(305), '/admin/admin_list' ) else: self.prompt( 0, apimsg.notice(307), '/admin/admin_list' )
def get(self): cardtype = self.get_argument('cardtype','') page = self.get_argument('page','1') per_page = self.get_argument('per_page','10') where = ' where u.status < 2 ' valid = validate() valid.Add( page,'当前页', ['NoEmpty','Isdigit'] ) valid.Add( per_page,'每页显示', ['NoEmpty','Isdigit'] ) if not valid._CheckMate(): self.finish( self.respone_data( 0, '分页参数异常' ) ) return if cardtype: valid.Add( cardtype,'分类', ['Isdigit'] ) if not valid._CheckMate(): self.finish( self.respone_data( 0, valid._Message() ) ) return where += " AND c.cardtype = %d" %int(cardtype) card = cardmodel(self) clist = card.card_list( where, int(page), int(per_page) ) if clist: pinfo = card.page_bar(2) else: clist = [] pinfo = {'this_page':1,'all_page':0,'all_num':0,'per_page':per_page} self.finish( self.respone_list( clist, pinfo ) )
def get(self): cardno = self.get_argument('cardno','') cardid = self.get_argument('cardid','') cardtype = self.get_argument('cardtype','') page = self.get_argument('page','1') per_page = self.get_argument('per_page','20') valid = validate() valid.Add( cardno,'识别码', ['NoEmpty','Isdigit'] ) valid.Add( cardid,'卡号', ['NoEmpty','Isdigit'] ) valid.Add( cardtype,'卡分类', ['NoEmpty','Isdigit'] ) valid.Add( page,'当前页', ['NoEmpty','Isdigit'] ) valid.Add( per_page,'每页显示', ['NoEmpty','Isdigit'] ) if not valid._CheckMate(): self.finish( self.respone_data( 0, valid._Message() ) ) return user = usermodel(self) userid = user.carduser(cardno,cardtype,cardid) charge = chargemodel(self) #查询条件 if userid: where = {'o.user_id =':userid['user_id'],'o.finish >':0} clist = charge.chargelist(where,int(page),int(per_page)) if clist: pinfo = charge.page_bar(2) else: clist = [] pinfo = {'this_page':1,'all_page':0,'all_num':0,'per_page':per_page} self.finish( self.respone_list( clist, pinfo ) ) else: self.finish( self.respone_data( 0, apimsg.notice(222) ) )
def post(self): username = self.get_argument('username','') password = self.get_argument('password','') ckpass = self.get_argument('ckpass','') valid = validate() valid.Add( username,'用户名', ['NoEmpty','IsLegalAccounts'], 4, 30 ) valid.Add( password,'密码', ['NoEmpty','IsLegalAccounts'], 6, 30 ) valid.Same( ckpass, '两次密码' ) if not valid._CheckMate(): self.prompt( 0, apimsg.notice(400), 'back', valid._Message() ) return user = usermodel(self) only = user.userinfo(username,False) if not only: res = user.register(username=username,password=password) if res == 1: self.prompt( 1, apimsg.notice(302), '/admin/user_list' ) return #跳转去登录页面 else: self.prompt( 0, res, 'javascript:history.go(-1)' ) return else: self.prompt( 0, apimsg.notice(202), 'javascript:history.go(-1)' ) return
def post(self): username = self.get_argument('username','') password = self.get_argument('password','') ckpass = self.get_argument('ckpass','') challenge = self.get_argument("geetest_challenge",'') geevalidate = self.get_argument("geetest_validate",'') seccode = self.get_argument("geetest_seccode",'') gt = geetest.geetest(setting['captcha_id'], setting['private_key']) result = gt.geetest_validate(challenge, geevalidate, seccode) if result: #验证码验证码通过 valid = validate() valid.Add( username,'用户名', ['NoEmpty','IsLegalAccounts'], 4, 30 ) valid.Add( password,'密码', ['NoEmpty','IsLegalAccounts'], 6, 30 ) valid.Same( ckpass, '两次密码' ) if not valid._CheckMate(): self.tips( 0, apimsg.notice(400), 'back', valid._Message() ) return user = usermodel(self) only = user.userinfo(username,False) if not only: res = user.register(username=username,password=password) if res == 1: self.tips( 1, apimsg.notice(302), '/login' ) return #跳转去登录页面 else: self.tips( 0, res, '/register' ) return else: self.tips( 0, apimsg.notice(202), '/register' ) return else: self.tips( 0, apimsg.notice(206), '/register' ) return
def get(self): cardno = self.get_argument('cardno','') cardid = self.get_argument('cardid','') cardtype = self.get_argument('cardtype','') page = self.get_argument('page','1') per_page = self.get_argument('per_page',15) target = self.get_argument('target','') valid = validate() valid.Add( cardno,'识别码', ['Isdigit'] ) valid.Add( cardid,'卡号', ['NoEmpty','Isdigit'] ) valid.Add( cardtype,'卡分类', ['NoEmpty','Isdigit'] ) valid.Add( page,'当前页', ['NoEmpty','Isdigit'] ) valid.Add( per_page,'每页显示', ['NoEmpty','Isdigit'] ) if not valid._CheckMate(): self.finish( self.respone_data( 0, valid._Message() ) ) return user = usermodel(self) userid = user.carduser(cardno,cardtype,cardid) charge = chargemodel(self) if target == 'deposit': where = {'user_id =':userid['user_id']} dlist = charge.savelist(where,int(page),int(per_page)) elif target == 'recharge': where = {'o.user_id =':userid['user_id'],'o.finish >':0} dlist = charge.chargelist(where,int(page),int(per_page)) else: dlist = [] self.render("point/print.html",dlist=json.dumps(dlist),target=target,cardno=cardno,cardid=cardid,cardtype=cardtype,page=page,per_page=per_page)
def post(self): cardno = self.get_argument('cardno','') cardid = self.get_argument('cardid','') cardtype = self.get_argument('cardtype','') phone = self.get_argument('phone','') nickname = self.get_argument('nickname','') password = self.get_argument('password','') valid = validate() valid.Add( cardno,'识别码', ['NoEmpty','Isdigit'] ) valid.Add( cardtype,'分类', ['NoEmpty','Isdigit'] ) valid.Add( cardid,'卡id', ['NoEmpty','Isdigit'] ) valid.Add( phone,'手机', ['NoEmpty','Isdigit'],11,11 ) if not valid._CheckMate(): self.finish( self.respone_data( 0, apimsg.notice(400) ) ) return user = usermodel(self) userid = user.carduser(cardno,cardtype,cardid) if userid: onlyphone = user.only_phone( phone, userid['user_id'] ) if not onlyphone: self.finish( self.respone_data( 0, apimsg.notice(228) ) ) return res = user.uinfo_edit(nickname=nickname,phone=phone,mail='',sex=1,id=userid['user_id']) if password: card = cardmodel(self) card.editinfo('pwd',self.md5(password),userid['user_id']) if res: self.finish( self.respone_data( 1 ) ) else: self.finish( self.respone_data( 0, apimsg.notice(307) ) ) else: self.finish( self.respone_data( 0, apimsg.notice(222) ) )
def post(self): card = self.get_argument('card','') pwd = self.get_argument('pwd','') valid = validate() valid.Add( card,'卡号', ['NoEmpty'] ) valid.Add( pwd,'密码', ['NoEmpty'] ) if not valid._CheckMate(): #跳转去相关页面 self.finish('3') return ca = cardmodel(self) res = ca.cardlogin(card,pwd) self.finish(res)
def post(self): username = self.get_argument('username','') password = self.get_argument('password','') #验证参数 valid = validate() valid.Add( username,'username', ['NoEmpty'] ) valid.Add( password,'password', ['NoEmpty'] ) if not valid._CheckMate(): self.finish( valid._Message(), 0 ) return res = self.user.userlogin(username,password) if res == 1: info = self.user.userinfo( username, 2 ) self.finish( info, 1 ) else: self.finish( code=res )
def post(self): id = self.get_argument('id','') password = self.get_argument('password','') referer = self.get_argument('referer','') valid = validate() valid.Add( id,'id', ['NoEmpty'] ) valid.Add( password,'密码', ['NoEmpty'], 6, 30 ) if not valid._CheckMate(): self.prompt( 0, apimsg.notice(400), 'javascript:history.go(-1)', valid._Message() ) return user = usermodel(self) res = user.pass_reset( id, password ) if res == 1: self.prompt( 1, apimsg.notice(305), referer ) else: self.prompt( 0, apimsg.notice(307), 'javascript:history.go(-1)', res )
def post(self): cardno = self.get_argument('cardno','') cardid = self.get_argument('cardid','') cardtype = self.get_argument('cardtype','') money = self.get_argument('money',0) valid = validate() valid.Add( cardno,'识别码', ['NoEmpty','Isdigit'] ) valid.Add( cardtype,'分类', ['NoEmpty','Isdigit'] ) valid.Add( cardid,'卡id', ['NoEmpty','Isdigit'] ) valid.Add( money,'钱数', ['NoEmpty','Isdigit'] ) if not valid._CheckMate(): self.finish( self.respone_data( 0, valid._Message() ) ) return #当前商家信息 session = self.get_secure_cookie('seller') card = cardmodel(self) sid = card.get_seller_id( session ) seller = card.sellerinfo( sid ) #用户信息 user = usermodel(self) userid = user.carduser(cardno,cardtype,cardid) if userid: uid = userid['user_id'] uinfo = user.trueinfo( '', uid ) charge = chargemodel(self) balance = charge.getpackage( uid ) #金额计算 fakemoney = int(money)*100 newmoney = ( float(balance)*100+fakemoney ) / 100 #当前时间 nowtime = int(time.time()) #订单号 oid = user.build_order() #描述组合 descript = seller['sellername']+u'用户'+uinfo['username']+'('+uinfo['nickname']+u')充值'+money log = logmodel(self) try: log.change_purse( newmoney, uid ) log.save_order( oid, uid, money, nowtime, 'point', seller['sellername'] ) log.save_payments( oid, sid, money, uid, descript, nowtime ) log.commit_submit() self.finish( self.respone_data( 1 ) ) except: self.finish( self.respone_data( 0, apimsg.notice(307) ) ) else: self.finish( self.respone_data( 0, apimsg.notice(222) ) )
def post(self): username = self.get_argument('username','') password = self.get_argument('password','') valid = validate() valid.Add( username,'用户名', ['NoEmpty'] ) valid.Add( password,'密码', ['NoEmpty'] ) if not valid._CheckMate(): #跳转去相关页面 self.finish('0') return elif not self.health_param(username): #用户名格式异常 self.finish('2') return card = cardmodel(self) res = card.sellerlogin( username,password ) self.finish(res)
def post(self): cardno = self.get_argument('cardno','') cardid = self.get_argument('cardid','') cardtype = self.get_argument('cardtype','') nickname = self.get_argument('nickname','') phone = self.get_argument('phone','') password = self.get_argument('password','') balance = self.get_argument('balance','') valid = validate() valid.Add( cardtype,'分类', ['NoEmpty','Isdigit'] ) valid.Add( cardno,'识别码', ['NoEmpty','Isdigit'] ) valid.Add( cardid,'卡id', ['NoEmpty','Isdigit'] ) valid.Add( phone,'手机', ['NoEmpty','Isdigit'],11,11 ) valid.Add( nickname,'用户名', ['NoEmpty'] ) valid.Add( balance,'充值金额', ['NoEmpty','Isdigit'] ) if not valid._CheckMate(): self.finish( self.respone_data( 0, apimsg.notice(400) ) ) return user = usermodel(self) #唯一电话验证 onlyphone = user.only_phone( phone ) if not onlyphone: self.finish( self.respone_data( 0, apimsg.notice(228) ) ) return #当前商家信息 session = self.get_secure_cookie('seller') card = cardmodel(self) sid = card.get_seller_id( session ) seller = card.sellerinfo( sid ) #随机用户名 username = user.used_name() #订单号 oid = user.build_order() #注册新用户,同时绑定当前卡号 res = user.bind_card(username=username,password=username,cardno=cardno,cardid=cardid,cardtype=cardtype) id = user.get_insert_id() if res == 1 and id: log = logmodel(self) #更改相关参数,以及写入日志 final = log.newcard_infomation( username=username,phone=phone,nickname=nickname,balance=balance,sellerid=sid,sellername=seller['sellername'],password=password,user_id=id,oid=oid ) if final == 1: self.finish( self.respone_data( 1 ) ) else: self.finish( self.respone_data( 0, final ) ) else: self.finish( self.respone_data( 0, res ) )
def post(self): username = self.get_argument('username','') password = self.get_argument('password','') captcha = self.get_argument('captcha','') valid = validate() valid.Add( username,'用户名', ['NoEmpty'] ) valid.Add( password,'密码', ['NoEmpty'] ) if not valid._CheckMate(): #跳转去相关页面 self.tips( 0, apimsg.notice(400), 'back', valid._Message() ) return user = usermodel(self) openid = self.get_secure_cookie('openid') res = user.userlogin( username=username,password=password,captcha=captcha,openid=openid ) if res == 1: self.redirect( '/wechat' ) else: self.tips( 0, res )
def post(self): cardno = self.get_argument('cardno','') cardnumber = self.get_argument('cardnumber','') nickname = self.get_argument('cardnumber','') phone = self.get_argument('phone','') idcard = self.get_argument('idcard','') valid = validate() valid.Add( cardno,'识别码', ['NoEmpty','Isdigit'] ) valid.Add( cardnumber,'卡号', ['NoEmpty','Isdigit','IsAccessLen'], 12, 12 ) user = usermodel(self) cardtype = int(cardnumber[0:4]) cardid = int(cardnumber[4:]) userid = user.carduser(cardno,cardtype,cardid) res = user.uinfo_edit(nickname=nickname,phone=phone,idcard=idcard,mail='',sex=1,id=userid['user_id']) if res: self.finish( self.respone_data( 1, ) ) else: self.finish( self.respone_data( 0, apimsg.notice(307) ) )
def get(self): code = self.get_argument('charge-number','') openid = self.get_secure_cookie('openid') #openid = 'oXq4LtyH8lET2u6iTuvxnWJGxr68' valid = validate() valid.Add( code,'设备码', ['NoEmpty','Isdigit','IsLegalAccounts'], 12, 12 ) if not valid._CheckMate(): #跳转去相关页面 self.tips( 0, apimsg.notice(400), 'back', valid._Message() ) return user = usermodel(self) info = user.userbind(openid) charge = chargemodel(self) res = charge.bind_pile( info['id'], code ) if res == 1: self.redirect('/combo') else: self.tips( 0, res )
def get(self): cardno = self.get_argument('cardno','') cardnumber = self.get_argument('cardnumber','') where = ' where u.status < 2 ' valid = validate() valid.Add( cardno,'识别码', ['NoEmpty','Isdigit'] ) valid.Add( cardnumber,'卡号', ['NoEmpty','Isdigit','IsAccessLen'], 12, 12 ) if not valid._CheckMate(): self.finish( self.respone_data( 0, valid._Message() ) ) return #识别码 where += " AND c.cardno = %d" %int(cardno) cardtype = int(cardnumber[0:4]) cardid = int(cardnumber[4:]) #卡号 where += " AND c.cardtype = %d AND c.cardid = %d" %(cardtype,cardid) card = cardmodel(self) info = card.card_infomation( where ) self.finish( self.respone_data( 1, info ) )
def get(self): appid = self.get_argument("appid", "") appkey = self.get_argument("appkey", "") valid = validate() valid.Add(appid, "appid", ["NoEmpty"]) valid.Add(appkey, "秘钥", ["NoEmpty"]) if not valid._CheckMate(): # 跳转去相关页面 self.finish(self.respone_data(0, valid._Message())) return sql = "SELECT id FROM seller WHERE appid = %s AND appkey = %s" res = self.db.get(sql, appid, appkey) if res: # 验证通过 access_token = str(uuid.uuid1()) # 保存验证记录 self.rd.set("token:" + access_token, 1) self.rd.expire("token:" + access_token, setting["redisexpire"]) self.finish(self.respone_data(1, access_token)) else: self.finish(self.respone_data(0, apimsg.notice(401)))
def get(self): cardno = self.get_argument('cardno','') cardid = self.get_argument('cardid','') cardtype = self.get_argument('cardtype','') valid = validate() valid.Add( cardno,'识别码', ['NoEmpty','Isdigit'] ) valid.Add( cardid,'卡号', ['NoEmpty','Isdigit'] ) valid.Add( cardtype,'卡分类', ['NoEmpty','Isdigit'] ) if not valid._CheckMate(): self.finish( self.respone_data( 0, valid._Message() ) ) return #识别码 where = " WHERE c.cardno = %d" %int(cardno) #卡号 where += " AND c.cardtype = %d AND c.cardid = %d" %(int(cardtype),int(cardid)) card = cardmodel(self) info = card.card_infomation( where ) if info: self.finish( self.respone_data( 1, info ) ) else: self.finish( self.respone_data( 2, apimsg.notice(222) ) )
def post(self): admin = self.get_argument('admin','') password = self.get_argument('password','') captcha = self.get_argument('captcha','') valid = validate() valid.Add( admin,'账号', ['NoEmpty'] ) valid.Add( password,'密码', ['NoEmpty'] ) if not valid._CheckMate(): #跳转去相关页面 params = urllib.urlencode({'admin':admin,'message':'用户名密码不能为空'}) url = "/admin/login?%s" %(params) self.redirect(url) return adm = adminmodel(self) res = adm.adminlogin( admin=admin,password=password,captcha=captcha ) if res == 1: self.write("<script>top.window.location='/admin/index'</script>") # self.redirect( '/admin/index' ) else: params = urllib.urlencode({'admin':admin,'message':res}) url = "/admin/login?%s" %(params) self.redirect(url)
def post(self): appid = self.get_argument('appid','') appsecret = self.get_argument('appsecret','') #验证参数 valid = validate() valid.Add( appid,'appid', ['NoEmpty'] ) valid.Add( appsecret,'appsecret', ['NoEmpty'] ) if not valid._CheckMate(): self.finish( valid._Message(), 0 ) return rd = self.rd db = self.db self.appid = str(appid) #先判断redis中是否存在 live = rd.get(self.appid) if live: live_info = eval( live ) if live_info['appsecret'] == appsecret: self.finish( live_info['token'], 1 ) else: self.finish( code=9 ) else: info = db.get("select * from api_access where appid = %s",self.appid) secret = self.md5(self.appid+str(setting['secretkey'])) #秘钥验证 if info and secret == appsecret: #验证通过 制作token import uuid self.sessionid = str(uuid.uuid4()) #相当于sessionid的随机码 #加密编码 token = self.make_token( self.appid, self.sessionid ) #存入redis rd.set(self.appid,{'appsecret':secret,'token':token,'sessionid':self.sessionid,'content':info['content']}) #过期时间 rd.expire(self.appid,setting['keyexpire']) self.finish( token, 1 ) else: self.finish( code=9 )
def get(self): cardno = self.get_argument('cardno','') cardnumber = self.get_argument('cardnumber','') start = self.get_argument('start','') end = self.get_argument('end','') page = self.get_argument('page','1') per_page = self.get_argument('per_page','10') valid = validate() valid.Add( cardno,'识别码', ['Isdigit'] ) valid.Add( cardnumber,'卡号', ['Isdigit','IsAccessLen'], 12, 12 ) valid.Add( page,'当前页', ['NoEmpty','Isdigit'] ) valid.Add( per_page,'每页显示', ['NoEmpty','Isdigit'] ) if not valid._CheckMate(): self.finish( self.respone_data( 0, valid._Message() ) ) return user = usermodel(self) cardtype = int(cardnumber[0:4]) cardid = int(cardnumber[4:]) userid = user.carduser(cardno,cardtype,cardid) charge = chargemodel(self) #查询条件 if userid: where = {'user_id =':userid['user_id']} if start and start.isdigit(): where['acttime >='] = start if end and end.isdigit(): where['acttime <='] = end dlist = charge.savelist(where,int(page),int(per_page)) if dlist: pinfo = charge.page_bar(2) else: dlist = [] pinfo = {'this_page':1,'all_page':0,'all_num':0,'per_page':per_page} self.finish( self.respone_list( dlist, pinfo ) ) else: self.finish( self.respone_data( 0, apimsg.notice(222) ) )
def post(self): cardno = self.get_argument('cardno','') cardnumber = self.get_argument('cardnumber','') money = self.get_argument('money',0) valid = validate() valid.Add( cardno,'识别码', ['NoEmpty','Isdigit'] ) valid.Add( cardnumber,'卡号', ['NoEmpty','Isdigit','IsAccessLen'], 12, 12 ) valid.Add( float(money),'钱数', ['NoEmpty','IsFloat'] ) if not valid._CheckMate(): self.finish( self.respone_data( 0, valid._Message() ) ) return user = usermodel(self) cardtype = int(cardnumber[0:4]) cardid = int(cardnumber[4:]) userid = user.carduser(cardno,cardtype,cardid) charge = chargemodel(self) balance = charge.getpackage( userid['user_id'] ) money = int(float(money)*100) newmoney = float(balance)*100+float(money) res = user.purse_edit( id=userid['user_id'], balance=newmoney/100 ) if res == '1': self.finish( self.respone_data( 1 ) ) else: self.finish( self.respone_data( 0, apimsg.notice(307) ) )
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 )
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')