Beispiel #1
0
    def get(request):
        """
        获取消息小尾巴

        POST例子:
        ~~~~~~~~~~~~~~~~~~~~~~~{.c}
        "tail":"这是一个小尾巴~~~~~"
        "is_active" = 1
        ~~~~~~~~~~~~~~~~~~~~~~~
        """
        FAKE_DATA=False
        if FAKE_DATA:
            tail = {
                        "tail": u'这是一个小尾巴~~~~~',
                        "is_active": 1
                    }
        else:
            tail = None
            try:
                tail = Tail.objects.get(owner=request.manager)
            except:
                pass

        c = RequestContext(request, {
            'first_nav_name': FIRST_NAV,
            'second_navs': export.get_weixin_second_navs(request),
            'second_nav_name': export.WEIXIN_MESSAGE_SECOND_NAV,
            'third_nav_name': export.MESSAGE_AUTO_REPLY_NAV,
            'tail': tail,
        })
        return render_to_response('weixin/message/message_tails.html', c)
Beispiel #2
0
    def get(request):
        """
		获取单图文编辑页面
		"""
        material_id = request.GET.get('id', None)
        if material_id:
            newses = list(
                weixin_models.News.objects.filter(material_id=material_id))
            news_count, newses_object = weixin_module_api.get_newses_object(
                newses)
        else:
            newses_object = []

        c = RequestContext(
            request,
            {
                'first_nav_name': FIRST_NAV,
                'second_navs': export.get_weixin_second_navs(request),
                'second_nav_name': export.WEIXIN_ADVANCE_SECOND_NAV,
                'third_nav_name': export.ADVANCE_MANAGE_MATERIAL_NAV,
                'material_id': material_id,
                'newses': json.dumps(newses_object).replace(
                    "'", "\\'")  #解决前台单引号导致的问题
            })

        return render_to_response(
            'weixin/advance_manage/edit_single_news.html', c)
Beispiel #3
0
	def get(request):
		"""
		自定义菜单页面
		"""
		status = STATUS_OPEN
		try:
			menu_status = CustomerMenuStatus.objects.get(owner=request.manager)
			status = menu_status.status
			
		except:
			pass
		
		is_certified_service = False
		try:
			mpuser = get_system_user_binded_mpuser(request.manager)
			is_certified_service = (mpuser.is_certified and mpuser.is_service)
		except:
			pass
		c = RequestContext(request, {
			'first_nav_name': FIRST_NAV,
			'second_navs': export.get_weixin_second_navs(request),
			'second_nav_name': export.WEIXIN_MPUSER_SECOND_NAV,
			'third_nav_name': export.MPUSER_MENU_NAV,
			'status': status,
			'is_weizoom_mall': request.manager.is_weizoom_mall,
			'is_certified_service': is_certified_service,
		})
		return render_to_response('weixin/mp_user/menu.html', c)
Beispiel #4
0
    def get(request):
        """
        获取“模板消息”的页面
        """

        industries = MarketToolsTemplateMessageDetail.objects.filter(
            owner=request.manager).values('industry', 'type').distinct()
        industry = {}
        for indus in industries:
            industry_name = TYPE2INDUSTRY.get(indus['industry'], '')
            if indus['type'] == MAJOR_INDUSTRY_TYPE:
                industry['major'] = industry_name
            elif indus['type'] == DEPUTY_INDUSTRY_TYPE:
                industry['deputy'] = industry_name

        c = RequestContext(
            request, {
                'first_nav_name': FIRST_NAV,
                'second_navs': export.get_weixin_second_navs(request),
                'second_nav_name': export.WEIXIN_MESSAGE_SECOND_NAV,
                'third_nav_name': export.MESSAGE_TEMPLATE_MESSAGE_NAV,
                'industry': industry,
            })

        return render_to_response('weixin/message/template_messages.html', c)
