def send_phone_captcha(mobile): code = random.randint(100000, 999999) r = json.loads( send_message(mobile=mobile, tpl_id=2, code=code, company=company)) if r['code'] == 0: dbsession = DBSession() FD_T_Phoneauth.post_or_put(dbsession, mobile, code) dbsession.commit() dbsession.close() return r else: return r
def validate_phone_captcha(code, mobile): dbsession = DBSession() try: row = dbsession.query(FD_T_Phoneauth).filter( FD_T_Phoneauth.phone_no == mobile).one() if row.auth_deadline > datetime.datetime.now() and str( row.auth_code) == str(code): # dbsession.delete(row) return {'is_success': True} else: return {'is_success': False, 'des': '验证码错误或已过期'} except: pass finally: dbsession.commit() dbsession.close()
def indb(code, mobile): dbsession = DBSession() FD_T_Phoneauth.post_or_put(dbsession, mobile, code) dbsession.commit() dbsession.close()