Exemplo n.º 1
0
    def POST(self):
        try:
            webData = web.data()
            print("Handle Post webdata is ", webData)

            recMsg = receive.parse_xml(webData)
            toUser = recMsg.FromUserName
            fromUser = recMsg.ToUserName

            if isinstance(recMsg, receive.Msg):
                if recMsg.MsgType == 'text':
                    content = "test"
                    print(toUser)
                    replyMsg = reply.TextMsg(toUser, fromUser, content)
                    return replyMsg.send()
                if recMsg.MsgType == "image":
                    mediaId = recMsg.MediaId
                    print(mediaId)
                    replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                    return replyMsg.send()
                # else:
                #    return reply.Msg().send()

            if isinstance(recMsg, receive.EventMsg):
                if recMsg.Event == 'CLICK':
                    if recMsg.Eventkey == 'mpGuide':
                        content = u"编写中".encode('utf8')
                        replyMsg = reply.TextMsg(toUser, fromUser, content)
                        return replyMsg.send()

            print("暂不处理")
            return reply.Msg().send()
        except Exception as e:
            return e
Exemplo n.º 2
0
 def POST(self):
     try:
         webData = web.data()
         print("Handle Post webdata is", webData)
         #后台打印日志
         recMsg = receive.parse_xml(webData)
         print(recMsg)
         if isinstance(recMsg, receive.Msg):
             print(recMsg)
             print(receive.Msg)
             toUser = recMsg.FromUserName
             fromUser = recMsg.ToUserName
             print(recMsg.MsgType)
             if recMsg.MsgType == 'text':
                 print("text")
                 content = recMsg.Content.decode('utf-8')
                 replyMsg = reply.TextMsg(toUser, fromUser, content)
                 return replyMsg.send()
             if recMsg.MsgType == 'image':
                 mediaId = recMsg.MediaId
                 print(mediaId)
                 print(11111111111111111)
                 replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                 print(replyMsg)
                 print(11111111111)
                 return replyMsg.send()
             else:
                 return reply.Msg().send()
         else:
             print("暂且不处理未识别的消息")
             return success
     except Exception as Argment:
         return Argment
Exemplo n.º 3
0
    def POST(self):
        try:
            webData = web.data()
            print('Handle POST webdata is ', webData)
            recMsg = receive.parse_xml(webData)
            if isinstance(recMsg, receive.Msg):
                toUser = recMsg.FromUserName
                fromUser = recMsg.ToUserName

                if recMsg.MsgType == 'text':
                    content = 'test'  #reply the massage
                    replyMsg = reply.TextMsg(toUser, fromUser, content)
                    return replyMsg.send()
                if recMsg.MsgType == 'image':
                    mediaId = recMsg.MediaId
                    replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                    return replyMsg.send()
                else:
                    print('暂不处理')
                    return 'success'

            if isinstance(recMsg, receive.EventMsg):
                toUser = recMsg.FromUserName
                fromUser = recMsg.ToUserName

                if recMsg.Event == 'CLICK':
                    content = u'尚未完成'.encode('utf-8')
                    replyMsg = reply.TextMsg(toUser, fromUser, content)
                    return replyMsg.send()
                else:
                    print('暂不处理')
                    return 'success'
        except Exception as Argment:
            return Argment
Exemplo n.º 4
0
    def POST(self):
        try:
            webData = web.data()
            print "Handle Post webdata is ", webData    #后台打日志
            
            recMsg = receive.parse_xml(webData)
            if isinstance(recMsg, receive.Msg):

                if recMsg.MsgType == 'text':
                    toUser = recMsg.FromUserName
                    fromUser = recMsg.ToUserName
                    content = "You told me:" + recMsg.Content + ",thanks!"
                    replyMsg = reply.TextMsg(toUser, fromUser, content)
                return replyMsg.send()

                if recMsg.MsgType == 'image':
                    toUser = recMsg.FromUserName
                    fromUser = recMsg.ToUserName
                    mediaId = recMsg.MediaId
                    replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                    return replyMsg.send()
                else:
                    return reply.Msg().send()

            else:
                print "暂且不处理"
                return "success"
        except Exception, Argment:
            return Argment