Beispiel #5
0
    def get(request):
        """
        获取图文信息
        """
        material_id = request.GET.get('id', None)
        if material_id:
            material = weixin_models.Material.objects.get(id=material_id)
            newses = list(
                weixin_models.News.objects.filter(material_id=material_id))
            news_count, newses_object = weixin_module_api.get_newses_object(
                newses, True)
        else:
            material = None
            newses_object = []

        c = RequestContext(
            request, {
                'first_nav_name': FIRST_NAV,
                'second_navs': export.get_weixin_second_navs(request),
                'second_nav_name': export.WEIXIN_ADVANCE_SECOND_NAV,
                'third_nav_name': export.ADVANCE_MANAGE_MATERIAL_NAV,
                'material_id': material_id,
                'newses': json.dumps(newses_object),
                'material': material,
                'head_img': get_mp_qrcode_img(request.manager.id)
            })
        return render_to_response('weixin/advance_manage/news_preview.html', c)
Beispiel #6
0
class FollowRules(resource.Resource):
    app = 'new_weixin'
    resource = 'follow_rules'

    @login_required
    @mp_required
    def get(request):
        """
        关注后自动回复消息的规则资源

        @param answer 文本回复内容
        @param material_id 图文回复内容的id
        
        ```说明```:
         * 当回复类型为文本消息时,answer的值一定不为空,material_id一定等于0
         * 当回复类型为图文消息时,material_id一定大于0,answer的值一定为空

        如果answer值为空且material_id等于0,说明关注时没有自动回复
        """
        FAKE_DATA=False
        if FAKE_DATA:
            rule = [{
                "id": 1,
                "answer": {"content":"1","type":"news","newses":[{
                    "id": 1,
                    "title": "title1"
                }, {
                    "id": 2,
                    "title": "title2"
                }]}, 
                "material_id": 1
            }]
        else:
            rule =None
            try:
                raw_rule = Rule.objects.get(owner=request.manager, type=FOLLOW_TYPE)
                if not raw_rule.answer or raw_rule.answer == '':
                    #当内容为空时删除该条记录
                    Rule.objects.filter(owner=request.manager, type=FOLLOW_TYPE).delete()
                else:
                    rule = raw_rule.format_to_dict()
            except Exception, e:
                print e

        jsons = [{
            "name": "rule", "content": rule
        }]

        c = RequestContext(request, {
            'first_nav_name': FIRST_NAV,
            'second_navs': export.get_weixin_second_navs(request),
            'second_nav_name': export.WEIXIN_MESSAGE_SECOND_NAV,
            'third_nav_name': export.MESSAGE_AUTO_REPLY_NAV,
            'rule': rule,
            'jsons': jsons
        })
        return render_to_response('weixin/message/follow_rules.html', c)
Beispiel #7
0
    def get(request):
        """
		测试React
		"""
        c = RequestContext(
            request, {
                'first_nav_name': FIRST_NAV,
                'second_navs': export.get_weixin_second_navs(request),
                'second_nav_name': export.HOME_NAV,
            })
        return render_to_response('weixin/home/react_test.html', c)
Beispiel #8
0
 def get(request):
     """
     会员渠道扫码列表页面
     """
     c = RequestContext(
         request, {
             'first_nav_name': FIRST_NAV,
             'second_navs': export.get_weixin_second_navs(request),
             'second_nav_name': export.WEIXIN_ADVANCE_SECOND_NAV,
             'third_nav_name':
             export.ADVANCE_MANAGE_MEMBER_CHANNEL_QRCODE_NAV,
         })
     return render_to_response('weixin/advance_manage/channel_qrcodes.html',
                               c)
 def get(request):
     """
         获取指定ID的模板消息详情的内容
     """
     template_detail_id = int(request.GET.get('template_detail_id'))
     message_detail = MarketToolsTemplateMessageDetail.objects.get(id=template_detail_id)
     c = RequestContext(request, {
         'first_nav_name': FIRST_NAV,
         'second_navs': export.get_weixin_second_navs(request),
         'second_nav_name': export.WEIXIN_MESSAGE_SECOND_NAV,
         'third_nav_name': export.MESSAGE_TEMPLATE_MESSAGE_NAV,
         'message_detail': message_detail
     })
     return render_to_response('weixin/message/template_messages_detail.html', c)
Beispiel #10
0
    def get(request):
        """
                        获取实时消息页面
        """
        status = request.GET.get('status', -1)
        c = RequestContext(
            request, {
                'first_nav_name': FIRST_NAV,
                'second_navs': export.get_weixin_second_navs(request),
                'second_nav_name': export.WEIXIN_MESSAGE_SECOND_NAV,
                'third_nav_name': export.MESSAGE_REALTIME_MESSAGE_NAV,
                'status': status
            })

        return render_to_response('weixin/message/realtime_messages.html', c)
