def queries_verify(message): content = str(message.content).strip() if re.match('绑定.*', content): s = content.replace('绑定', '').strip() try: row = s.split(' ', 1) if len(row) < 2: return template.help_message user = Consumer.getBy(weixinId=message.source) username = row[0].upper() password = row[1] flg = ApiClient().verify(username, password) if flg is None: return '抱歉, 远程服务未启动, 请稍后再试.' elif not flg: return '身份验证失败, 请检查用户名或密码.' if user is None: Consumer(dict( weixinId=message.source, studentId=username, password=password, )).insert() else: user.studentId = username user.password = password user.update() return '绑定成功, 请通过菜单进行消费记录查询 :-)' except Exception, e: return "抱歉, 出现错误." return str(e)
def consume_history(message): try: user = Consumer.getBy(weixinId=message.source) if user == None: return template.bind_help spider = ApiClient() info = spider.get_cost_today(user.studentId, user.password) status = info.get('errcode') cost = info.get('cost', '') detail = info.get('detail', '') balance = info.get('balance', '') import time user.lastQueryTime = time.strftime("%Y-%m-%d %H:%M:%S") user.update() if status == 0: return [[ template.page["consume_today"].title, template.page["consume_today"].description.format(today=cost, balance=balance) \ + ('\n\n详细消费记录如下: \n\n' + detail if detail else ""), template.page["consume_today"].img, template.page["consume_today"].url, ]] else: return "密码已变更, 身份验证出错." except Exception: return '抱歉,远程服务未启动, 请稍后再试.'
weixinId=message.source, studentId=username, password=password, )).insert() else: user.studentId = username user.password = password user.update() return '绑定成功, 请通过菜单进行消费记录查询 :-)' except Exception, e: return "抱歉, 出现错误." return str(e) elif re.match('挂失饭卡', content): try: user = Consumer.getBy(weixinId=message.source) if user is None: return '操作失败, 请先绑定您的饭卡.' result = ApiClient().report_loss(user.studentId, user.password) if result is None: return '抱歉, 远程服务未启动, 请稍后再试.' if result.get('errcode', 100) != 0: return '出现错误' if result.get('errmsg', '') == '': return '出现错误' return result.get('errmsg', '') except Exception, e: return str(e) elif re.match('绑定查询', content):