本文整理匯總了Python中router.Router.get_instance方法的典型用法代碼示例。如果您正苦於以下問題:Python Router.get_instance方法的具體用法?Python Router.get_instance怎麽用?Python Router.get_instance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類router.Router
的用法示例。
在下文中一共展示了Router.get_instance方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_default_cover
# 需要導入模塊: from router import Router [as 別名]
# 或者: from router.Router import get_instance [as 別名]
if menu.page.message_cover:
data['pic_url'] = menu.page.message_cover.url
else:
data['pic_url'] = settings.SITE_URL + settings.STATIC_URL + get_default_cover(menu.page)
data['url'] = cls.get_url() + "?user=%s&wx=%s" % (info.user, info.wx)
return BuildConfig(MessageBuilder.TYPE_WEB_APP, None, data)
else:
return BuildConfig(MessageBuilder.TYPE_RAW_TEXT, None, u'非常抱歉')
except:
logger.error(traceback.format_exc())
return BuildConfig(MessageBuilder.TYPE_RAW_TEXT, None, u'非常抱歉')
Router.get_instance().set({
'name' : u'關注',
'pattern' : match_subscribe_event,
'handler' : micro_site
})
Router.get_instance().set({
'name' : u'取消關注',
'pattern' : match_unsubscribe_event,
'handler' : unsubscribe
})
Router.get_instance().set({
'name' : u'驗證綁定',
'pattern' : u'rocket',
'handler' : check_bind_state
})
Router.get_instance().set({
'name' : u'microsite',
'pattern' : u'(官網|網站|你好|hi|hello|你是誰)',
示例2: index
# 需要導入模塊: from router import Router [as 別名]
# 或者: from router.Router import get_instance [as 別名]
#.........這裏部分代碼省略.........
walluser.save()
r.rpush('userList', message['FromUserName'])
wxlogger.info("我要訂閱")
if message['MsgType'] == 'text' or message['MsgType'] == 'image' or message['MsgType'] == 'voice':
wxlogger.info("我想上牆")
wxlogger.info(len(WallUser.objects.filter(wx=wx_account, openid=message['FromUserName'])))
if not len(WallUser.objects.filter(wx=wx_account, openid=message['FromUserName']))==0:
walluser = WallUser.objects.filter(wx=wx_account, openid=message['FromUserName'])[0]
#wxlogger.info('walluser is %s' % message['FromUserName'])
if not walluser.wall_item_id == '0':#說明上牆了
#對上牆活動的進行時間進行判斷,有可能上牆了但活動已經結束了
wallitem = WallItem.objects.filter(id=walluser.wall_item_id)
if len(wallitem) == 0:
walluser.wall_item_id = '0'
walluser.save()
reply_str = "活動不存在"
reply_config = BuildConfig(MessageBuilder.TYPE_RAW_TEXT, MessageBuilder.PLATFORM_WEIXIN, reply_str)
return HttpResponse(MessageBuilder.build(message, reply_config), content_type="application/xml")
else:
wallitem = wallitem[0]
#結束時間10分鍾後的處理
#if (datetime.now()-wallitem.begin_time).seconds <= 600:
if datetime.now()<wallitem.end_time:#說明在上牆時間內
if message['MsgType'] == 'text' or message['MsgType'] == 'voice':
message_str = ""
if message['MsgType'] == 'text':
message_str = message['Content']
else:
message_str = message['Recognition']
if not message_str == "退出":
wxlogger.info('receive message %s' % message_str)
WallMsg.objects.create(user=walluser, type='text', content=message_str, wall_item_id=walluser.wall_item_id)
reply_str = "發送成功"
wxlogger.info(datetime.now())
reply_config = BuildConfig(MessageBuilder.TYPE_RAW_TEXT, MessageBuilder.PLATFORM_WEIXIN, reply_str)
return HttpResponse(MessageBuilder.build(message, reply_config), content_type="application/xml")
else:#quit the wall
walluser.wall_item_id = '0'
walluser.save()
reply_str = "退出成功"
reply_config = BuildConfig(MessageBuilder.TYPE_RAW_TEXT, MessageBuilder.PLATFORM_WEIXIN, reply_str)
return HttpResponse(MessageBuilder.build(message, reply_config), content_type="application/xml")
else:#image
WallMsg.objects.create(user=walluser, type=message['MsgType'], content=message['PicUrl'], wall_item_id=walluser.wall_item_id)
reply_str = "發送成功"
reply_config = BuildConfig(MessageBuilder.TYPE_RAW_TEXT, MessageBuilder.PLATFORM_WEIXIN, reply_str)
return HttpResponse(MessageBuilder.build(message, reply_config), content_type="application/xml")
if (datetime.now()-wallitem.end_time).seconds <= 600:#超出上牆時間不到10分鍾
reply_str = "活動已結束,您將在10分鍾之後自動退出該活動,您也可以回複“退出”直接退出該活動。"
reply_config = BuildConfig(MessageBuilder.TYPE_RAW_TEXT, MessageBuilder.PLATFORM_WEIXIN, reply_str)
return HttpResponse(MessageBuilder.build(message, reply_config), content_type="application/xml")
else:
walluser.wall_item_id = '0'
walluser.save()
wxlogger.info("活動已經結束超過10分鍾,您已經被係統退出上牆。")
reply_str = "活動已經結束超過10分鍾,您已經被係統退出上牆。"
reply_config = BuildConfig(MessageBuilder.TYPE_RAW_TEXT, MessageBuilder.PLATFORM_WEIXIN, reply_str)
return HttpResponse(MessageBuilder.build(message, reply_config), content_type="application/xml")
else:#說明沒有上牆
if message['MsgType'] == 'text':
wxlogger.info(message)
wxlogger.info("說明沒有上牆")
if not len(WallItem.objects.filter(wx=wx_account)) == 0:#說明該微信號有微信牆活動
for wallitem in WallItem.objects.filter(wx=wx_account):
if message['Content']==wallitem.keyword:#說明有上牆的關鍵字
reply_str = ""
if datetime.now()<wallitem.begin_time:#沒有開始
reply_str = "活動未開始,請在活動開始("+str(wallitem.begin_time)+")之後再發送消息。"
elif datetime.now()>wallitem.end_time:#說明已經結束
reply_str = "活動已結束"
else:
wxlogger.info(wallitem.welcome)
walluser.wall_item_id = wallitem.id
walluser.save()
if judge_symbol(wallitem.welcome):
reply_str = wallitem.welcome+'回複“退出”則退出上牆。'
else:
reply_str = wallitem.welcome+','+'回複“退出”則退出上牆。'
reply_config = BuildConfig(MessageBuilder.TYPE_RAW_TEXT, MessageBuilder.PLATFORM_WEIXIN, reply_str)
return HttpResponse(MessageBuilder.build(message, reply_config), content_type="application/xml")
Router.get_instance().reply(wx, message, _route_callback)
if router_error is None and router_reply is not None:
router_reply.platform = MessageBuilder.PLATFORM_WEIXIN
if router_reply.type != MessageBuilder.TYPE_NO_RESPONSE:
wxlogger.info("reply success type %s platform %s data %s" % (router_reply.type, router_reply.platform, router_reply.data))
return HttpResponse(MessageBuilder.build(message, router_reply), content_type="application/xml")
else:
wxlogger.info("%s", router_reply.data)
else:
wxlogger.info("router error %s router reply %s" % (str(router_error), str(router_reply)))
reply_config = BuildConfig(MessageBuilder.TYPE_RAW_TEXT, MessageBuilder.PLATFORM_WEIXIN, u"抱歉,我不是很明白")
return HttpResponse(MessageBuilder.build(message, reply_config), content_type="application/xml")
#return HttpResponse('<xml></xml>', content_type="application/xml")
except:
wxlogger.error(traceback.format_exc())
reply_config = BuildConfig(MessageBuilder.TYPE_RAW_TEXT, MessageBuilder.PLATFORM_WEIXIN, u"抱歉,我不是很明白。")
return HttpResponse(MessageBuilder.build(message, reply_config), content_type="application/xml")