Beispiel #11
0
    def get(request):
        """
        带参数二维码
        """
        qrcode_id = request.GET.get('qrcode_id', None)
        c = RequestContext(
            request, {
                'first_nav_name': FIRST_NAV,
                'second_navs': export.get_weixin_second_navs(request),
                'second_nav_name':
                export.ADVANCE_MANAGE_MEMBER_CHANNEL_QRCODE_NAV,
                'qrcode_id': qrcode_id
            })

        return render_to_response(
            'weixin/advance_manage/channel_qrcode_order.html', c)
Beispiel #12
0
    def get(request):
        """
        未匹配自动回复的消息
        active_type等于2表示分时段开启,等于1表示始终开启,等于0表示禁用
        """
        FAKE_DATA=False
        rule = None
        if FAKE_DATA:
            rule = {
                "answer": [{"content":"欢迎光临","type":"text"},
                    {"content":"1","type":"text"},
                    {"content":"2","type":"news","newses":[{"id":1,"title":"标题一"},{"id":2,"title":"标题二"}]}], 
                "active_type": 2,
                "active_days":{'Mon':True,'Tue':False,'Wed':True,'Thu':True,'Fri':True,'Sat':False,'Sun':False},
                "start_hour": '00:00',
                "end_hour": '24:00',
                "material_id": 0
            }
            jsons = [{
                "name": "rule", "content": rule
            }]
        else:
            try:
                raw_rule = Rule.objects.get(owner=request.manager, type=UNMATCH_TYPE)
                if not raw_rule.answer or raw_rule.answer == '':
                    #当内容为空时删除该条记录
                    Rule.objects.filter(owner=request.manager, type=UNMATCH_TYPE).delete()
                else:
                    rule = raw_rule.format_to_dict()
            except:
                rule = None
        
        jsons = [{
            "name": "rule", "content": rule
        }]

        c = RequestContext(request, {
            'first_nav_name': FIRST_NAV,
            'second_navs': export.get_weixin_second_navs(request),
            'second_nav_name': export.WEIXIN_MESSAGE_SECOND_NAV,
            'third_nav_name': export.MESSAGE_AUTO_REPLY_NAV,
            'rule': rule,
            'jsons': jsons
        })
        return render_to_response('weixin/message/unmatch_rules.html', c)
Beispiel #13
0
    def get(request):
        mpuser = get_system_user_binded_mpuser(request.manager)

        if (mpuser is
                None) or (not mpuser.is_certified) or (not mpuser.is_service):
            should_show_authorize_cover = True
        else:
            should_show_authorize_cover = False

        coupon_rules = get_coupon_rules(request.manager)
        try:
            member_qrcode_setting = MemberChannelQrcodeSettings.objects.get(
                owner=request.manager)
        except:
            member_qrcode_setting = None

        if member_qrcode_setting:
            try:
                award_content = MemberChannelQrcodeAwardContent.objects.get(
                    owner=request.manager)
            except:
                award_content = None
        else:
            award_content = None

        c = RequestContext(
            request, {
                'first_nav_name': FIRST_NAV,
                'second_navs': export.get_weixin_second_navs(request),
                'second_nav_name': export.WEIXIN_ADVANCE_SECOND_NAV,
                'third_nav_name':
                export.ADVANCE_MANAGE_MEMBER_CHANNEL_QRCODE_NAV,
                'member_qrcode_settings': member_qrcode_setting,
                'coupon_rules': coupon_rules,
                'award_content': award_content,
                'should_show_authorize_cover': should_show_authorize_cover,
                'is_hide_weixin_option_menu': True
            })

        return render_to_response(
            'weixin/advance_manage/edit_member_channel_qrcode.html', c)