Exemplo n.º 5
0
 def POST(self):
     try:
         webData = web.data()
         print "Handle Post webdata is ", webData
         # 后台打日志
         recMsg = receive.parse_xml(webData)
         if isinstance(recMsg, receive.Msg):
             toUser = recMsg.FromUserName
             fromUser = recMsg.ToUserName
             if recMsg.MsgType == 'text':
                 content = "text reply"
                 replyMsg = reply.TextMsg(toUser, fromUser, content)
                 return replyMsg.send()
             elif recMsg.MsgType == 'image':
                 mediaId = recMsg.MediaId
                 replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                 return replyMsg.send()
             elif recMsg.MsgType == 'location':
                 msgId = recMsg.MsgId
                 replyMsg = reply.LocationMsg(toUser, fromUser, msgId)
                 print "位置信息"
                 return replyMsg.send()
             else:
                 print "暂且不处理"
                 return "success"
     except Exception, Argment:
         return Argment
Exemplo n.º 6
0
 def POST(self):
     try:
         webData = web.data()
         print("Handle Post webdata is :", webData)
         #后台打日志
         recMsg = receive.parse_xml(webData)
         if isinstance(recMsg, receive.Msg):
             toUser = recMsg.FromUserName
             fromUser = recMsg.ToUserName
             recv_content = recMsg.Content.decode()
             if recMsg.MsgType == 'text':
                 print('recv:', recv_content)
                 ans = agent.search(recv_content)
                 #print('ans:',ans)
                 #content = "公众号test"
                 replyMsg = reply.TextMsg(toUser, fromUser, ans)
                 return replyMsg.send()
             if recMsg.MsgType == 'image':
                 mediaId = recMsg.MediaId
                 replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                 return replyMsg.send()
             else:
                 return reply.Msg().send()
         else:
             print("暂且不处理")
             return reply.Msg().send()
     except Exception as Argment:
         return Argment
Exemplo n.º 7
0
 def POST(self):
     try:
         webData = web.data()
         print
         "Handle Post webdata is ", webData  # 后台打日志
         recMsg = receive.parse_xml(webData)
         if isinstance(recMsg, receive.Msg):
             toUser = recMsg.FromUserName
             fromUser = recMsg.ToUserName
             if recMsg.MsgType == 'text':
                 content = "test"
                 replyMsg = reply.TextMsg(toUser, fromUser, content)
                 return replyMsg.send()
             if recMsg.MsgType == 'image':
                 mediaId = recMsg.MediaId
                 replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                 return replyMsg.send()
             else:
                 return reply.Msg().send()
         else:
             print
             "暂且不处理"
             return reply.Msg().send()
     except Exception as e:
         print(e)
Exemplo n.º 8
0
 def POST(self):
     try:
         webData = web.data()
         print "Handle Post webdata is ", webData  # 后台打日志
         recMsg = receive.parse_xml(webData)
         if isinstance(recMsg, receive.Msg):
             toUser = recMsg.FromUserName
             fromUser = recMsg.ToUserName
             if recMsg.MsgType == 'text':
                 content = recMsg.Content
                 replyMsg = reply.TextMsg(toUser, fromUser, content)
                 return replyMsg.send()
             if recMsg.MsgType == 'image':
                 mediaId = recMsg.MediaId
                 replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                 return replyMsg.send()
         if isinstance(recMsg, receive.EventMsg):
             toUser = recMsg.FromUserName
             fromUser = recMsg.ToUserName
             if recMsg.Event == 'CLICK':
                 if recMsg.Eventkey == 'mpGuide':
                     content = u"编写中,尚未完成".encode('utf-8')
                     replyMsg = reply.TextMsg(toUser, fromUser, content)
                     return replyMsg.send()
         print "暂且不处理"
         return reply.Msg().send()
     except Exception, Argment:
         return Argment
Exemplo n.º 9
0
 def POST(self):
     try:
         webData = web.data()
         print("Handle Post webdata is ", webData)
         #后台打日志
         recMsg = receive.parse_xml(webData)
         if isinstance(recMsg, receive.Msg):
             toUser = recMsg.FromUserName
             fromUser = recMsg.ToUserName
             if recMsg.MsgType == 'text':
                 content = "test"
                 replyMsg = reply.TextMsg(toUser, fromUser, content)
                 return replyMsg.send()
             if recMsg.MsgType == 'image':
                 mediaId = recMsg.MediaId
                 replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                 return replyMsg.send()
             if isinstance(recMsg, receive.EventMsg):
                 if recMsg.Event == 'CLICK':
                     if recMsg.Eventkey == 'jidai_location':
                         replyMsg = reply.TextMsg(
                             toUser, fromUser,
                             "广隆吉大店\n0756-3228782\n珠海市香洲区\n吉大石花东路203号")
                     if recMsg.Eventkey == 'jinji_location':
                         replyMsg = reply.TextMsg(
                             toUser, fromUser,
                             "广隆前山店\n0756-8652111\n珠海市香洲区\n前山金鸡路路555号")
                     return replyMsg.send()
         else:
             print("暂且不处理")
             return "success"
     except Exception as Argment:
         return Argment
