基本信息
源码名称:微信小程序与ONENET通讯实例
源码大小:7.98KB
文件格式:.zip
开发语言:Java
更新时间:2019-01-05
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
可以实现ONENET互发数据,微信控制OneNET云设备demo

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
from datetime import date
from flask.views import View,MethodView
from flask import request, abort, jsonify, render_template, send_from_directory, make_response
from flask_web import app
from flask_web.plugins.led import red_led_on,red_led_off
class Index_view(MethodView):
    #methods = ['GET', 'POST']
    def get_template_name(self):
        raise NotImplementedError()
    def get(self):
        return render_template('index.html')
    def post(self):
        if request.is_json:
            data = request.json
            if data['red_led'] == 1:
                red_led_on()
            else :
                red_led_off()
            return make_response(jsonify({'Status': 'Successed'}), 200)
        return make_response(jsonify({'Status': 'Unauthorized Access'}), 403)

index_view = Index_view.as_view('index_view')
app.add_url_rule('/', view_func=index_view, methods=['GET', 'POST',])

class Static_view(MethodView):
    methods = ['GET']
    def get(self):
        return send_from_directory(app.static_folder, request.path[1:])

static_view = Static_view.as_view('static_view')
app.add_url_rule('/favicon.ico', view_func=static_view,methods=['GET'])
app.add_url_rule('/robots.txt', view_func=static_view,methods=['GET'])