Beispiel #14
0
    def get(request):
        """
		获取图文列表页面
		"""
        material_count = weixin_models.Material.objects.filter(
            owner=request.manager, is_deleted=False).count()
        if material_count > 0:
            has_material = True
        else:
            has_material = False

        c = RequestContext(
            request, {
                'first_nav_name': FIRST_NAV,
                'second_navs': export.get_weixin_second_navs(request),
                'second_nav_name': export.WEIXIN_ADVANCE_SECOND_NAV,
                'third_nav_name': export.ADVANCE_MANAGE_MATERIAL_NAV,
                'has_material': has_material
            })

        return render_to_response('weixin/advance_manage/materials.html', c)
Beispiel #15
0
    def get(request):
        """
		快速关注页面
		"""
        operation_settings_objs = OperationSettings.objects.filter(
            owner=request.manager)
        if operation_settings_objs.count() == 0:
            operation_settings = OperationSettings.objects.create(
                owner=request.manager)
        else:
            operation_settings = operation_settings_objs[0]

        c = RequestContext(
            request, {
                'first_nav_name': FIRST_NAV,
                'second_navs': export.get_weixin_second_navs(request),
                'second_nav_name': export.WEIXIN_MPUSER_SECOND_NAV,
                'third_nav_name': export.MPUSER_DIRECT_FOLLOW_NAV,
                'operation_settings': operation_settings,
            })
        return render_to_response('weixin/mp_user/direct_follow.html', c)
    def get(request):
        """
        获取商家的模板消息
        """
        c = RequestContext(
            request, {
                'first_nav_name':
                FIRST_NAV,
                'second_navs':
                export.get_weixin_second_navs(request),
                'second_nav_name':
                export.WEIXIN_MESSAGE_SECOND_NAV,
                'third_nav_name':
                export.MESSAGE_TEMPLATE_MESSAGE_NAV,
                'has_templates':
                weixin_models.UserHasTemplateMessages.objects.filter(
                    owner_id=request.manager.id).count() > 0
            })

        return render_to_response('weixin/message/new_template_messages.html',
                                  c)
Beispiel #17
0
    def get(request):
        """
        获取群发消息的“已发送消息”
        """
        """
        sent_messages = [{
            "id": 1,
            "message_type": 1, # 文本、图文、语音?
            "message_content": "已发送文本已发送文本已发送文本已发送文本已发送文本已发送文本已发送文本已发送文本",
            "status": 1, # 发送中、已发送、失败、已删除
            "created_at": "3月26日",
        }, {
            "id": 2,
            "message_type": 2, # 文本、图文、语音?
            "message_content": "已发送文本已发送文本已发送文本已发送文本已发送文本已发送文本已发送文本已发送文本",
            "status": 4, # 发送中、已发送、失败、已删除
            "created_at": "3月26日",
        }]
        """

        user_profile = request.user_profile
        webapp_id = user_profile.webapp_id
        sent_messages = UserSentMassMsgLog.objects.filter(webapp_id=webapp_id)

        for message in sent_messages:
            message.created_at = message.created_at.strftime('%m月%d日')
            message.message_content = emotion.change_emotion_to_img(
                message.message_content)

        c = RequestContext(
            request, {
                'first_nav_name': FIRST_NAV,
                'second_navs': export.get_weixin_second_navs(request),
                'second_nav_name': export.WEIXIN_MESSAGE_SECOND_NAV,
                'third_nav_name': export.MESSAGE_MASS_SENDING_NAV,
                'sent_messages': sent_messages
            })
        return render_to_response('weixin/message/mass_sent_messages.html', c)
    def get(request):
        """
        获取实时消息页面
        """
        session_id = request.GET.get('session_id', '')
        try:
            could_replied = int(request.GET.get('replied', 0))
        except:
            could_replied = 0

        try:
            session = Session.objects.get(id=session_id)
            if 'replied' not in request.GET:
                member_latest_created_at = get_datetime_from_timestamp(int(session.member_latest_created_at))
                datetime_before = get_datetime_before_by_hour(DATETIME_BEFORE_HOURS)
                if member_latest_created_at <= datetime_before:
                    could_replied = 0
                else:
                    could_replied = 1
                webapp_id = request.user_profile.webapp_id
                member = get_social_member(webapp_id, session.member_user_username)
                if not member.get('is_subscribed',True):
                    could_replied = 0
        except:
            session = None


        c = RequestContext(request, {
            'first_nav_name': FIRST_NAV,
            'second_navs': export.get_weixin_second_navs(request),
            'second_nav_name': export.WEIXIN_MESSAGE_SECOND_NAV,
            'third_nav_name': export.MESSAGE_REALTIME_MESSAGE_NAV,
            'session_id': session_id,
            'could_replied': could_replied,
            'session':session
        })

        return render_to_response('weixin/message/realtime_messages_detail.html', c)
