Exemplo n.º 1
0
    def _build_response_without_auto_response_rule(self, user_profile, message,
                                                   is_from_simulator):
        #response_rule = qa_util.find_unmatch_answer_for(user_profile.webapp_id)
        #从缓存中获取数据  duhao  2015-03-09
        response_rule = cache_util.find_unmatch_answer_from_cache_for(
            user_profile)

        if response_rule and response_rule.is_active:
            #sdwex = self._get_token_for_weixin_user(user_profile, message.fromUserName, is_from_simulator)
            if response_rule.material_id > 0:
                response = generator.get_news_response(message.fromUserName,
                                                       message.toUserName,
                                                       response_rule.newses,
                                                       message.fromUserName)
            else:
                if is_from_simulator:
                    response = generator.get_text_response(
                        message.fromUserName, message.toUserName,
                        emotion.change_emotion_to_img(response_rule.answer),
                        message.fromUserName, user_profile)
                else:
                    response = generator.get_text_response(
                        message.fromUserName, message.toUserName,
                        response_rule.answer, message.fromUserName,
                        user_profile)

            return response_rule, response
        else:
            return None, None
    def _build_response_to_weixin_user(self, user_profile, message,
                                       response_rule, is_from_simulator):
        from_weixin_user = self._get_from_weixin_user(message)
        token = self._get_token_for_weixin_user(user_profile, from_weixin_user,
                                                is_from_simulator)

        if is_from_simulator:
            response = generator.get_text_response(
                from_weixin_user.username, message.toUserName,
                emotion.change_emotion_to_img(response_rule.answer), token,
                user_profile)
        else:
            response = generator.get_text_response(from_weixin_user.username,
                                                   message.toUserName,
                                                   response_rule.answer, token,
                                                   user_profile)

        return response
Exemplo n.º 3
0
    def _handle_keyword(self, context, from_weixin_user, is_from_simulator):
        user_id = context.user_profile.user_id
        username = User.objects.get(id=user_id).username
        if username != 'weshop':
            # request = context.request
            message = context.message
            response = None
            response_rule = None
            response_content = None
            try:
                webapp_owner_id = context.user_profile.user_id
                keyword = message.content
                openid = message.fromUserName
                webapp_id = context.user_profile.webapp_id
                response_content = Resource.use('marketapp_apiserver').post({
                    'resource':
                    'sign.do_auto_signment',
                    'data': {
                        'webapp_owner_id': webapp_owner_id,
                        'keyword': keyword,
                        'openid': openid,
                        'webapp_id': webapp_id
                    }
                })
                response_content = response_content['data']
                if response_content:
                    response = generator.get_text_response(
                        message.fromUserName, message.toUserName,
                        response_content, message.fromUserName,
                        context.user_profile)

                    try:
                        self._process_recorde_message(context, response_rule,
                                                      from_weixin_user,
                                                      is_from_simulator)
                    except:
                        notify_message = u"_process_recorde_message, cause:\n{}".format(
                            unicode_full_stack())
                        message_tail = '\nanswer:%s,patterns:%s,owner_id:%d,id:%d' % (
                            response_rule.answer, response_rule.patterns,
                            response_rule.owner_id, response_rule.id)
                        notify_message += message_tail
                        watchdog_error(notify_message)

                return response
            except:
                return None
        else:
            return None
Exemplo n.º 4
0
    def _handle_keyword(self, context, from_weixin_user, is_from_simulator):
        # request = context.request
        message = context.message
        response = None
        response_rule = None
        response_content = None
        data = {}
        try:
            data['webapp_owner_id'] = context.user_profile.user_id
            data['keyword'] = message.content
            data['openid'] = message.fromUserName
            data['webapp_id'] = context.user_profile.webapp_id

            response_content = check_keyword(data)

            if response_content:
                response = generator.get_text_response(message.fromUserName,
                                                       message.toUserName,
                                                       response_content,
                                                       message.fromUserName,
                                                       context.user_profile)

                try:
                    self._process_recorde_message(context, response_rule,
                                                  from_weixin_user,
                                                  is_from_simulator)
                except:
                    notify_message = u"_process_recorde_message, cause:\n{}".format(
                        unicode_full_stack())
                    message_tail = '\nanswer:%s,patterns:%s,owner_id:%d,id:%d' % (
                        response_rule.answer, response_rule.patterns,
                        response_rule.owner_id, response_rule.id)
                    notify_message += message_tail
                    watchdog_error(notify_message)

            return response
        except:
            return None
