Exemplo n.º 1
0
def _auto_control_light():
    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(LUMPORT, GPIO.IN)
    GPIO.setup(LIGHTPORT, GPIO.OUT)

    wc = WeiXinClient(my_appid, my_secret, fc=True, path='/tmp')
    wc.request_access_token()
    rjson = wc.user.get._get(next_openid=None)
    count = rjson.count
    id_list = rjson.data.openid
    while count < rjson.total:
        rjson = wc.user.get._get(next_openid=rjson.next_openid)
        count += rjson.count
        id_list.extend(rjson.openid)

    print id_list
    while flagal == 1:

        inputValue = GPIO.input(LUMPORT)
        if (inputValue == 0):
            #            print("THE LED IS OFF NOW")
            GPIO.output(LIGHTPORT, GPIO.LOW)

        else:
            #            print("THE LED IS ON NOW")
            GPIO.output(LIGHTPORT, GPIO.HIGH)

        time.sleep(1.0)
Exemplo n.º 2
0
 def __init__(self):
     self.app_root = os.path.dirname(__file__)
     self.templates_root = os.path.join(self.app_root, 'templates')
     self.render = web.template.render(self.templates_root)
     self.client = WeiXinClient(my_appid, my_secret, fc=True, path='/tmp')
     self.client.request_access_token()
     self.yee = YeeLinkClient(my_yeekey)
Exemplo n.º 3
0
 def __init__(self):
     self.app_root = os.path.dirname(__file__)
     self.templates_root = os.path.join(self.app_root, 'templates')
     self.render = web.template.render(self.templates_root)
     self.client = WeiXinClient('my_appid', \
             'my_secret', fc=False, path='192.168.1.12:11211')
     self.client.request_access_token()
     self.yee = YeeLinkClient('yee_key')
Exemplo n.º 4
0
 def __init__(self):
     self.app_root = os.path.dirname(__file__)
     self.templates_root = os.path.join(self.app_root, 'templates')
     self.render = web.template.render(self.templates_root)
     self.client = WeiXinClient('my_appid', 'my_secret')
     try:
         self.client.request_access_token()
     except Exception, e:
         self.client.set_access_token('ThisIsAFakeToken',
                                      1800,
                                      persistence=True)
Exemplo n.º 5
0
def _auto_control_body():
    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BOARD) 
    GPIO.setup(BODYPORT,GPIO.IN)

    wc = WeiXinClient(my_appid, my_secret, fc=True, path='/tmp')
    wc.request_access_token()
    rjson = wc.user.get._get(next_openid=None)
    count = rjson.count
    id_list = rjson.data.openid
    while count < rjson.total:
        rjson = wc.user.get._get(next_openid=rjson.next_openid)
        count += rjson.count
        id_list.extend(rjson.openid)
    # 最后看看都有哪些用户
    #print id_list
    
    while flagab == 1:
        print "alarm is working"
        inputValue = GPIO.input(BODYPORT)
        if(inputValue!=0):
            #发送报警文字
            for uid in id_list:
                content = '{"touser":"******", "msgtype":"text", "text":{ "content":"Waring! Somebody in your Room"}}' %uid
                #print 可以看有没有发送成功, 可以捕获api错误异常
                try:
                    print wc.message.custom.send.post(body=content)
                except APIError, e:
                    print e, uid

            url = 'http://127.0.0.1:8001/?action=snapshot'
            req = urllib2.Request(url)
            resp = urllib2.urlopen(req, timeout = 2)
            rjson = wc.media.upload.file(type='image', pic=resp)
            #print rjson
            # 把上传的图片发出去
            for uid in id_list:
                content = '{"touser":"******", "msgtype":"image", ' \
                    '"image":{ "media_id":"%s"}}' % (uid, rjson.media_id)
                try:
                    print wc.message.custom.send.post(body=content)
                except APIError, e:
                    print e, uid
Exemplo n.º 6
0
class WeixinServer:

    app_root = os.path.dirname(__file__)
    templates_root = os.path.join(app_root, 'templates')
    render = web.template.render(templates_root)
    wc_client = WeiXinClient('wxe3da4718bc1a9a18', \
            '2238eb7e0a13748039ec31f0309bbf68', fc = True, path = '.')
    lyric_client = LyricClient()

    def __init__(self):

        self.wc_client.request_access_token()


    def deal_with_text_impl(self, fromUser, toUser, content):

        user = getUserByName(fromUser)

        if user.mode == 'geci':

            return self.lyric_client.deal_with_text_impl(fromUser, toUser, content, self.wc_client)

        else:
            pass


        return '当前不处于歌词模式'


    def _recv_text(self, fromUser, toUser, doc):
        content = doc.find('Content').text

        reply_msg = self.deal_with_text_impl(fromUser, toUser, content)

        return self._reply_text(fromUser, toUser, reply_msg)

    def _recv_event(self, fromUser, toUser, doc):
        event = doc.find('Event').text
        try:
            return _weixin_event_table[event](self, fromUser, toUser, doc)
        except KeyError, e:
            print '_recv_event: %s' %e
            return self._reply_text(fromUser, toUser, u'Unknow event: '+event)
