Ejemplo n.º 1
0
def saveUserInfo(wechat, openid):
    '''
    create by bigzhu at 15/07/19 01:47:09 顺便绑定用户
    '''
    # 检查用户是否存储了,没有的话存之
    wechat_user_info = public_db.getWechatUserByOpenid(openid)
    if wechat_user_info:
        pass
    else:
        wechat_user_info = wechat.get_user_info(openid)
        pg.insert('wechat_user', **wechat_user_info)
Ejemplo n.º 2
0
def addWechatUser(openid):
    '''
    create by bigzhu at 15/04/08 21:07:54 检查用户是否存储了,没有的话存之
    '''
    wechat_user_info = public_db.getWechatUserByOpenid(openid)
    if wechat_user_info:
        pass
    else:
        wechat = getWechat()
        wechat_user_info = wechat.get_user_info(openid)
        pg.db.insert('wechat_user', **wechat_user_info)
Ejemplo n.º 3
0
def saveUserInfo(wechat, openid):
    '''
    create by bigzhu at 15/07/19 01:47:09 顺便绑定用户
    '''
    # 检查用户是否存储了,没有的话存之
    wechat_user_info = public_db.getWechatUserByOpenid(openid)
    if wechat_user_info:
        pass
    else:
        wechat_user_info = wechat.get_user_info(openid)
        pg.insert('wechat_user', **wechat_user_info)
 def done(response):
     with open("static/upload/images/" + message.media_id + ".jpg", "w") as f:
         f.write(response.body)
         print "DONE"
         downloadImageFile()
         # 检查用户是否存储了,没有的话存之
         wechat_user_info = public_db.getWechatUserByOpenid(message.source)
         if wechat_user_info:
             pass
         else:
             wechat_user_info = wechat.get_user_info(message.source)
             pg.db.insert("wechat_user", **wechat_user_info)
             pg.db.insert("upload_info", openid=message.source, media_id=message.media_id)
    def post(self):
        self.set_header("Content-Type", "application/json")

        wechat = wechat_oper.getWechat()

        wechat.parse_data(self.request.body)
        message = wechat.get_message()

        response = None
        if isinstance(message, TextMessage):
            # count = public_db.updateDescription(openid=message.source, desc=message.content)
            # if count == 1:
            #    response = wechat.response_text(content=u'描述已经添加,感谢您的举报.')
            # else:
            #    response = wechat.response_text(content=u'请先发送需要举报的照片')
            response = wechat.response_text(content=u'文字信息')

        elif isinstance(message, VoiceMessage):
            response = wechat.response_text(content=u'语音信息')
        elif isinstance(message, ImageMessage):

            # 需要下载图片
            def downloadImageFile():
                http_client = tornado.httpclient.AsyncHTTPClient()
                http_client.fetch(message.picurl, callback=done)

            def done(response):
                with open("static/upload/images/" + message.media_id + '.jpg', "w") as f:
                    f.write(response.body)
                print "DONE"
            downloadImageFile()
            # 检查用户是否存储了,没有的话存之
            wechat_user_info = public_db.getWechatUserByOpenid(message.source)
            if wechat_user_info:
                pass
            else:
                wechat_user_info = wechat.get_user_info(message.source)
                pg.db.insert('wechat_user', **wechat_user_info)
            pg.db.insert('upload_info', openid=message.source, media_id=message.media_id)

            response = wechat.response_text(content=u'图片已经保存,请继续向我们发送对图片的描述')
        elif isinstance(message, VideoMessage):
            response = wechat.response_text(content=u'视频信息')
        elif isinstance(message, LinkMessage):
            wechat_user_info = wechat.get_user_info(message.source)
            print wechat_user_info
            response = wechat.response_text(content=u'链接信息')
        elif isinstance(message, LocationMessage):
            response = wechat.response_text(content=u'地理位置信息')
        elif isinstance(message, EventMessage):  # 事件信息
            if message.type == 'subscribe':  # 关注事件(包括普通关注事件和扫描二维码造成的关注事件)
                print message.source
                if message.key and message.ticket:  # 如果 key 和 ticket 均不为空,则是扫描二维码造成的关注事件
                    response = wechat.response_text(content=u'用户尚未关注时的二维码扫描关注事件')
                else:
                    response = wechat.response_text(content=u'普通关注事件')
            elif message.type == 'unsubscribe':
                response = wechat.response_text(content=u'取消关注事件')
            elif message.type == 'scan':
                response = wechat.response_text(content=u'用户已关注时的二维码扫描事件')
            elif message.type == 'location':
                response = wechat.response_text(content=u'上报地理位置事件')
            elif message.type == 'click':
                response = wechat.response_text(content=u'自定义菜单点击事件')
            elif message.type == 'view':
                response = wechat.response_text(content=u'自定义菜单跳转链接事件')

        self.write(response)