Beispiel #19
0
    def get(request):
        """
		微信概况
		"""
        owner_id = request.manager.id
        webapp_id = request.user_profile.webapp_id

        member_count = Member.count(webapp_id)

        yesterday_added_count, yesterday_net_count = _get_yesterday_count(
            owner_id)

        unread_message_count = get_unread_message_count(request.manager)
        c = RequestContext(
            request, {
                'first_nav_name': FIRST_NAV,
                'second_navs': export.get_weixin_second_navs(request),
                'second_nav_name': export.WEIXIN_HOME_OUTLINE_NAV,
                'member_count': member_count,
                'yesterday_added_count': yesterday_added_count,
                'yesterday_net_count': yesterday_net_count,
                'unread_message_count': unread_message_count
            })
        return render_to_response('weixin/home/outline.html', c)
Beispiel #20
0
    def get(request):
        """
		获取粉丝列表页面
		"""
        webapp_id = request.user_profile.webapp_id
        # TODO: 缓存粉丝数量
        member_count = Member.objects.filter(webapp_id=webapp_id,
                                             is_for_test=False).count()
        has_fans = member_count > 0

        # 获取粉丝分组数据
        categories = get_fan_category_list(webapp_id, member_count)

        c = RequestContext(
            request, {
                'first_nav_name': FIRST_NAV,
                'second_navs': export.get_weixin_second_navs(request),
                'second_nav_name': export.WEIXIN_ADVANCE_SECOND_NAV,
                'third_nav_name': export.ADVANCE_MANAGE_FANS_NAV,
                'has_fans': has_fans,
                'categories': categories
            })

        return render_to_response('weixin/advance_manage/fanses.html', c)
Beispiel #21
0
    def get(request):
        """
		获得公众号详情
		"""
        user_profile = request.user_profile
        # request_user = request.user
        request_user = request.manager  #duhao 20151020
        user_profile = account_models.UserProfile.objects.get(
            id=user_profile.id)

        if user_profile.is_mp_registered:
            try:
                mpuser = weixin_models.get_system_user_binded_mpuser(
                    request_user)
                mpuser_preview_info = weixin_models.MpuserPreviewInfo.objects.get(
                    mpuser=mpuser)
            except:
                mpuser = None
                mpuser_preview_info = None

        from weixin.user.util import get_component_info_from
        component_info = get_component_info_from(request)

        pre_auth_code = None
        request_host = settings.DOMAIN
        logging.info('>>>>>>>>>>>>>>>>>>>>>>>start')
        logging.info(request_host)
        logging.info('>>>>>>>>>>>>>>>>>>>>>>>end')
        #request_host = request.META['HTTP_HOST']

        if component_info:
            from core.wxapi.agent_weixin_api import WeixinApi, WeixinHttpClient
            weixin_http_client = WeixinHttpClient()
            weixin_api = WeixinApi(component_info.component_access_token,
                                   weixin_http_client)
            result = weixin_api.api_create_preauthcode(component_info.app_id)
            print result
            if hasattr(result, 'pre_auth_code'):
                pre_auth_code = result['pre_auth_code']
            else:
                result = weixin_api.api_create_preauthcode(
                    component_info.app_id)
                if result and result.has_key('pre_auth_code'):
                    pre_auth_code = result['pre_auth_code']
                else:
                    watchdog_error(result)

            if weixin_models.ComponentAuthedAppid.objects.filter(
                    component_info=component_info,
                    user_id=request.manager.id).count() == 0:
                weixin_models.ComponentAuthedAppid.objects.create(
                    component_info=component_info, user_id=request.manager.id)
            auth_appid = weixin_models.ComponentAuthedAppid.objects.filter(
                component_info=component_info, user_id=request.manager.id)[0]

            if weixin_models.ComponentAuthedAppidInfo.objects.filter(
                    auth_appid=auth_appid).count() > 0:
                auth_appid_info = weixin_models.ComponentAuthedAppidInfo.objects.filter(
                    auth_appid=auth_appid)[0]
            else:
                auth_appid_info = None
        else:
            component_info = None
            auth_appid = None
            auth_appid_info = None

        #微众商城引流图文地址
        operation_settings_objs = account_models.OperationSettings.objects.filter(
            owner=request.manager)
        if operation_settings_objs.count() == 0:
            operation_settings = account_models.OperationSettings.objects.create(
                owner=request.manager)
        else:
            operation_settings = operation_settings_objs[0]

        if user_profile.is_mp_registered:
            mpuser_access_token = weixin_models.get_mpuser_access_token_for(
                mpuser)
            c = RequestContext(
                request, {
                    'first_nav_name': FIRST_NAV,
                    'second_navs': export.get_weixin_second_navs(request),
                    'second_nav_name': export.WEIXIN_MPUSER_SECOND_NAV,
                    'third_nav_name': export.MPUSER_BINDING_NAV,
                    'component_info': component_info,
                    'request_user': request_user,
                    'user_profile': user_profile,
                    'mpuser': mpuser,
                    'mpuser_access_token': mpuser_access_token,
                    'preview_user': mpuser_preview_info,
                    'default_icon': weixin_models.DEFAULT_ICON,
                    'is_mp_registered': user_profile.is_mp_registered,
                    'pre_auth_code': pre_auth_code,
                    'auth_appid_info': auth_appid_info,
                    'request_host': request_host,
                    'operation_settings': operation_settings
                })
            return render_to_response('weixin/mp_user/mp_user.html', c)
        else:
            c = RequestContext(
                request, {
                    'first_nav_name': FIRST_NAV,
                    'pre_auth_code': pre_auth_code,
                    'request_user': request_user,
                    'user_profile': user_profile,
                    'default_icon': weixin_models.DEFAULT_ICON,
                    'component_info': component_info,
                    'is_mp_registered': user_profile.is_mp_registered,
                    'auth_appid_info': auth_appid_info,
                    'request_host': request_host,
                    'operation_settings': operation_settings
                })
            return render_to_response('weixin/mp_user/mp_user_index.html', c)
