def Qrcode(User=None, Grade=None): try: if User and Grade: if User and int(Grade) >= 2: verify_key = "{0}_{1}".format(User, Grade) code = produce.Produce(length=6, chars=string.digits) Redis.set(verify_key, code) Redis.expire(verify_key, 900) # send sms result = produce.send_sms( content='上线码:{0} 申请人:{1} 15分钟内有效!'.format(code, User), mobile=Mobile) if isinstance(result, dict): if result['code'] == 200: INFO = '上线码已成功发送给领导!' else: INFO = '上线码发送失败!' else: INFO = '上线码发送失败!' else: INFO = "无需申请上线码!" else: INFO = "非法请求信息!" except Exception as e: INFO = str(e) return render_template('qrcode.html', INFO=INFO)
def Qrcode(User = None,Grade = None,project=None,project_level = None): try: tw = int(time.strftime('%w', time.localtime())) publish_time = int(time.strftime("%H", time.localtime())) crypto = Md5.crypto(crypto_key) if User and Grade: db = db_op.idc_users User = crypto.decrypt(User) project = crypto.decrypt(project) if db.query.filter(db.name == User).all() and int(Grade) >= 2: if tw in (0,6) or publish_time >= 17 or publish_time < 9: verify_key = "{0}_{1}".format(User,project) code = str(produce.Produce(length=6, chars=string.digits)) if '0' in code: code.replace('0','1') myRedis.set(verify_key,code) myRedis.expire(verify_key, 900) # send sms mobile = JAVA_Mobile if int(project_level) >= 7: mobile = Mobile result = produce.send_sms(content='上线码:{0} 上线项目:{1} 申请人:{2} 15分钟内有效!'.format(code,project,User), mobile=mobile) if isinstance(result, dict): if result['code'] == 200: INFO = '上线码已成功发送给JAVA领导!' if int(project_level) >= 7: INFO = '上线码已成功发送给曾总!' else: INFO = '上线码发送失败!' else: INFO = '上线码发送失败!' else: INFO = "只允许在工作日17点之后或者周末全天申请!" else: INFO = "该账号无权申请上线码!" else: INFO = '非法请求信息!' except Exception as e: INFO = str(e) return render_template('qrcode.html',INFO=INFO)