Exemplo n.º 10
0
    def POST(self):
        try:
            webData = web.data()
            print("Handle post web data is:", webData)
            recvMsg = receive.parse_xml(webData)

            if isinstance(recvMsg, receive.Msg):
                toUser = recvMsg.FromUserName
                fromUser = recvMsg.ToUserName
                if recvMsg.MsgType == 'text':
                    replyMsg = reply.TextMsg(toUser, fromUser, recvMsg.Content)
                    textMsg = replyMsg.send()
                    print("Return to WeChat Msg is :", textMsg)
                    return textMsg
                if recvMsg.MsgType == 'image':
                    mediaId = recvMsg.MediaId
                    replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                    imageMsg = replyMsg.send()
                    return imageMsg
                else:
                    return reply.Msg().send()

            if isinstance(recvMsg, receive.EventMsg):
                if recvMsg.Event == 'CLICK':
                    if recvMsg.EventKey == 'mpGuide':
                        content = u'编写中,尚未完成'.encode('utf-8')
                        replyMsg = reply.TextMsg(toUser, fromUser, content)
                        return replyMsg.send()
            print("暂不处理......")
            return reply.Msg().send()
        except Exception, Argment:
            print("[ERROR]: except Exception!!!!:", Argment)
            return Argment
Exemplo n.º 11
0
 def POST(self):
     try:
         webData = web.data()
         mylog = log.Mylog()
         mylog.printToLog("########\n[info]Handle Post webdata is " +
                          webData.decode('utf-8') + "\n########\n")
         recMsg = receive.parse_xml(webData.decode())
         if isinstance(recMsg, receive.Msg):
             toUser = recMsg.FromUserName
             fromUser = recMsg.ToUserName
             if recMsg.MsgType == 'text':
                 replyMsg = keyword_reply.parse_keyword(recMsg.Content)
                 return replyMsg.send(toUser, fromUser)
             if recMsg.MsgType == 'image':
                 mediaId = recMsg.MediaId
                 replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                 return replyMsg.send()
             if recMsg.MsgType == 'link':
                 replyMsg = custom_reply.parse_link(recMsg.Description)
                 #url=shorter(recMsg.Url)
                 #print(url)
                 replyMsg.update(toUser, recMsg.Url)
                 return replyMsg.send(toUser, fromUser)
             else:
                 return reply.Msg().send()
         else:
             mylog.printToLog("暂且不处理")
             return reply.Msg().send()
     except Exception as Argument:
         return Argument
Exemplo n.º 12
0
 def POST(self):
     try:
         webdata = web.data()
         print("Handle Post webdata is ", webdata)
         print('hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh')
         #后台打日志
         print('hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh')
         recMsg = receive.parse_xml(webdata)
         print("isinstance Msg", isinstance(recMsg, receive.Msg))
         print(type(recMsg))
         print("length of webdata", len(webdata))
         if isinstance(recMsg, receive.Msg):
             toUser = recMsg.FromUserName
             fromUser = recMsg.ToUserName
             if recMsg.MsgType == 'text':
                 content = 'test'
                 replyMsg = reply.TextMsg(toUser, fromUser, content)
                 return replyMsg.send()
             if recMsg.MsgType == 'image':
                 mediaId = recMsg.MediaId
                 replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                 print(type(replyMsg))
                 return replyMsg.send()
             else:
                 return reply.Msg().send()
         else:
             print("暂且不处理")
             return reply.Msg().send()
     except Exception, Argument:
         return Argument
Exemplo n.º 13
0
 def POST(self):
     try:
         webData = web.data()
         print("Handle Post webdata is ", webData)
         recMsg = receive.parse_xml(webData)
         if isinstance(recMsg, receive.Msg):
             toUser = recMsg.FromUserName
             fromUser = recMsg.ToUserName
             if recMsg.MsgType == 'text':
                 rec_text = recMsg.Content.decode('utf-8')
                 print('the input is: ', rec_text)
                 content = db_test.reply_result(rec_text) # 调用查询数据库程序
                 replyMsg = reply.TextMsg(toUser, fromUser, content)
                 return replyMsg.send()
             if recMsg.MsgType == 'image':
                 mediaId = recMsg.MediaId
                 replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                 return replyMsg.send()
             if recMsg.MsgType == 'event':
                 event = recMsg.Event
                 if event == 'subscribe':  # 判断如果是关注则进行回复
                     content = "您好,欢迎关注!发送数字‘1’即可获得当前浴室排队情况;发送数字‘2’即可获得当前水房排队情况。"
                     replyMsg = reply.TextMsg(toUser, fromUser, content)
                     return replyMsg.send()
         else:
             print("暂且不处理")
             return "success"
     except Exception as Argment:
         return Argment
