@app.route('/index') def index_html(): print(session.get('userid')) temp_data = { "userid": session.get('userid') } headers = { 'content-type': "application/json", } rs = requests.post(get_user_menu_url, data=json.dumps(temp_data), headers=headers) data = rs.text.encode('utf8') data_json = json.loads(data) info = {'menu_info': data_json['data']} print(info) return render_template('index.html', **info) @app.route('/cas/qrcode',methods=['GET','POST']) def qrcode(): type = request.values.get('type') id = request.values.get('id') data = json.dumps({'serviceId': cas_serviceId}) req = requests.post(cas_getConfig_url, data=data) config = req.json() if type == 'cXJjb2Rl': req = requests.get(cas_qrcode_url,headers={'routing':config['routing']},params={"type":type}) return jsonify(req.json()) else: req = requests.get(cas_qrcode_url,headers={'routing':config['routing']},params={"type":type,"id":id}) result = req.json() print("===================================") print('监控接口响应',result) if result['success']: service = base64.b64decode(result['data']['id']) service = base64.b64decode(service).decode() validate_data = json.dumps({ 'st':result['data']['ticket'], 'service': service }) validate_req = requests.post(validate_url, headers={'routing': config['routing']}, data=validate_data) validate_res = validate_req.json() print('验证接口响应',validate_res) if validate_res['status'] == 'SUCCESS': temp_data = { "keyword": validate_res['userName'] } headers = { 'content-type': "application/json", } rs = requests.post(query_user_url, data=json.dumps(temp_data), headers=headers) data = rs.text.encode('utf8') data_json = json.loads(data) if data_json['success'] and len(data_json['data']): session['username'] = data_json['data'][0]['username'] session['userid'] = validate_res['userName'] session['roleid'] = data_json['data'][0]['roleid'] print(session) return redirect('/index') else: return render_template('user/cas_auth.html', result='登录异常,请联系运维处理') else: return render_template('user/cas_auth.html', result=validate_res['error']) return jsonify(result)