How to use the wechatpy.create_reply function in wechatpy

To help you get started, we’ve selected a few wechatpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mn3711698 / Small / weixin / weixin.py View on Github external
self.objHandle.data,
                    msg_signature,
                    timestamp,
                    nonce
                )
            except Exception as e:
                self.wx_log('消息解密失败:%s' % open_id, '%s' % e)
            else:
                msg = parse_message(msg)
                if msg.type == 'text':
                    reply = create_reply(msg.content, msg)
                elif msg.type == 'event':
                    if msg.event == 'scan' or msg.event == 'subscribe_scan':
                        if msg.scene_id == 'login_code' or msg.scene_id == 'register_code':
                            MSG = self.wx_code_msg(open_id)
                            reply = create_reply(MSG, msg)
                        else:
                            reply = create_reply('未知事件', msg)
                    else:
                        reply = create_reply('login_code666666', msg)
                else:
                    reply = create_reply('Sorry, can not handle this for now11111111', msg)
                return crypto.encrypt_message(reply.render(), nonce, timestamp)
github jxtech / wechatpy / examples / echo / app.py View on Github external
signature = request.args.get('signature', '')
    timestamp = request.args.get('timestamp', '')
    nonce = request.args.get('nonce', '')
    echo_str = request.args.get('echostr', '')
    try:
        check_signature(TOKEN, signature, timestamp, nonce)
    except InvalidSignatureException:
        abort(403)
    if request.method == 'GET':
        return echo_str
    else:
        msg = parse_message(request.data)
        if msg.type == 'text':
            reply = create_reply(msg.content, msg)
        else:
            reply = create_reply('Sorry, can not handle this for now', msg)
        return reply.render()
github mn3711698 / Small / weixin / weixin.py View on Github external
if encrypt_type == 'raw':
            # plaintext mode
            msg = parse_message(self.objHandle.data)
            if msg.type == 'text':
                reply = create_reply(msg.content, msg)
            elif msg.type == 'event':
                if msg.event =='scan' or msg.event=='subscribe_scan':
                    if msg.scene_id == 'login_code' or msg.scene_id == 'register_code':
                        MSG = self.wx_code_msg(open_id)
                        reply = create_reply(MSG, msg)
                    else:
                        reply = create_reply('未知事件', msg)
                else:
                    reply = create_reply('login_code666666', msg)
            else:
                reply = create_reply('Sorry, can not handle this for now', msg)
            return reply.render()
        else:

            # encryption mode
            from wechatpy.crypto import WeChatCrypto
            crypto = WeChatCrypto(self.TOKEN, self.AES_KEY, self.APPID)
            try:
                msg = crypto.decrypt_message(
                    self.objHandle.data,
                    msg_signature,
                    timestamp,
                    nonce
                )
            except Exception as e:
                self.wx_log('消息解密失败:%s' % open_id, '%s' % e)
            else:
github mn3711698 / Small / weixin / weixin.py View on Github external
self.APPID = self.oTOLL.get('wx_appid', '')

        signature = self.objHandle.args.get('signature', '')
        timestamp = self.objHandle.args.get('timestamp', '')
        nonce = self.objHandle.args.get('nonce', '')
        encrypt_type = self.objHandle.args.get('encrypt_type', 'raw')
        msg_signature = self.objHandle.args.get('msg_signature', '')
        open_id = self.objHandle.args.get('openid', '')

        try:
            check_signature(self.TOKEN, signature, timestamp, nonce)
        except Exception as e:
            self.wx_log('验证失败:%s'%open_id, '%s' % e)
            if encrypt_type == 'raw':
                msg = parse_message(self.objHandle.data)
                reply=create_reply('该公众号服务器故障,请休息一会再试', msg)
                return reply.render()
            return ''

        if self.objHandle.method == 'GET':
            echo_str = self.objHandle.args.get('echostr', '')
            return echo_str
        #self.wx_log('恭恭敬敬恭恭敬敬', 'aaaaaaaaaaaaaaaa')
        # POST request
        if encrypt_type == 'raw':
            # plaintext mode
            msg = parse_message(self.objHandle.data)
            if msg.type == 'text':
                reply = create_reply(msg.content, msg)
            elif msg.type == 'event':
                if msg.event =='scan' or msg.event=='subscribe_scan':
                    if msg.scene_id == 'login_code' or msg.scene_id == 'register_code':
github mn3711698 / Small / weixin / weixin.py View on Github external
#self.wx_log('恭恭敬敬恭恭敬敬', 'aaaaaaaaaaaaaaaa')
        # POST request
        if encrypt_type == 'raw':
            # plaintext mode
            msg = parse_message(self.objHandle.data)
            if msg.type == 'text':
                reply = create_reply(msg.content, msg)
            elif msg.type == 'event':
                if msg.event =='scan' or msg.event=='subscribe_scan':
                    if msg.scene_id == 'login_code' or msg.scene_id == 'register_code':
                        MSG = self.wx_code_msg(open_id)
                        reply = create_reply(MSG, msg)
                    else:
                        reply = create_reply('未知事件', msg)
                else:
                    reply = create_reply('login_code666666', msg)
            else:
                reply = create_reply('Sorry, can not handle this for now', msg)
            return reply.render()
        else:

            # encryption mode
            from wechatpy.crypto import WeChatCrypto
            crypto = WeChatCrypto(self.TOKEN, self.AES_KEY, self.APPID)
            try:
                msg = crypto.decrypt_message(
                    self.objHandle.data,
                    msg_signature,
                    timestamp,
                    nonce
                )
            except Exception as e:
