<filename>main.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import Flask
from flask_restful import reqparse, abort, Api, Resource

import wx_api
import dev_api
import tool_api
import sence_api
import link_api

# Flask初始化参数尽量使用你的包名，这个初始化方式是官方推荐的，官方解释：http://flask.pocoo.org/docs/0.12/api/#flask.Flask
app = Flask(__name__)
api = Api(app)

token = '<PASSWORD>'

def check_token(token_in):
    if (not token_in):
        print ('not token')
        return -1
    elif (token_in != token):
        print('token error: ' + token_in)
        return -1
    else:
        return 0

# get blog info
class GetBlogInfo(Resource):
    def post(self):
        if (0 != check_token(reqparse.request.headers.get('token'))):
            abort(403)
            return
        else:
            return wx_api.wx_blog_info_get(reqparse.request.json)


# get dev list
class GetDevList(Resource):
    def post(self):
        if (0 != check_token(reqparse.request.headers.get('token'))):
            abort(403)
            return
        else:
            return dev_api.dev_list_get(reqparse.request.json)

# get tool list
class GetToolList(Resource):
    def post(self):
        if (0 != check_token(reqparse.request.headers.get('token'))):
            abort(403)
            return
        else:
            return tool_api.tool_list_get(reqparse.request.json)

# get sence list
class GetSenceList(Resource):
    def post(self):
        if (0 != check_token(reqparse.request.headers.get('token'))):
            abort(403)
            return
        else:
            return sence_api.sence_list_get(reqparse.request.json)

# get link list
class GetLinkList(Resource):
    def post(self):
        if (0 != check_token(reqparse.request.headers.get('token'))):
            abort(403)
            return
        else:
            return link_api.link_list_get(reqparse.request.json)

##
## Actually setup the Api resource routing here
##
api.add_resource(GetBlogInfo,   '/iot/blog/info/get')
api.add_resource(GetDevList,    '/iot/dev/list/get')
api.add_resource(GetToolList,   '/iot/tool/list/get')
api.add_resource(GetSenceList,  '/iot/sence/list/get')
api.add_resource(GetLinkList,   '/iot/link/list/get')


if __name__ == '__main__':
    # init
    wx_api.wx_api_init()

    # 官方启动方式参见：http://flask.pocoo.org/docs/0.12/quickstart/#a-minimal-application
    app.run(host="127.0.0.1", port=8090, debug=True) #, ssl_context='adhoc')

<filename>main.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import Flask
from flask_restful import reqparse, abort, Api, Resource

import wx_api
import dev_api
import tool_api
import sence_api
import link_api

# Flask初始化参数尽量使用你的包名，这个初始化方式是官方推荐的，官方解释：http://flask.pocoo.org/docs/0.12/api/#flask.Flask
app = Flask(__name__)
api = Api(app)

token = '<PASSWORD>'

def check_token(token_in):
    if (not token_in):
        print ('not token')
        return -1
    elif (token_in != token):
        print('token error: ' + token_in)
        return -1
    else:
        return 0

# get blog info
class GetBlogInfo(Resource):
    def post(self):
        if (0 != check_token(reqparse.request.headers.get('token'))):
            abort(403)
            return
        else:
            return wx_api.wx_blog_info_get(reqparse.request.json)


# get dev list
class GetDevList(Resource):
    def post(self):
        if (0 != check_token(reqparse.request.headers.get('token'))):
            abort(403)
            return
        else:
            return dev_api.dev_list_get(reqparse.request.json)

# get tool list
class GetToolList(Resource):
    def post(self):
        if (0 != check_token(reqparse.request.headers.get('token'))):
            abort(403)
            return
        else:
            return tool_api.tool_list_get(reqparse.request.json)

# get sence list
class GetSenceList(Resource):
    def post(self):
        if (0 != check_token(reqparse.request.headers.get('token'))):
            abort(403)
            return
        else:
            return sence_api.sence_list_get(reqparse.request.json)

# get link list
class GetLinkList(Resource):
    def post(self):
        if (0 != check_token(reqparse.request.headers.get('token'))):
            abort(403)
            return
        else:
            return link_api.link_list_get(reqparse.request.json)

##
## Actually setup the Api resource routing here
##
api.add_resource(GetBlogInfo,   '/iot/blog/info/get')
api.add_resource(GetDevList,    '/iot/dev/list/get')
api.add_resource(GetToolList,   '/iot/tool/list/get')
api.add_resource(GetSenceList,  '/iot/sence/list/get')
api.add_resource(GetLinkList,   '/iot/link/list/get')


if __name__ == '__main__':
    # init
    wx_api.wx_api_init()

    # 官方启动方式参见：http://flask.pocoo.org/docs/0.12/quickstart/#a-minimal-application
    app.run(host="127.0.0.1", port=8090, debug=True) #, ssl_context='adhoc')

#!/usr/bin/env python # -*- coding: utf-8 -*- # Flask初始化参数尽量使用你的包名，这个初始化方式是官方推荐的，官方解释：http://flask.pocoo.org/docs/0.12/api/#flask.Flask # get blog info # get dev list # get tool list # get sence list # get link list ## ## Actually setup the Api resource routing here ## # init # 官方启动方式参见：http://flask.pocoo.org/docs/0.12/quickstart/#a-minimal-application #, ssl_context='adhoc')