Exemplo n.º 14
0
 def POST(self):
     try:
         webData = web.data()
         recMsg = receive.parse_xml(webData)
         if isinstance(recMsg, receive.Msg):
             toUser = recMsg.FromUserName
             fromUser = recMsg.ToUserName
             if recMsg.MsgType == 'text':
                 content = auoth.Text(toUser, recMsg.Content)  #自动回复接口
                 replyMsg = reply.TextMsg(toUser, fromUser, content)
                 return replyMsg.send()
             if recMsg.MsgType == 'image':
                 mediaId = recMsg.MediaId
                 replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                 return replyMsg.send()
         #if isinstance(recMsg,receive.EventMsg):        #菜单
         #    if recMsg.Event=='CLICK':
         #        if recMsg.Eventkey =='mpGuide':
         #            content=u"编写中,尚未完成"
         #            reply=reply.TextMsg(toUser,fromUser,content)
         #            return reply.send()
         else:
             print "暂不处理"
             return reply.Msg().send()
     except Exception, Argument:
         return Argument
Exemplo n.º 15
0
    def POST(self):
        try:
            webData = web.data()
            print "Handle Post webdata is \n", webData  # 打印后台日志
            recMsg = receive.parse_xml(webData)

            if isinstance(recMsg, receive.Msg):
                toUser = recMsg.FromUserName
                fromUser = recMsg.ToUserName
                if recMsg.MsgType == 'text':
                    content = recMsg.Content
                    replyMsg = reply.TextMsg(toUser, fromUser, content)
                    return replyMsg.send()
                if recMsg.MsgType == 'image':
                    mediaId = recMsg.MediaId
                    replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                    return replyMsg.send()
                else:
                    return reply.Msg().send()

            if isinstance(recMsg, receive.EventMsg):
                toUser = recMsg.FromUserName
                fromUser = recMsg.ToUserName
                if recMsg.Event == 'CLICK':
                    print 'It is a CLICK event'
                    content = u'功能正在开发中,敬请期待..'.encode('utf-8')
                    replyMsg = reply.TextMsg(toUser, fromUser, content)
                    return replyMsg.send()

            print "暂且不处理"
            return reply.Msg().send()

        except Exception, Argment:
            return Argment
Exemplo n.º 16
0
 def POST(self):
     try:
         webData = web.data()
         print("Handle Post webdata is %s" % webData)  #后台打日志
         recMsg = receive.parse_xml(webData)
         #print(str(isinstance(recMsg, Msg)))
         #print(str(recMsg.MsgType))
         print("recMsg instanceof receive.Msg :%s, recMsg.MsgType:%s" %
               (str(isinstance(recMsg, Msg)), str(recMsg.MsgType)))
         if isinstance(recMsg, Msg):
             toUser = recMsg.FromUserName
             fromUser = recMsg.ToUserName
             if recMsg.MsgType == 'text':
                 handle_mess = HandleMessage()
                 print(recMsg.Content)
                 content = handle_mess.handle_message(recMsg.Content)
                 print("##########:" + content)
                 replyMsg = reply.TextMsg(toUser, fromUser, content)
                 print("toUser:%s,fromUser:%s,info:%s" %
                       (str(toUser), str(fromUser), str(
                           recMsg.Content).encode("utf-8")))
                 return replyMsg.send()
             if recMsg.MsgType == 'image':
                 mediaId = recMsg.MediaId
                 replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                 return replyMsg.send()
             else:
                 return reply.Msg().send()
         else:
             print("暂且不处理")
             return reply.Msg().send()
     except Exception as ar:
         return ar
Exemplo n.º 17
0
 def POST(self):
     try:
         webData = web.data()
         recMsg = receive.parse_xml(webData)
         if isinstance(recMsg, receive.Msg):
             toUser = recMsg.FromUserName
             fromUser = recMsg.ToUserName
             if recMsg.MsgType == 'text':
                 content = recMsg.reply()
                 render = web.template.render('templates/')
                 return render.reply_text(fromUser, \
                  toUser, int(time.time()), content)
                 replyMsg = reply.TextMsg(toUser, \
                  fromUser, content)
                 return replyMsg.send()
             elif recMsg.MsgType == 'image':
                 mediaId = recMsg.MediaId
                 replyMsg = reply.ImageMsg(toUser, \
                  fromUser, mediaId)
                 return replyMsg.send()
             else:
                 return reply.Msg().send()
         else:
             print "暂且不处理"
             return "success"
     except Exception, Argment:
         return Argment