Exemplo n.º 5
0
	def _build_response_to_weixin_user(self, user_profile, message, from_weixin_user, response_text, is_from_simulator):
		token = self._get_token_for_weixin_user(user_profile, from_weixin_user, is_from_simulator)
		response = generator.get_text_response(from_weixin_user.username, message.toUserName, response_text, token, user_profile)
		return response
Exemplo n.º 6
0
    def _handle_keyword(self, context, from_weixin_user, is_from_simulator):
        # request = context.request
        message = context.message
        user_profile = context.user_profile
        print '===========0', message.msgType, user_profile.user_id
        response = None
        response_rule = None
        response_content = None
        if message.msgType == WeixinMessageTypes.TEXT and user_profile.user_id in [
                632, 119
        ]:
            content = message.content
            if content and content.strip().startswith('sxsdj'):
                member = get_member_by_openid(message.fromUserName,
                                              user_profile.webapp_id)
                print member, '==============23423'
                if member:
                    print '===============1', content, '--', SheDe.objects.filter(
                        number=content.strip()).count()
                    if SheDe.objects.filter(
                            number=content.strip()).count() > 0:
                        print '===============2'
                        #if SheDeLog.objects.filter(member_id=member.id).count() == 0:
                        print '===============3'
                        with transaction.atomic():
                            print '===============4'
                            she_de = SheDe.objects.select_for_update().get(
                                number=content.strip())
                            print '===============5'
                            if she_de.is_send is False:
                                print '===============6'
                                increase_member_integral(
                                    member, she_de.integral, u'活动奖励')

                                she_de.is_send = True
                                she_de.save()
                                SheDeLog.objects.create(member_id=member.id,
                                                        shede=she_de)
                                response_content = u'恭喜您获得的舍得酒业100积分已充值到<a href="http://%s/termite/workbench/jqm/preview/?module=user_center&model=user_info&action=get&workspace_id=mall&webapp_owner_id=%s&project_id=0">个人中心-我的积分</a>' % (
                                    user_profile.host, user_profile.user_id)
                            else:
                                response_content = u'抱歉,该验证码已使用!'
                    else:
                        response_content = u'抱歉,验证码错误!'

        if response_content:
            response = generator.get_text_response(message.fromUserName,
                                                   message.toUserName,
                                                   response_content,
                                                   message.fromUserName,
                                                   user_profile)

            try:
                self._process_recorde_message(context, response_rule,
                                              from_weixin_user,
                                              is_from_simulator)
            except:
                notify_message = u"_process_recorde_message, cause:\n{}".format(
                    unicode_full_stack())
                message_tail = '\nanswer:%s,patterns:%s,owner_id:%d,id:%d' % (
                    response_rule.answer, response_rule.patterns,
                    response_rule.owner_id, response_rule.id)
                notify_message += message_tail
                print notify_message
                watchdog_error(notify_message)

        return response
Exemplo n.º 7
0
	def handle(self, context, is_from_simulator=False):
		message = context.message

		if message.is_optimization_message:
			print 'ChannelDistributionQrcodeHandler only handle is_optimization_message = true'
			return None

		username = message.fromUserName
		user_profile = context.user_profile
		member = context.member

		if not hasattr(context.message, 'event'):
			return None

		if not hasattr(context.message, 'ticket') or context.message.ticket is None:
			return None
		ticket = context.message.ticket

		if not hasattr(context.message, 'eventKey') or context.message.eventKey is None or ticket == '':
			return None

		if member and (hasattr(member, 'is_new') is False):
			member.is_new = False

		#优化处理
		if hasattr(context, 'is_member_qrcode') and (context.is_member_qrcode is True):
			return None

		# 一 将信息添加到ChannelDistributionQrcodeHasMember中
		# 二 将扫码的会员添加到新分组中
		channel_distribution_qrcode_has_member = ChannelDistributionQrcodeHasMember.objects.filter(member_id=member.id)
		if channel_distribution_qrcode_has_member:  # 如果这个会员已经绑定到别人的二维码下:
			return None
		else:
			qrcode = ChannelDistributionQrcodeSettings.objects.filter(ticket=ticket)  # 得到ticket绑定的二维码数据
			if qrcode:
				ChannelDistributionQrcodeHasMember.objects.create(
					channel_qrcode_id = qrcode[0].id,
					member_id = member.id,
				)
				qrcode.update(bing_member_count = F('bing_member_count') + 1)
				# 得到需要绑定的member分组
				group_id = qrcode[0].group_id
				# 添加到得到的分组
				MemberHasTag.add_tag_member_relation(member, [group_id])
				# 发放优惠券
				award_prize_info = json.loads(qrcode[0].award_prize_info)
				if award_prize_info['type'] == u"优惠券":
					coupon_id = award_prize_info['id']  # 优惠券id
					consume_coupon(qrcode[0].owner.id, coupon_id, member.id)
				elif award_prize_info['type'] == u"积分":
					# 发放积分
					award = award_prize_info['id']  # 扫码奖励积分
					increase_member_integral(member, award, u'推荐扫码奖励')

				# 扫码回复
				msg_type, detail = get_response_msg_info_restructure(qrcode[0], user_profile)
				if msg_type != None:
					# from_weixin_user = self._get_from_weixin_user(message)
					# token = self._get_token_for_weixin_user(user_profile, from_weixin_user, is_from_simulator)
					if msg_type == 'text' and detail:
						if is_from_simulator:
							return generator.get_text_response(username, message.toUserName,
								emotion.change_emotion_to_img(detail), username,
								user_profile)
						else:
							return generator.get_text_response(username, message.toUserName, detail, username,
															   user_profile)
					if msg_type == 'news' and get_material_news_info(detail):
						news = get_material_news_info(detail)
						return generator.get_news_response(username, message.toUserName, news, username)
				else:
					return None
			else:
				return None
		return None