github mn3711698 / Small / weixin / weixin.py View on Github external
self.wx_log('消息解密失败:%s' % open_id, '%s' % e)
            else:
                msg = parse_message(msg)
                if msg.type == 'text':
                    reply = create_reply(msg.content, msg)
                elif msg.type == 'event':
                    if msg.event == 'scan' or msg.event == 'subscribe_scan':
                        if msg.scene_id == 'login_code' or msg.scene_id == 'register_code':
                            MSG = self.wx_code_msg(open_id)
                            reply = create_reply(MSG, msg)
                        else:
                            reply = create_reply('未知事件', msg)
                    else:
                        reply = create_reply('login_code666666', msg)
                else:
                    reply = create_reply('Sorry, can not handle this for now11111111', msg)
                return crypto.encrypt_message(reply.render(), nonce, timestamp)
github messense / wechat-bot / handlers.py View on Github external
self.set_header("Content-Type", "application/xml;charset=utf-8")
        body = self.request.body
        msg = parse_message(body)
        if not msg:
            logging.info('Empty message, ignored')
            return

        # new bot
        bot = AI(msg)

        if msg.type == 'text':
            if options.debug:
                logging.info('message type text from %s', msg.source)

            response = bot.respond(msg.content, msg)
            reply = create_reply(response, msg, render=True)
            self.write(reply)

            if options.debug:
                logging.info('Replied to %s with "%s"', msg.source, response)
        elif msg.type == 'location':
            if options.debug:
                logging.info('message type location from %s', msg.source)
        elif msg.type == 'image':
            if options.debug:
                logging.info('message type image from %s', msg.source)
        else:
            logging.info('message type unknown')
github saibei88 / wechat-router / handlers / wechathandlers.py View on Github external
msg = parse_message(self.request.body)
            os.kill(os.getpid(), signal.SIGUSR1)
            self.cache.append(msg)
#            main.ChatSocketHandler.update_cache()
#            print "message time ",msg.time
            data_source = 1
            customer_name = msg.source
            content_type = msg.type
            create_time = datetime.datetime.fromtimestamp(msg.time)
            msg_id = msg.id
            content = ""
#  微信服务器post的数据链接可以直接回写回复信息,xml格式
            if msg.type == 'text':
#                print msg.content
                content = msg.content
                reply = create_reply(msg.content, msg)
                message_class = REPLY_TYPES.get("text")
                reply_msg = message_class(source=msg.source,
                                          target=msg.target,
                                          content=msg.content)
                self.write(reply_msg.render())
            elif msg.type == 'image':
                content = msg.image
                self.http_client.fetch(msg.image, self.handle_multimedia_file)

            else:
                url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=" + ACCESS_TOKEN + "&media_id=" + msg.media_id 
                self.http_client.fetch(url,
                                       self.handle_multimedia_file)
                if msg.type == 'voice':
                    content = msg.format + ":" + ":" + msg.media_id + recognition
                elif msg.type == 'video':
github JoneXiong / oejia_wx / controllers / wx.py View on Github external
ret = subscribe(request, msg)
            elif msg.event=='unsubscribe':
                from .handlers.sys_event import unsubscribe
                ret = unsubscribe(request, msg)
            elif msg.event=='view':
                from .handlers.sys_event import url_view
                ret = url_view(request, msg)
            elif msg.event=='click':
                from .handlers.menu_click import onclick
                ret = onclick(request, msg)
        elif msg.type == 'unknown':
            _ret = self.handle_unknown(msg)
            if _ret:
                ret = _ret

        reply = create_reply(ret, msg).render()
        if encrypt_type == 'raw':
            return reply
        else:
            res = self.crypto.encrypt_message(reply, nonce, timestamp)
            return res
github mn3711698 / Small / weixin / weixin.py View on Github external
# encryption mode
            from wechatpy.crypto import WeChatCrypto
            crypto = WeChatCrypto(self.TOKEN, self.AES_KEY, self.APPID)
            try:
                msg = crypto.decrypt_message(
                    self.objHandle.data,
                    msg_signature,
                    timestamp,
                    nonce
                )
            except Exception as e:
                self.wx_log('消息解密失败:%s' % open_id, '%s' % e)
            else:
                msg = parse_message(msg)
                if msg.type == 'text':
                    reply = create_reply(msg.content, msg)
                elif msg.type == 'event':
                    if msg.event == 'scan' or msg.event == 'subscribe_scan':
                        if msg.scene_id == 'login_code' or msg.scene_id == 'register_code':
                            MSG = self.wx_code_msg(open_id)
                            reply = create_reply(MSG, msg)
                        else:
                            reply = create_reply('未知事件', msg)
                    else:
                        reply = create_reply('login_code666666', msg)
                else:
                    reply = create_reply('Sorry, can not handle this for now11111111', msg)
                return crypto.encrypt_message(reply.render(), nonce, timestamp)