Exemplo n.º 18
0
    def POST(self):
        try:
            token = Basic().get_access_token()
            print(token)
            webData = web.data()
            recMsg = receive.parse_xml(webData)
            if isinstance(recMsg, receive.Msg):
                toUser = recMsg.FromUserName
                fromUser = recMsg.ToUserName
                if recMsg.MsgType == 'text':
                    content = "欢迎光临!"
                    replyMsg = reply.TextMsg(toUser, fromUser, content)
                    return replyMsg.send()
                if recMsg.MsgType == 'image':
                    mediaId = recMsg.MediaId
                    replyImageMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                    return replyImageMsg.send()
                else:
                    return reply.Msg().send()

            else:
                print("暂且不处理")
                return reply.Msg().send()
        except  Exception as Argment:
            print(Argment)
            return Argment
Exemplo n.º 19
0
 def POST(self):
     try:
         webData = web.data()
         print "Handle Post webdata is ", webData   #后台打日志
         recMsg = receive.parse_xml(webData)
         xml = etree.fromstring(webData)
         #进行XML解析
         if isinstance(recMsg, receive.Msg):
             toUser = recMsg.FromUserName
             fromUser = recMsg.ToUserName
             if recMsg.MsgType == 'text':
                 #content = recMsg.Content
                 Content = xml.find("Content").text
                 replyMsg = reply.TextMsg(toUser, fromUser, content)
                 return replyMsg.send()
             if recMsg.MsgType == 'image':
                 mediaId = recMsg.MediaId
                 replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                 return replyMsg.send()
             else:
                 return reply.Msg().send()
         else:
             print "暂且不处理"
             return reply.Msg().send()
     except Exception, Argment:
         return Argment
Exemplo n.º 20
0
    def POST(self):
        webData = web.data()
        recMsg = receive.parse_xml(webData)
        # 自动回复功能:
        # if isinstance(recMsg, receive.Msg) and recMsg.MsgType == 'text':
        #     toUser = recMsg.FromUserName
        #     fromUser = recMsg.ToUserName
        #     content = '您好!我是平台管理员,有任何问题或建议都联系我15305170962(微信同号)'
        #     replyMsg = reply.TextMsg(toUser, fromUser, content)
        #     return replyMsg.send()

        if isinstance(recMsg, receive.Msg) and recMsg.MsgType == 'image':
            toUser = recMsg.FromUserName
            fromUser = recMsg.ToUserName
            mediaID = recMsg.MediaId
            replyMsg = reply.ImageMsg(toUser,fromUser,mediaID)
            return replyMsg.send()
        
        elif isinstance(recMsg, receive.Msg) and recMsg.MsgType == 'event' and recMsg.Event == 'CLICK' and recMsg.EventKey == 'SendInfo':
            toUser = recMsg.FromUserName
            fromUser = recMsg.ToUserName
            content = '您好!我是平台管理员,有任何问题或建议都联系我15305170962(微信同号)' 
            replyMsg = reply.TextMsg(toUser, fromUser, content)
            return replyMsg.send()

        else:
            return "success"
Exemplo n.º 21
0
 def POST(self):
     global eventEngine, eventHandle, question, answer
     try:
         eventEngine.set()
         webData = web.data()
         #print "Handle Post webdata is ", webData   #后台打日志
         recMsg = receive.parse_xml(webData)
         if isinstance(recMsg, receive.Msg):
             toUser = recMsg.FromUserName
             fromUser = recMsg.ToUserName
             if recMsg.MsgType == 'text':
                 print recMsg.Content
                 question = recMsg.Content
                 eventEngine.set()
                 eventHandle.wait()
                 eventHandle.clear()
                 content = answer.strip()
                 replyMsg = reply.TextMsg(toUser, fromUser, content)
                 return replyMsg.send()
             if recMsg.MsgType == 'image':
                 mediaId = recMsg.MediaId
                 replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                 return replyMsg.send()
             else:
                 return reply.Msg().send()
         else:
             print "暂且不处理"
             return "success"
     except Exception, Argment:
         return Argment