Exemplo n.º 8
0
    def _handle_keyword(self, context, from_weixin_user, is_from_simulator):
        # request = context.request
        message = context.message
        user_profile = context.user_profile
        print '===========0', message.msgType, user_profile.user_id
        response = None
        response_rule = None
        response_content = None
        if message.msgType == WeixinMessageTypes.TEXT and user_profile.user_id in [
                151, 570
        ]:
            content = message.content
            if content and content.strip().isdigit() and len(
                    content.strip()) == 11:
                response_content = u'感谢亲的关注,「一盒甜品」老朋友活动已经结束了哦!但是亲还是可以优惠价尝鲜哦~<a href="http://weapp.weizoom.com/workbench/jqm/preview/?module=mall&model=product&action=get&rid=3813&workspace_id=mall&webapp_owner_id=570">点击我购买</a>'
                #member = get_member_by_openid( message.fromUserName, user_profile.webapp_id)
                #print member,'==============23423'

                #if member:
                # print '===============1',content, '--',WoFu.objects.filter(phone_number=content.strip()).count()
                # if WoFu.objects.filter(phone_number=content.strip()).count() > 0:
                # 	# print '===============2'
                # 	# if WoFuLog.objects.filter(member_id=member.id).count() == 0:
                # 	# 	print '===============3'
                # 	# 	with transaction.atomic():
                # 	# 		print '===============4'
                # 	# 		wo_fu = WoFu.objects.select_for_update().get(phone_number=content.strip())
                # 	# 		print '===============5'
                # 	# 		if wo_fu.is_send is False:
                # 	# 			print '===============6'
                # 	# 			coupon,error_msg = consume_coupon(user_profile.user_id, wo_fu.coupon_rule_id, member.id)
                # 	# 			print '===============7',coupon,error_msg
                # 	# 			if coupon:
                # 	# 				print '===============8'
                # 	# 				wo_fu.is_send = True
                # 	# 				wo_fu.save()
                # 	# 				WoFuLog.objects.create(member_id=member.id, wofu=wo_fu)
                # 	# 				if wo_fu.level == 1:
                # 	# 					response_content = u'您的订购就是窝夫小子的人生!我们一辈子努力的事儿,就是让您订上一款满意的蛋糕!感谢时空变换中您依旧相伴的这些年,虽未谋面,但我们已彼此熟悉,老朋友,为感谢您一直都在,冰箱里的新宠“一盒甜品”的优惠券已经躺在您的个人中心了,点击窝·服务-个人中心-我的优惠券,只需39元(原价139元)即可购买!<a href="http://%s/termite/workbench/jqm/preview/?module=user_center&model=user_info&action=get&workspace_id=mall&webapp_owner_id=%s&project_id=0">戳我进入个人中心</a>' % (user_profile.host, user_profile.user_id)
                # 	# 				elif wo_fu.level == 2:
                # 	# 					response_content = u'您的订购就是窝夫小子的人生!我们一辈子努力的事儿,就是让您订上一款满意的蛋糕!感谢时空变换中您依旧相伴的这些年,虽未谋面,但我们已彼此熟悉,老朋友,为感谢您一直都在,根据您过去的购买记录,冰箱里的新宠“一盒甜品”的优惠券已经躺在您的个人中心了,点击窝•服务-个人中心-我的优惠券,只需69元(原价139元)即可购买!<a href="http://%s/termite/workbench/jqm/preview/?module=user_center&model=user_info&action=get&workspace_id=mall&webapp_owner_id=%s&project_id=0">戳我进入个人中心</a>' % (user_profile.host, user_profile.user_id)
                # 	# 				elif wo_fu.level == 3:
                # 	# 					response_content = u'您的订购就是窝夫小子的人生!我们一辈子努力的事儿,就是让您订上一款满意的蛋糕!感谢时空变换中您依旧相伴的这些年,虽未谋面,但您的人生已经留下窝夫小子的痕迹,为感谢您对窝夫小子的支持,根据您过去的购买记录,冰箱里的新宠“一盒甜品”的优惠券已经躺在您的个人中心了,点击窝•服务-个人中心-我的优惠券,只需99元(原价139元)即可购买!<a href="http://%s/termite/workbench/jqm/preview/?module=user_center&model=user_info&action=get&workspace_id=mall&webapp_owner_id=%s&project_id=0">戳我进入个人中心</a>' % (user_profile.host, user_profile.user_id)
                # 	# 				# elif wo_fu.level == 4:
                # 	# 				# 	response_content = u'虽未谋面,但您的人生已经留下窝夫小子的痕迹,作为新朋友,多想看看首次品尝后您幸福的笑容,您的一个订单,就是窝夫小子默默努力一辈子的事情,绝对不能懈怠的决心让我们坚持品质超过10余年,为感谢您对窝夫小子的支持,窝夫小子刚刚上架的新宠“一盒甜品”欢迎尝鲜价选购!'
                # 	# 			else:
                # 	# 				response_content = u'老朋友决不能冒名取代,每一个老朋友对于窝夫小子来说都是独一无二的,您的手机号已经领取过相应的优惠券,本次活动一个微信号只对应一个老朋友资格的手机号,不支持帮朋友查询哦~您可以邀请您的朋友关注窝夫小子蛋糕公众号亲自参与活动哦'
                # 	# 		else:
                # 	# 			response_content = u'老朋友决不能冒名取代,每一个老朋友对于窝夫小子来说都是独一无二的,您的手机号已经领取过相应的优惠券,本次活动一个微信号只对应一个老朋友资格的手机号,不支持帮朋友查询哦~您可以邀请您的朋友关注窝夫小子蛋糕公众号亲自参与活动哦~'
                # 	else:
                # 		response_content = u'老朋友决不能冒名取代,每一个老朋友对于窝夫小子来说都是独一无二的,您的手机号已经领取过相应的优惠券,本次活动一个微信号只对应一个老朋友资格的手机号,不支持帮朋友查询哦~您可以邀请您的朋友关注窝夫小子蛋糕公众号亲自参与活动哦~'
                # else:
                # 	response_content = u'虽未谋面,但您的人生已经留下窝夫小子的痕迹,作为新朋友,多想看看首次品尝后您幸福的笑容,您的一个订单,就是窝夫小子默默努力一辈子的事情,绝对不能懈怠的决心让我们坚持品质超过10余年,为感谢您对窝夫小子的支持,冰箱里的新宠“一盒甜品”现在尝鲜价只需119元~快快点击链接尝鲜吧~<a href="http://weapp.weizoom.com/termite/workbench/jqm/preview/?module=mall&model=product&action=get&rid=3813&workspace_id=mall&webapp_owner_id=570">点击我购买</a>'

        if response_content:
            response = generator.get_text_response(message.fromUserName,
                                                   message.toUserName,
                                                   response_content,
                                                   message.fromUserName,
                                                   user_profile)

            try:
                self._process_recorde_message(context, response_rule,
                                              from_weixin_user,
                                              is_from_simulator)
            except:
                notify_message = u"_process_recorde_message, cause:\n{}".format(
                    unicode_full_stack())
                message_tail = '\nanswer:%s,patterns:%s,owner_id:%d,id:%d' % (
                    response_rule.answer, response_rule.patterns,
                    response_rule.owner_id, response_rule.id)
                notify_message += message_tail
                print notify_message
                watchdog_error(notify_message)

        return response