(cls, data, app, src=None)
return menu
:type app: wechat_django.models.WeChatApp
:type app: wechat_django.models.WeChatApp
: type app : wechat_django . models . WeChatApp
def json2menu(cls, data, app, src=None):
        """
        :type app: wechat_django.models.WeChatApp
        """
        menu = cls(name=data["name"], app=app)
        menu.type = data.get("type")
        if not menu.type:
            menu.save()
            menu.sub_button.add(*[
                cls.json2menu(sub, app, src) for sub in
                (data.get("sub_button") or dict(list=[])).get("list")
            ])
        elif menu.type in (cls.Event.VIEW, cls.Event.CLICK,
                           cls.Event.MINIPROGRAM):
            menu.content = data
        else:
            # 要当作回复处理了
            menu.type = cls.Event.CLICK
            # 生成一个唯一key
            key = md5(json.dumps(data).encode()).hexdigest()
            menu.content = dict(key=key)
            MessageHandler.from_menu(menu, data, src)
        menu.save()
        return menu
def json2menu ( cls , data , app , src = None ) : menu = cls ( name = data [ "name" ] , app = app ) menu . type = data . get ( "type" ) if not menu . type : menu . save ( ) menu . sub_button . add ( * [ cls . json2menu ( sub , app , src ) for sub in ( data . get ( "sub_button" ) or dict ( list = [ ] ) ) . get ( "list" ) ] ) elif menu . type in ( cls . Event . VIEW , cls . Event . CLICK , cls . Event . MINIPROGRAM ) : menu . content = data else : # 要当作回复处理了 menu . type = cls . Event . CLICK # 生成一个唯一key key = md5 ( json . dumps ( data ) . encode ( ) ) . hexdigest ( ) menu . content = dict ( key = key ) MessageHandler . from_menu ( menu , data , src ) menu . save ( ) return menu