flask
Posted pertest
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了flask相关的知识,希望对你有一定的参考价值。
# -*- coding: utf-8 -*-
# @Time : 2018/12/30 20:55
# @Author : yang dan
# @FileName: mockXCX.py
"""
1.服务名称:挡板程序,模拟企业版微服务 小程序sprint 1st 接口服务
2.接口详情:
1)小程序登录及token刷新:/sns/component/jscode2session | GET
"""
from flask import Flask, request
import json
app = Flask(__name__)
@app.route(‘/‘)
def index():
return ‘flask demo!‘
# 小程序登录及token刷新
@app.route(‘/sns/component/jscode2session‘, methods=[‘GET‘, ‘POST‘])
def card_detail():
if request.method == ‘GET‘:
data = request.form.to_dict()
company_id = data.get(‘Long‘)
if company_id == ‘523144769413582848‘:
resp = """{
"code":0,
"data":{
"errcode":0,
"openid":"obpMo41bszydJKWCvHhyDb1oW9v8",
"session_key":"jTXrZqfLg5bL1ayM3NeusQ=="
},
"msg":"成功"
}
"""
return resp
elif company_id ==‘502565183546195968‘:
resp = """{
"code":0,
"data":{
"errcode":0,
"openid":"ozN_M4i70w2lRAa8IkBhgDmhQTKw",
"session_key":"a2c9D1YQ1WY11Q0ssPRsOQ=="
},
"msg":"成功"
}"""
return resp
else:
return r‘{code:-2, message:"无效或错误的参数!"}‘
else:
return r‘{code:-1, message:"请求方法错误!"}‘
if __name__ == ‘__main__‘:
app.run(host=‘0.0.0.0‘, port=80, debug=True)
以上是关于flask的主要内容,如果未能解决你的问题,请参考以下文章