Beispiel #22
0
    def get(request):
        """
        关键词自动回复的消息

        @param patterns 关键词列表
        @param answer 回复内容列表
        """
        FAKE_DATA = False
        if FAKE_DATA:
            items = [
                {
                    "id":
                    1,
                    "rule_name":
                    "未命名规则1",
                    "patterns": [{
                        "keyword": "你好",
                        "type": 1
                    }, {
                        "keyword": "hi",
                        "type": 0
                    }],  # 1表示部分匹配,0表示精确匹配
                    "answer": [{
                        "content": "欢迎光临",
                        "type": "text"
                    }, {
                        "content": "1",
                        "type": "text"
                    }, {
                        "content":
                        "2",
                        "type":
                        "news",
                        "newses": [{
                            "id": 1,
                            "title": "标题一"
                        }, {
                            "id": 2,
                            "title": "标题二"
                        }]
                    }],
                },
                {
                    "id":
                    2,
                    "rule_name":
                    "未命名规则2",
                    "patterns": [{
                        "keyword": "你好",
                        "type": 1
                    }, {
                        "keyword": "hi",
                        "type": 0
                    }],  # 1表示部分匹配,0表示精确匹配
                    "answer": [{
                        "type": "text",
                        "content": "欢迎光临"
                    }, {
                        "type": "text",
                        "content": "1"
                    }, {
                        "type":
                        "news",
                        "content":
                        "2",
                        "newses": [{
                            "id": 1,
                            "title": "标题一"
                        }, {
                            "id": 2,
                            "title": "标题二"
                        }]
                    }],
                }
            ]

        c = RequestContext(
            request,
            {
                'first_nav_name': FIRST_NAV,
                'second_navs': export.get_weixin_second_navs(request),
                'second_nav_name': export.WEIXIN_MESSAGE_SECOND_NAV,
                'third_nav_name': export.MESSAGE_AUTO_REPLY_NAV,
                #'rules': items,
                #'jsons': jsons
            })
        return render_to_response('weixin/message/keyword_rules.html', c)