Ejemplo n.º 6
0
    def post(self):
        self.set_header("Content-Type", "application/json")

        '''
        #to 7+1
        result = wechat_bz.callPlatform(self, url='http://admin.hoywe.com/api.php?hash=GO5KZ')
        self.write(result)
        return
        '''

        wechat = self.wechat

        wechat.parse_data(self.request.body)
        message = wechat.get_message()

        response = None
        if isinstance(message, TextMessage):
            #wechat.send_text_message(message.source, 'test')
            response = wechat.response_text(content=u'文字信息')

        elif isinstance(message, VoiceMessage):
            response = wechat.response_text(content=u'语音信息')
        elif isinstance(message, ImageMessage):

            # 需要下载图片
            def downloadImageFile():
                http_client = tornado.httpclient.AsyncHTTPClient()
                http_client.fetch(message.picurl, callback=done)

            def done(response):
                with open("static/upload/images/" + message.media_id + '.jpg', "w") as f:
                    f.write(response.body)
            downloadImageFile()
            # 检查用户是否存储了,没有的话存之
            wechat_user_info = public_db.getWechatUserByOpenid(message.source)
            if wechat_user_info:
                pass
            else:
                wechat_user_info = wechat.get_user_info(message.source)
                pg.insert('wechat_user', **wechat_user_info)
            pg.insert('upload_info', openid=message.source, media_id=message.media_id)

            response = wechat.response_text(content=u'图片已经保存,请继续向我们发送对图片的描述')
        elif isinstance(message, VideoMessage):
            response = wechat.response_text(content=u'视频信息')
        elif isinstance(message, LinkMessage):
            wechat_user_info = wechat.get_user_info(message.source)
            response = wechat.response_text(content=u'链接信息')
        elif isinstance(message, LocationMessage):
            response = wechat.response_text(content=u'地理位置信息')
        elif isinstance(message, EventMessage):  # 事件信息

            if message.type == 'subscribe':  # 关注事件(包括普通关注事件和扫描二维码造成的关注事件)
                if message.key and message.ticket:  # 如果 key 和 ticket 均不为空,则是扫描二维码造成的关注事件
                    user_name = message.key.replace('qrscene_', '')
                    wechat_oper.saveUserInfo(wechat, message.source)
                    wechat_oper.bindUser(user_name, message.source)
                    #response = wechat.response_text(content=u'用户尚未关注时的二维码扫描关注事件')
                    response = wechat.response_text(content=u'感谢你关注FollowCenter, %s follow 的动态信息将会发送到您的微信上' % user_name)
                else:
                    response = wechat.response_text(content=u'普通关注事件')
            elif message.type == 'unsubscribe':
                response = wechat.response_text(content=u'取消关注事件')
            elif message.type == 'scan':
                user_name = message.key
                wechat_oper.saveUserInfo(wechat, message.source)
                wechat_oper.bindUser(user_name, message.source)
                #response = wechat.response_text(content=u'用户已关注时的二维码扫描事件')
                response = wechat.response_text(content=u'成功与%s绑定, 其follow 的动态信息将会发送到您的微信上' % user_name)

            elif message.type == 'location':
                response = wechat.response_text(content=u'上报地理位置事件')
            elif message.type == 'click':
                response = wechat.response_text(content=u'自定义菜单点击事件')
            elif message.type == 'view':
                response = wechat.response_text(content=u'自定义菜单跳转链接事件')

        self.write(response)