Exemplo n.º 22
0
 def POST(self):
     try:
         webData = web.data()
         #后台打印
         print('handle POST webdata', webData)
         recMsg = receive.parse_xml(webData)
         if isinstance(recMsg, receive.Msg):
             toUser = recMsg.FromUserName
             fromUser = recMsg.ToUserName
             if recMsg.MsgType == 'text':
                 content = u"客服暂未开放,如需帮助请点击菜单旗舰店联系客服,或者拨打售后服务热线400-820-6276".encode(
                     'utf-8')
                 replyMsg = reply.TextMsg(toUser, fromUser, content)
             if recMsg.MsgType == 'image':
                 mediaId = recMsg.MediaId
                 replyMsg = reply.ImageMsg(toUser, fromUser, content)
             return replyMsg.send()
         if isinstance(recMsg, receive.EventMsg):
             toUser = recMsg.FromUserName
             fromUser = recMsg.ToUserName
             print(recMsg.Event, recMsg.EventKey)
             if recMsg.Event == 'CLICK':
                 if recMsg.EventKey == 'zbf':
                     content = u"编写中".encode('utf-8')
                     replyMsg = reply.TextMsg(toUser, fromUser, content)
                     return replyMsg.send()
         else:
             print('not handle now')
             return reply.Msg().send()
     except Exception, e:
         return e
Exemplo n.º 23
0
 def POST(self):
     try:
         webData = web.data()
         print "接收客户信息:\n", webData
         # 后台打日志
         recMsg = receive.parse_xml(webData)#处理接收微信发过来的信息
         if isinstance(recMsg, receive.Msg):
             toUser = recMsg.FromUserName
             fromUser = recMsg.ToUserName
             recvtext = recMsg.Content#接收发送的信息
             if recMsg.MsgType == 'text':
                 try:
                     if recvtext.isdigit():#判断接收的是数字还是字符串
                         #连接数据库获取评论信息
                         content = NetSQL.sqlitetest(recvtext)['txt'].encode('utf8') + "\n\n\n------来自网易云音乐评论------\n    %s" % (
                         NetSQL.sqlitetest(recvtext)['footer'].encode('utf8'))#不转码报错ASCII
                         print(content)
                         #new对象
                         replyMsg = reply.TextMsg(toUser, fromUser, content)
                         return replyMsg.send()#调用方法发送
                     else:
                         content = "请发送数字:1-104180\nhttp://daydayup11.cn/"
                         replyMsg = reply.TextMsg(toUser, fromUser, content)
                         return replyMsg.send()#发送XML格式数据
                 except Exception,e:
                     print("SendERR:",e)
             if recMsg.MsgType == 'image':
                 mediaId = recMsg.MediaId
                 replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                 return replyMsg.send()
             else:
                 return reply.Msg().send()
         else:
Exemplo n.º 24
0
 def POST(self):
     try:
         webData = web.data()
         print('Handle Post webdata is ', webData)
         recMsg = receive.parse_xml(webData)
         if isinstance(recMsg, receive.Msg) and recMsg.MsgType == 'text':
             print('this is a text message')
             toUser = recMsg.FromUserName
             fromUser = recMsg.ToUserName
             content = "你好,这是平平的背包,现在在试验阶段。"
             replyMsg = reply.TextMsg(toUser, fromUser, content)
             #print(replyMsg)
             return replyMsg.send()
         elif isinstance(recMsg, receive.Msg) and recMsg.MsgType == 'image':
             print('this is a image mesage')
             toUser = recMsg.FromUserName
             fromUser = recMsg.ToUserName
             mediaId = recMsg.MediaId
             #picUrl = recMsg.PicUrl
             #print('the message from ', toUser)
             #print('the message to ', fromUser)
             #print('the MediaID is', mediaId)
             #print('the picUrl is ', picUrl)
             #content = "你好,这是平平的背包,现在在试验阶段。"
             #replyMsg = reply.TextMsg(toUser, fromUser, content)
             replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
             #print(replyMsg)
             return replyMsg.send()
         else:
             print ("暂且不处理")
             return "success"
     except Exception as Argment:
         return Argment
Exemplo n.º 25
0
    def POST(self):
        try:
            webData = web.data()
            print "Handle Post webdata is ", webData   #后台打日志
            recMsg = receive.parse_xml(webData)
            if isinstance(recMsg, receive.Msg):
                toUser = recMsg.FromUserName
                fromUser = recMsg.ToUserName
                if recMsg.MsgType == 'text':
                    queryUser = recMsg.Content
                    if queryUser in msgs.keys():
                      if msgs[queryUser]:
                        content = msgs[queryUser].pop();
                      else:
                        content = 'there is no msg for ' + queryUser
                    else:
                      content = 'there is no msg for ' + queryUser

                    replyMsg = reply.TextMsg(toUser, fromUser, content)
                    return replyMsg.send()
                if recMsg.MsgType == 'image':
                    mediaId = recMsg.MediaId
                    replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                    return replyMsg.send()
                else:
                    return reply.Msg().send()
            else:
                print "暂且不处理"
                return reply.Msg().send()
        except Exception, Argment:
            return Argment
