def handle_response(to_class=None):
    """
    装饰器：检查从 itchat 返回的字典对象，并将其转化为指定类的实例
    若返回值不为0，会抛出 ResponseError 异常

    :param to_class: 需转化成的类，若为None则不转换
    """

    def decorator(func):
        @wraps(func)
        def wrapped(*args, **kwargs):
            ret = func(*args, **kwargs)

            if ret is None:
                return

            smart_map(check_response_body, ret)

            if to_class:
                if args:
                    self = args[0]
                else:
                    self = inspect.currentframe().f_back.f_locals.get('self')

                from wxpy.api.bot import Bot
                if isinstance(self, Bot):
                    bot = weakref.proxy(self)
                else:
                    bot = getattr(self, 'bot', None)
                    if not bot:
                        raise ValueError('bot not found:m\nmethod: {}\nself: {}\nbot: {}'.format(
                            func, self, bot
                        ))

                ret = smart_map(to_class, ret, bot)

                if isinstance(ret, list):
                    from wxpy.api.chats import Group
                    if to_class == Group:
                        from wxpy.api.chats import Groups
                        ret = Groups(ret)
                    else:
                        from wxpy.api.chats import Chats
                        ret = Chats(ret, bot)

            return ret

        return wrapped

    return decorator
装饰器：检查从 itchat 返回的字典对象，并将其转化为指定类的实例
若返回值不为0，会抛出 ResponseError 异常

:param to_class: 需转化成的类，若为None则不转换
wxpy/utils/misc.py