Exemplo n.º 1
0
    def process_event_msg(self):

        self.reply_msg = CHAT_MAP.get('subscribe').get('welcome_str')

        if self.msg_type == 'event' and self.msg_event == 'SCAN':
            event_key = self.event_key
            event_key_action = self.get_event_action(event_key)
            uid_key = event_key[1:]

            if event_key_action == 'qr_bind':
                ret = WeixinService.qrcode_bind_user(uid_key=uid_key,
                                                     openid=self.openid)
                self.reply_msg = CHAT_MAP.get('subscribe').get(ret['msg'])
                if ret['status'] == 'ok':
                    self.reply_msg = self.reply_msg % (ret.get('username'))

            if event_key_action == 'get_red_pack':

                ret = WeixinService.qrcode_get_red_pack(uid_key=uid_key,
                                                        openid=self.openid)
                self.reply_msg = CHAT_MAP.get('get_red_pack').get(ret['msg'])

        if self.msg_type == 'event' and self.msg_event == 'subscribe':
            self.reply_msg = CHAT_MAP.get('subscribe').get('welcome_str')
            if self.event_key and 'qrscene' in self.event_key:

                event_key = self.event_key[8:]
                event_key_action = self.get_event_action(event_key)
                uid_key = event_key[1:]

                if event_key_action == 'qr_bind':
                    ret = WeixinService.qrcode_bind_user(uid_key=uid_key,
                                                         openid=self.openid)
                    self.reply_msg = CHAT_MAP.get('subscribe').get(ret['msg'])
                    if ret['status'] == 'ok':
                        self.reply_msg = self.reply_msg % (ret.get('username'))

                if event_key_action == 'get_red_pack':
                    ret = WeixinService.qrcode_get_red_pack(uid_key=uid_key,
                                                            openid=self.openid)
                    self.reply_msg = CHAT_MAP.get('get_red_pack').get(
                        ret['msg'])

            WeixinService.update_weixin_user(openid=self.openid,
                                             is_subscribe=True)

        if self.msg_type == 'event' and self.msg_event == 'unsubscribe':
            WeixinService.update_weixin_user(openid=self.openid,
                                             is_subscribe=False)

        if self.msg_type == 'event' and self.msg_event == 'CLICK':

            ret = EVENT_KEY_MAP.get(self.event_key)
            self.reply_msg = self.do_str_to_fun(fun_name=ret.get('fun_name'))

        return self.reply_content(content=self.reply_msg)
Exemplo n.º 2
0
    def process_text_msg(self):

        self.reply_msg = EVENT_KEY_MAP.get('KEY_HELP').get('welcome_str')
        reply_doc = CHAT_MAP.get(self.recv_msg)
        if not reply_doc:
            return self.reply_content(content=self.reply_msg)
        if reply_doc.get('type') == 'show_text':
            self.reply_msg = reply_doc.get('welcome_str')

        if reply_doc.get('type') == 'show_text_fun':
            self.reply_msg = reply_doc.get('fun_name')

        if reply_doc.get('type') == 'reply_text_fun':
            self.reply_msg = self.do_str_to_fun(
                fun_name=reply_doc.get('fun_name'))

        return self.reply_content(content=self.reply_msg)
Exemplo n.º 3
0
    def process_text_msg(self):

        self.reply_msg = EVENT_KEY_MAP.get('KEY_HELP').get('welcome_str')
        reply_doc = CHAT_MAP.get(self.recv_msg)
        if not reply_doc:
            return self.reply_content(
                content=self.reply_msg
            )
        if reply_doc.get('type') == 'show_text':
            self.reply_msg = reply_doc.get('welcome_str')

        if reply_doc.get('type') == 'show_text_fun':
            self.reply_msg = reply_doc.get('fun_name')

        if reply_doc.get('type') == 'reply_text_fun':
            self.reply_msg = self.do_str_to_fun(
                fun_name=reply_doc.get('fun_name')
            )

        return self.reply_content(
            content=self.reply_msg
        )
Exemplo n.º 4
0
    def process_event_msg(self):

        self.reply_msg = CHAT_MAP.get('subscribe').get('welcome_str')

        if self.msg_type == 'event' and self.msg_event == 'SCAN':
            event_key = self.event_key
            event_key_action = self.get_event_action(event_key)
            uid_key = event_key[1:]

            if event_key_action == 'qr_bind':
                ret = WeixinService.qrcode_bind_user(
                    uid_key=uid_key,
                    openid=self.openid
                )
                self.reply_msg = CHAT_MAP.get('subscribe').get(ret['msg'])
                if ret['status'] == 'ok':
                    self.reply_msg = self.reply_msg % (ret.get('username'))

            if event_key_action == 'get_red_pack':

                ret = WeixinService.qrcode_get_red_pack(
                    uid_key=uid_key,
                    openid=self.openid
                )
                self.reply_msg = CHAT_MAP.get('get_red_pack').get(ret['msg'])

        if self.msg_type == 'event' and self.msg_event == 'subscribe':
            self.reply_msg = CHAT_MAP.get('subscribe').get('welcome_str')
            if self.event_key and 'qrscene' in self.event_key:

                event_key = self.event_key[8:]
                event_key_action = self.get_event_action(event_key)
                uid_key = event_key[1:]

                if event_key_action == 'qr_bind':
                    ret = WeixinService.qrcode_bind_user(
                        uid_key=uid_key,
                        openid=self.openid
                    )
                    self.reply_msg = CHAT_MAP.get('subscribe').get(ret['msg'])
                    if ret['status'] == 'ok':
                        self.reply_msg = self.reply_msg % (ret.get('username'))

                if event_key_action == 'get_red_pack':
                    ret = WeixinService.qrcode_get_red_pack(
                        uid_key=uid_key,
                        openid=self.openid
                    )
                    self.reply_msg = CHAT_MAP.get('get_red_pack').get(ret['msg'])

            WeixinService.update_weixin_user(
                openid=self.openid,
                is_subscribe=True
            )

        if self.msg_type == 'event' and self.msg_event == 'unsubscribe':
            WeixinService.update_weixin_user(
                openid=self.openid,
                is_subscribe=False
            )

        if self.msg_type == 'event' and self.msg_event == 'CLICK':

            ret = EVENT_KEY_MAP.get(self.event_key)
            self.reply_msg = self.do_str_to_fun(
                fun_name=ret.get('fun_name')
            )

        return self.reply_content(
            content=self.reply_msg
        )