Exemplo n.º 26
0
    def POST(self):
        try:
            webData = web.data()
            print "Handle Post webdata is ", webData  # 后台打印日志
            recMsg = receive.parse_xml(webData)  # 解析webData
            if isinstance(recMsg, receive.Msg):  # 若recMsg为消息类
                toUser = recMsg.FromUserName
                fromUser = recMsg.ToUserName
                print recMsg.MsgType
                if recMsg.MsgType == 'text':
                    content = recMsg.Content
                    picPath = "/home/pi/media/%s.jpg" % content
                    #print "content is %s"%content
                    #print "picPath is %s"%picPath
                    # 若名为content的图片存在,且大小小于2M,则上传到临时素材,获得mediaId
                    if os.path.exists(
                            picPath) and os.path.getsize(picPath) < 2097152:
                        print "Sending picture %s.jpg, size: %sB" % (
                            content, os.path.getsize(picPath))
                        myMedia = Media()
                        accessToken = Basic().get_access_token()
                        mediaType = "image"
                        mediaId = myMedia.upload(accessToken, picPath,
                                                 mediaType)
                        # 发送图片
                        replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                        return replyMsg.send()
                    else:
                        print "%s not valid" % picPath
                        return "success"
                else:
                    return "success"

            elif isinstance(recMsg, receive.Evt):  # 若recMsg为事件类
                toUser = recMsg.FromUserName
                fromUser = recMsg.ToUserName
                print recMsg.Event
                # 若事件类型为订阅,发送使用提示
                if recMsg.Event == 'subscribe':
                    #print "Sending qrcode..."
                    # 获取accessToken,上传临时素材
                    #myMedia = Media()
                    #accessToken = Basic().get_access_token()
                    #filePath = "/home/pi/media/qrcode.png"
                    #mediaType = "image"
                    #mediaId = myMedia.upload(accessToken, filePath, mediaType)
                    # 发送二维码
                    # replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                    # return replyMsg.send()
                    content = "共享拍立得:请发送图片码获取图片"
                    replyMsg = reply.TextMsg(toUser, fromUser, content)
                    return replyMsg.send()
                else:
                    return "success"
            else:
                print "No action"
                return "success"
        except Exception, Argument:
            return Argument
Exemplo n.º 27
0
    def POST(self):
        try:
            webData = web.data()
            print("Handle Post webData is ", webData)

            recMsg = receive.parse_xml(webData)
            if isinstance(recMsg, receive.Msg):
                toUser = recMsg.FromUserName
                fromUser = recMsg.ToUserName
                if recMsg.MsgType == 'text':
                    content = response(recMsg.Content)
                    if content == '':
                        content = '没有查询到序号对应内容\n回复0可查询菜单主页'
                    if isinstance(content, dict):
                        responseType = content['type']
                        if responseType == 'text':
                            replyMsg = reply.TextMsg(toUser, fromUser,
                                                     content['content'])
                        elif responseType == 'image':
                            replyMsg = reply.ImageMsg(toUser, fromUser,
                                                      content['id'])
                        elif responseType == 'news':
                            replyMsg = reply.NewsMsg(toUser, fromUser,
                                                     **content)
                    else:
                        replyMsg = reply.TextMsg(toUser, fromUser, content)
                    return replyMsg.send()
                elif recMsg.MsgType == 'image':
                    mediaId = recMsg.MediaId
                    replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                    return replyMsg.send()
                elif recMsg.MsgType == 'event':
                    if recMsg.EventType == 'subscribe':  #订阅事件
                        pre = '欢迎关注无名小屋\n'
                        content = response('0') + '\n'
                        end = '回复序号即可获取下级菜单或详情'
                        content = pre + content + end
                        replyMsg = reply.TextMsg(toUser, fromUser, content)
                        return replyMsg.send()
            else:
                print('不处理')
                return 'success'

        except BaseException as e:
            print('Error:', e)
            return 'Error'
