Esempio 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)
Esempio n. 2
0
class weixinserver:

    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)
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(18, GPIO.OUT)
Esempio n. 3
0
class weixinserver:
    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)
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(18, GPIO.OUT)
class WeixinInterface:
    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')
        a = self.client.request_access_token()
Esempio n. 5
0
class WeixinInterface:
 
    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')
        a=self.client.request_access_token()
       
      
        
 
    def _recv_text(self, fromUser, toUser, xml):
        global open_door_flag
        global flag
        global times
        global data
        content = xml.find('Content').text
        reply_msg = content
	if open_door_flag==1:
            if reply_msg=='123' :
                flag=1 #open door ,motor open 
                open_door_flag=0
                atexit.register(GPIO.cleanup)    
                servopin = 21  
                GPIO.setmode(GPIO.BCM)  
                GPIO.setup(servopin, GPIO.OUT, initial=False)  
                p = GPIO.PWM(servopin,50) #50HZ  
                p.start(0)  
                for i in range(1,7):
                    p.ChangeDutyCycle(2.5) #设置转动角度  
                    time.sleep(0.02)                      #等该20ms周期结束  
                    p.ChangeDutyCycle(0)                  #归零信号
                return self._reply_text(fromUser, toUser, u'success' )
            else:
                times=times+1
                print times
                if times<=3:
                    return self._reply_text(fromUser, toUser, u'error')
                else:
                    open_door_flag=0
                    times =0
                    return self._reply_image(fromUser, toUser, data.media_id)
                    
        else:
            return self._reply_text(fromUser, toUser, u'我还不能理解你说的话:' + reply_msg)
        

    def _recv_event(self, fromUser, toUser, xml):
        event = xml.find('Event').text
        try:
            return _weixin_event_table[event](self, fromUser, toUser, xml)
        except KeyError, e:
            print '_recv_event: %s' %e
            return server._reply_text(fromUser, toUser, u'Unknow event: '+event)
Esempio n. 6
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
Esempio n. 7
0
class weixinserver:

    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('wxaece866e46e9d4a6', 'c104ddad7eef2e369acb1aee01bf8341')
        try:
            self.client.request_access_token()
            self.client.menu.delete.post()
            self.client.menu.create.post(body=menu)

        except Exception, e:
            self.client.set_access_token('ThisIsAFakeToken', 1800, persistence=True)
Esempio n. 8
0
class WeixinInterface:
 
    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()
        
	#定义接受处理
    def _recv_text(self, fromUser, toUser, xml):
        content = xml.find('Content').text
        reply_msg = content
		if reply_msg == u'截图':
			try:
				data = _take_snapshot('heiybb.**.cc', 1015, server.client)
			return self.render.reply_image(toUser, fromUser, int(time.time()), data.media_id)
		else:
			return self._reply_text(fromUser, toUser, u'真系唔知你UP么7喔:' + reply_msg)
Esempio n. 9
0
class WeixinInterface:
    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)

    def _recv_text(self, fromUser, toUser, xml):
        content = xml.find('Content').text
        reply_msg = content
        return self._reply_text(fromUser, toUser, u'我还不能理解你说的话:' + reply_msg)

    def _recv_event(self, fromUser, toUser, xml):
        event = xml.find('Event').text
        try:
            return _weixin_event_table[event](self, fromUser, toUser, xml)
        except KeyError, e:
            print '_recv_event: %s' % e
            return server._reply_text(fromUser, toUser,
                                      u'Unknow event: ' + event)
Esempio n. 10
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
Esempio n. 11
0
class WeixinInterface:
 
    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()

    

 

    def _recv_text(self, fromUser, toUser, xml):
        content = xml.find('Content').text
        openid = xml.find('FromUserName').text
        bdcheck_text = re.compile(r'#')
        #ubdcheck_text = re.compile(r'unlink')
        bdmatch = bdcheck_text.match(content)
        #ubdmatch = ubdcheck_text.match(content)
        if bdmatch:
            return _link_schoolid(self, fromUser, toUser, content, openid)
        elif content == '解绑':
            return _unlink_schoolid(self, fromUser, toUser, openid)
            #return self._reply_text(fromUser, toUser, u'啊!' )
            #return _do_change_ALARM_OFF(self, fromUser, toUser, xml)

        else:
            reply_msg = content
            return self._reply_text(fromUser, toUser, u'我还不能理解你说的话:' + reply_msg)
    
    def _recv_event(self, fromUser, toUser, xml):
        event = xml.find('Event').text
        try:
            return _weixin_event_table[event](self, fromUser, toUser, xml)
        except KeyError, e:
            print '_recv_event: %s' %e
            return self._reply_text(fromUser, toUser, u'Unknow event: '+event)
Esempio n. 12
0
class weixinserver:

    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('your_appid', \
                'your_secret', fc = False, path = '192.168.1.12:11211')
        self.client.request_access_token()
        self.yee = YeeLinkClient('yee_key')

    def _recv_text(self, fromUser, toUser, doc):
        content = doc.find('Content').text
        reply_msg = 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)
Esempio n. 13
0
class weixinserver:
    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('your_appid', \
                'your_secret', fc = False, path = '192.168.1.12:11211')
        self.client.request_access_token()
        self.yee = YeeLinkClient('yee_key')

    def _recv_text(self, fromUser, toUser, doc):
        content = doc.find('Content').text
        reply_msg = 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)
Esempio n. 14
0
class WeixinInterface:
 
    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)
        
 
    def _recv_text(self, fromUser, toUser, xml):
        content = xml.find('Content').text
        reply_msg = content
        return self._reply_text(fromUser, toUser, u'我还不能理解你说的话:' + reply_msg)
        

    def _recv_event(self, fromUser, toUser, xml):
        event = xml.find('Event').text
        try:
            return _weixin_event_table[event](self, fromUser, toUser, xml)
        except KeyError, e:
            print '_recv_event: %s' %e
            return server._reply_text(fromUser, toUser, u'Unknow event: '+event)
Esempio n. 15
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._get(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._get(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', pic = 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"
Esempio n. 16
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"