Esempio n. 1
0
    def prepare(self):
        self.fans_manager = FansManager(self.db)
        self.message_manager = MessageManager(self.db)
        self.article_manager = ArticleManager(self.db)
        self.account_manager = AccountManager(self.db)
        self.menu_manager = MenuManager(self.db)
        self.image_article_manager = ImageArticleManager(self.db)
        self.auto_manager = AutoManager(self.db)
        self.form_manager = FormManager(self.db)
        self.card_manager = CardManager(self.db)
        self.impact_manager = ImpactManager(self.db)
        self.auto_keyword_manager = AutoKeywordManager(self.db)
        self.site_manager = SiteManager(self.db)
        self.event_manager = EventManager(self.db)
        self.template_manager = TemplateManager(self.db)
        self.canyin_manager = CanyinManager(self.db)

        aid = self.request.uri.split('/')[2]
        if not aid:
            raise HTTPError(404)
        account = self.account_manager.get_account_by_aid(aid)
        if not account:
            raise HTTPError(404)
        if account.user_id != self.current_user.id:
            raise HTTPError(403)
        if self.get_cookie('aid', None) != account.aid:
            self.set_cookie('aid', aid)
        if not wei_api.access_token_available(account):
            wei_api.get_access_token(account, self.account_manager.update_account_token)
            self.account = self.account_manager.get_account_by_aid(aid)
        AccountBaseHandler.account = account
Esempio n. 2
0
 def post(self, aid, *args, **kwargs):
     """POST请求为微信服务器针对用户操作做出的响应"""
     account = self.account_manager.get_account_by_aid(aid)
     if not account:
         raise HTTPError(404)
     if not wei_api.access_token_available(account):
         wei_api.get_access_token(account, self.account_manager.update_account_token)
     message = self._get_message()
     if not message:
         raise HTTPError(404)
     result = self.message_util.process_message(account, message, self.get_template_path())
     if result:
         self.write(result)