Exemplo n.º 28
0
 def POST(self):
     try:
         webData = web.data()
         print "Handle Post webdata is ", webData
         recMsg = receive.parse_xml(webData)
         if isinstance(recMsg, receive.Msg):
             toUser = recMsg.FromUserName
             fromUser = recMsg.ToUserName
             if recMsg.MsgType == 'text':
                 content = recMsg.Content
                 with open('./files/handle.txt', 'a') as f:
                     f.write('%s%s\n' % (toUser, content))
                 if content.strip() == "菜单":
                     content = "这是一个菜单\n输入1:查看历史消息\n输入2:查看历史图片"
                 elif content.strip() == "1":
                     content = os.popen(
                         "cat ./files/handle.txt | grep %s | tail -n 100 | awk -F '%s' '{print $2}'"
                         % (toUser, toUser)).read()[:-1]
                 elif content.strip() == "2":
                     mediaId = os.popen(
                         "cat ./files/images.txt | grep %s | tail -n 1 | awk -F '%s' '{print $2}'"
                         % (toUser, toUser)).read()[:-1]
                     if mediaId == "":
                         #mediaId = "ko6zjMTgHhXFSy2p8W4eupv9v6EVjidxvzta4rHcmaovSxVzREoDxa1MBl89Sotu"
                         mediaId = "1Plaf_sgdmVbg5Au_IzUfy_d20BvpQ05x0tSoJaBqtFH5aGB0eTyez6Uh48BSNNC"
                     replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                     return replyMsg.send()
                 elif content.strip() == "3":
                     content = "你真漂亮!"
                 replyMsg = reply.TextMsg(toUser, fromUser, content)
                 return replyMsg.send()
             if recMsg.MsgType == 'image':
                 mediaId = recMsg.MediaId
                 with open('./files/images.txt', 'a') as f:
                     f.write('%s%s\n' % (toUser, mediaId))
                 replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                 return replyMsg.send()
             else:
                 return reply.Msg().send()
         else:
             print "暂且不处理"
             return reply.Msg().send()
     except Exception, Argment:
         return Argment
Exemplo n.º 29
0
def responseImg(recMsg):
    toUser = recMsg.FromUserName
    fromUser = recMsg.ToUserName

    mediaId = recMsg.MediaId
    media.saveImg(mediaId, config.temppath + mediaId + '.jpg')
    revImg(temppath + mediaId + '.jpg',
           config.temppath + mediaId + '_flip.jpg')
    mid = media.uploadImg(config.temppath + mediaId + '_flip.jpg')
    replyMsg = reply.ImageMsg(toUser, fromUser, mid)
    return replyMsg.send()
Exemplo n.º 30
0
 def POST(self):
     try:
         webData = web.data()
         print "Handle Post webdata is \n", webData  # 后台打印日志
         recMsg = receive.parse_xml(webData)
         if isinstance(recMsg, receive.EventMsg):
             toUser = recMsg.FromUserName
             fromUser = recMsg.ToUserName
             if recMsg.Event == 'subscribe':
                 content = '你好,这个公众号还未开化哦'
                 replyMsg = reply.TextMsg(toUser, fromUser, content)
                 return replyMsg.send()
         elif isinstance(recMsg, receive.Msg):
             toUser = recMsg.FromUserName
             fromUser = recMsg.ToUserName
             if recMsg.MsgType == 'text':
                 print recMsg.Content
                 content = Tuling(recMsg.Content).reply().encode('utf8')
                 print content
                 if recMsg.Content == '智障':
                     content = '666'
                 elif recMsg.Content == '我是智障':
                     title = '中秋快乐'
                     description = '惊不惊喜'
                     picUrl = 'http://pic33.nipic.com/20130923/11927319_180343313383_2.jpg'
                     url = 'http://www.umi101108.com'
                     replyMsg = reply.TextImageMsg(toUser, fromUser, title,
                                                   description, picUrl, url)
                     return replyMsg.send()
                 elif recMsg.Content == '电影':
                     piaofang = Cbooo().getPiaofang()
                     replyMsg = reply.MultiTextImageMsg(
                         toUser, fromUser, piaofang, 5)
                     return replyMsg.send()
                 replyMsg = reply.TextMsg(toUser, fromUser, content)
                 return replyMsg.send()
             elif recMsg.MsgType == 'image':
                 mediaId = recMsg.MediaId
                 PicUrl = recMsg.PicUrl
                 try:
                     content = How_old().getAttributes(PicUrl)
                     print content
                     replyMsg = reply.TextMsg(toUser, fromUser, content)
                 except:
                     replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
                 return replyMsg.send()
             else:
                 return reply.Msg().send()
         else:
             print "暂且不处理"
             return reply.Msg().send()
     except Exception, Argument:
         return Argument