Exemplo n.º 7
0
def _auto_control_light():
    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BOARD) 
    GPIO.setup(LUMPORT,GPIO.IN)
    GPIO.setup(LIGHTPORT,GPIO.OUT)

    wc = WeiXinClient(my_appid, my_secret, fc=True, path='/tmp')
    wc.request_access_token()
    rjson = wc.user.get._get(next_openid=None)
    count = rjson.count
    id_list = rjson.data.openid
    while count < rjson.total:
        rjson = wc.user.get._get(next_openid=rjson.next_openid)
        count += rjson.count
        id_list.extend(rjson.openid)
    # 最后看看都有哪些用户
    #print id_list
    while flagal == 1:
        print "auto light is working"
        inputValue = GPIO.input(LUMPORT)
        if(inputValue==0):
            print("THE LED IS OFF NOW")
            GPIO.setup(LIGHTPORT,GPIO.HIGH)
            for uid in id_list:
                content = '{"touser":"******", "msgtype":"text", "text":{ "content":"The light already close"}}' %uid
                try:
                    print wc.message.custom.send.post(body=content)
                except APIError, e:
                    print e, uid
        else:
            print("THE LED IS ON NOW")
            GPIO.setup(LIGHTPORT,GPIO.LOW)
            for uid in id_list:
                content = '{"touser":"******", "msgtype":"text", "text":{ "content":"The light already open"}}' %uid
                try:
                    print wc.message.custom.send.post(body=content)
                except APIError, e:
                    print e, uid
Exemplo n.º 8
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from weixin import WeiXinClient

if __name__ == '__main__':
    wc = WeiXinClient('your_appid', 'your_secret', fc = True, path='/tmp')
    #"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET"
    wc.request_access_token()

    data = '{"touser":"******", "msgtype":"text", "text":{ "content":"hello!"}}'
    #data = '{"touser":"******", "msgtype":"image", ' \
    #    '"image":{ "media_id":"OaPSe4DP-HF4s_ABWHEVDgMKOPCUoViID8x-yPUvwCfqTEA0whZOza4hGODiHs93"}}'
    key = '{"button":[{"type":"click","name":"test","key":"V1001_TEST"}]}'
    #"https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN"
    print wc.message.custom.send.post(body=data)
    #"https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN"
    print wc.user.info.dget(openid='obMnLt43lgfeeC8Ljn4-cLixEW6Q', lang='zh_CN')
    #"https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN"
    print wc.message.custom.send.post(body=data)
    #"https://api.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&next_openid=NEXT_OPENID"
    print wc.user.get.dget(next_openid=None)
    #"http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE"
    print wc.media.upload.file(type='image', jpeg = open('./test.jpg', 'rb'))
    #"https://api.weixin.qq.com/cgi-bin/groups/create?access_token=ACCESS_TOKEN"
    print wc.groups.create.post(body='{"group":{"name":"test_group_01"}}')
    #"https://api.weixin.qq.com/cgi-bin/groups/update?access_token=ACCESS_TOKEN"
    print wc.groups.update.post(body='{"group":{"id":100,"name":"test"}}')
    #"https://api.weixin.qq.com/cgi-bin/groups/members/update?access_token=ACCESS_TOKEN"
    print wc.groups.members.update.post(body='{"openid":"obMnLt9Qx5ZfPdElO3DQblM7ksl0","to_groupid":100}')
    #"https://api.weixin.qq.com/cgi-bin/groups/getid?access_token=ACCESS_TOKEN"
Exemplo n.º 9
0
import time  #调入时间库
import os
from weixin import WeiXinClient
from weixin import APIError
from weixin import AccessTokenError

BODYPORT = 12
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(BODYPORT, GPIO.IN)

my_appid = ''
my_secret = ''

if __name__ == '__main__':
    wc = WeiXinClient(my_appid, my_secret, fc=True, path='/tmp')

    wc.request_access_token()
    rjson = wc.user.get._get(next_openid=None)
    count = rjson.count
    id_list = rjson.data.openid
    while count < rjson.total:
        rjson = wc.user.get._get(next_openid=rjson.next_openid)
        count += rjson.count
        id_list.extend(rjson.openid)
    # 最后看看都有哪些用户
    print id_list

    while True:
        inputValue = GPIO.input(BODYPORT)
        if (inputValue != 0):