def step_impl(context, webapp_user_name, shared_webapp_user_name): webapp_owner_id = context.webapp_owner_id user = User.objects.get(id=webapp_owner_id) openid = "%s_%s" % (webapp_user_name, user.username) member = member_api.get_member_by_openid(openid, context.webapp_id) followed_member = Member.objects.get( username_hexstr=byte_to_hex(shared_webapp_user_name)) if member: new_url = url_helper.remove_querystr_filed_from_request_path( context.shared_url, 'fmt') new_url = url_helper.remove_querystr_filed_from_request_path( new_url, 'opid') context.shared_url = "%s&fmt=%s" % (new_url, followed_member.token) response = context.client.get(context.shared_url) if response.status_code == 302: print('[info] redirect by change fmt in shared_url') redirect_url = bdd_util.nginx(response['Location']) context.last_url = redirect_url response = context.client.get(bdd_util.nginx(redirect_url)) else: print('[info] not redirect') context.last_url = context.shared_url context.api_response = __get_red_packet_informations( context, webapp_owner_id, context.red_packet_rule_id, openid, context.page_owner_member_id).content print('context.api_response') print(context.api_response)
def step_impl(context, webapp_user_name, webapp_owner_name, survey_name): webapp_owner_id = context.webapp_owner_id user = User.objects.get(id=context.webapp_owner_id) openid = "%s_%s" % (webapp_user_name, user.username) survey_id = __get_survey_id(survey_name) member = member_api.get_member_by_openid(openid, context.webapp_id) response = __get_into_survey_pages(context, webapp_owner_id, survey_id, openid) if member: is_already_participanted = (surveyParticipance.objects( belong_to=str(survey_id), member_id=member.id).count() > 0) else: is_already_participanted = False if is_already_participanted: context.survey_hint = u'您已参与' else: activity_status = response.context['activity_status'] if activity_status == u'已结束': context.survey_hint = u'活动已结束' elif activity_status == u'未开始': context.survey_hint = u'请等待活动开始...' elif activity_status == u'进行中': permission = response.context['permission'] isMember = response.context['isMember'] if permission == 'member': if isMember: __participate_survey(context, webapp_owner_id, survey_id) else: pass #弹二维码 else: __participate_survey(context, webapp_owner_id, survey_id) response_json = context.response_json if response_json['code'] == 200: context.survey_hint = u"提交成功"
def step_tmpl(context, webapp_user_name, mp_user_name): context.execute_steps(u"when %s关注%s的公众号" % (webapp_user_name, mp_user_name)) webapp_owner_id = context.webapp_owner_id user = User.objects.get(id=webapp_owner_id) openid = "%s_%s" % (webapp_user_name, user.username) member = member_api.get_member_by_openid(openid, context.webapp_id) # 因没有可用的API处理Member相关的source字段, 暂时直接操作Member对象 Member.objects.filter(id=member.id).update(source=SOURCE_MEMBER_QRCODE)
def step_impl(context, webapp_user_name, webapp_owner_name, survey_name, date): context.termite_data = json.loads(context.text) context.execute_steps(u"When %s参加%s的用户调研活动'%s'" % (webapp_user_name, webapp_owner_name, survey_name)) date = bdd_util.get_date(date) survey_id = __get_survey_id(survey_name) user = User.objects.get(id=context.webapp_owner_id) openid = "%s_%s" % (webapp_user_name, user.username) member = member_api.get_member_by_openid(openid, context.webapp_id) #修改参与时间 survey_info = surveyParticipance.objects.get(member_id=member.id, belong_to=str(survey_id)) survey_info.update(set__created_at=date)
def step_impl(context, webapp_user_name, shared_webapp_user_name): webapp_owner_id = context.webapp_owner_id user = User.objects.get(id=webapp_owner_id) openid = "%s_%s" % (webapp_user_name, user.username) member = member_api.get_member_by_openid(openid, context.webapp_id) if member.is_subscribed: #非会员不可签到 appRecordId = __get_exsign_record_id(webapp_owner_id) params = { 'webapp_owner_id': webapp_owner_id, 'id': appRecordId } response = context.client.post('/m/apps/exsign/api/exsign_participance/?_method=put', params) else: pass
def step_impl(context, webapp_owner_name): for row in context.table: webapp_user_name = row['member_name'] if webapp_user_name[0] == u'-': webapp_user_name = webapp_user_name[1:] #clear last member's info in cookie and context context.execute_steps(u"When 清空浏览器") else: context.execute_steps(u"When 清空浏览器") context.execute_steps(u"When %s访问%s的webapp" % (webapp_user_name, webapp_owner_name)) data = { 'webapp_user_name': webapp_user_name, 'powerme_value': row['powerme_value'], 'parti_time': bdd_util.get_datetime_str(row['parti_time']), 'name': row['name'] } webapp_owner_id = context.webapp_owner_id user = User.objects.get(id=webapp_owner_id) openid = "%s_%s" % (webapp_user_name, user.username) power_me_rule_id = str(__get_power_me_rule_id(data['name'])) member = member_api.get_member_by_openid(openid, context.webapp_id) #先进入微助力页面 response = __get_into_power_me_pages(context, webapp_owner_id, power_me_rule_id, openid) context.power_me_rule_id = power_me_rule_id context.rank_response = __get_power_me_rank_informations( context, webapp_owner_id, power_me_rule_id, openid).content context.execute_steps(u"when %s把%s的微助力活动链接分享到朋友圈" % (webapp_user_name, webapp_owner_name)) powered_member_info = PowerMeParticipance.objects.get( member_id=member.id, belong_to=power_me_rule_id) powered_member_info.update(set__created_at=data['parti_time']) i = 0 webapp_test_user_name = 'test_user_' while i < int(data['powerme_value']): i += 1 context.execute_steps(u"When 清空浏览器") context.execute_steps( u"When %s关注%s的公众号" % (webapp_test_user_name + str(i), webapp_owner_name)) context.execute_steps( u"When %s访问%s的webapp" % (webapp_test_user_name + str(i), webapp_owner_name)) context.execute_steps( u"When %s点击%s分享的微助力活动链接进行助力" % (webapp_test_user_name + str(i), webapp_user_name)) context.execute_steps(u"When 更新助力排名")
def step_impl(context, webapp_user_name, shared_webapp_user_name): webapp_owner_id = context.webapp_owner_id user = User.objects.get(id=webapp_owner_id) openid = "%s_%s" % (shared_webapp_user_name, user.username) member = module_api.get_member_by_openid(openid, context.webapp_id) if member: new_url = url_helper.remove_querystr_filed_from_request_path(context.shared_url, 'fmt') context.shared_url = "%s&fmt=%s" % (new_url, member.token) response = context.client.get(context.shared_url) if response.status_code == 302: redirect_url = bdd_util.nginx(response['Location']) context.last_url = redirect_url response = context.client.get(bdd_util.nginx(redirect_url)) else: print('[info] not redirect') context.last_url = context.shared_url
def step_tmpl(context, webapp_user_name, event_name, date): webapp_owner_id = context.webapp_owner_id user = User.objects.get(id=context.webapp_owner_id) openid = "%s_%s" % (webapp_user_name, user.username) date = bdd_util.get_date(date) event_rule_id = __get_event_rule_id(event_name) member = member_api.get_member_by_openid(openid, context.webapp_id) response = __get_into_event_pages(context, webapp_owner_id, event_rule_id, openid) if member: is_already_participanted = (eventParticipance.objects( belong_to=str(event_rule_id), member_id=member.id).count() > 0) else: is_already_participanted = False if is_already_participanted: context.event_hint = u'您已报名' else: activity_status = response.context['activity_status'] if activity_status == u'已结束': context.event_hint = u'活动已结束' elif activity_status == u'未开始': context.event_hint = u'请等待活动开始...' elif activity_status == u'进行中': permission = response.context['permission'] isMember = response.context['isMember'] if permission == 'member': if isMember: __participate_event(context, webapp_owner_id, event_rule_id) #修改参与时间 event_info = eventParticipance.objects.get( member_id=member.id, belong_to=str(event_rule_id)) event_info.update(set__created_at=date) else: pass #弹二维码 else: __participate_event(context, webapp_owner_id, event_rule_id) #修改参与时间 event_info = eventParticipance.objects.get( member_id=member.id, belong_to=str(event_rule_id)) event_info.update(set__created_at=date) response_json = context.response_json if response_json['code'] == 200: context.event_hint = u"提交成功"
def do_auto_signment(data): """ 回复关键字自动签到 :param data: 字典 :包含 webapp_owner_id, openid, keyword, webapp_id :return: html片段 """ return_html = [] sign_description = "" host = settings.DOMAIN try: sign = Sign.objects.get(owner_id=data['webapp_owner_id']) checking_result = check_matched_keyword(data['keyword'], sign.reply['keyword']) if checking_result: if sign.status != 1: return_html.append(u'签到活动未开始') else: # add by bert 增加获取会员代码 member = get_member_by_openid(data['openid'], data['webapp_id']) if not member: return None #设置的最大连续签到天数 max_setting_count = sorted(map(lambda x: int(x), sign.prize_settings.keys()), reverse=True)[0] signer = SignParticipance.objects(member_id=member.id, belong_to=str(sign.id)) if signer.count() == 0: signer = SignParticipance( belong_to=str(sign.id), member_id=member.id, prize={ 'integral': 0, 'coupon': '' }, created_at=datetime.datetime.today()) signer.save() else: signer = signer[0] #如果已达到最大设置天数则重置签到 if (signer.serial_count == max_setting_count and signer.latest_date and signer.latest_date.strftime('%Y-%m-%d') != datetime.datetime.now().strftime('%Y-%m-%d')) or ( max_setting_count != 0 and signer.serial_count > max_setting_count): signer.update(set__serial_count=0, set__latest_date=None) signer.reload() pagestore = pagestore_manager.get_pagestore('mongo') page = pagestore.get_page(sign.related_page_id, 1) sign_description = page['component']['components'][0][ 'model']['description'] return_data = signer.do_signment(sign) detail_dict = { 'belong_to': str(sign.id), 'member_id': member.id, 'created_at': datetime.datetime.today(), 'type': u'自动签到', 'prize': { 'integral': 0, 'coupon': { 'id': 0, 'name': '' } } } if return_data['status_code'] == RETURN_STATUS_CODE[ 'ALREADY']: return_html.append(u'亲,今天您已经签到过了哦,\n明天再来吧!') if return_data['status_code'] == RETURN_STATUS_CODE[ 'SUCCESS']: detail_prize_dict = { 'integral': 0, 'coupon': { 'id': 0, 'name': '' } } return_html.append(u'签到成功!\n已连续签到%s天。\n本次签到获得以下奖励:\n' % return_data['serial_count']) return_html.append( str(return_data['curr_prize_integral'])) return_html.append(u'积分') detail_prize_dict['integral'] = str( return_data['curr_prize_integral']) if return_data[ 'curr_prize_coupon_name'] != '' and return_data[ 'curr_prize_coupon_count'] >= 0: if return_data['curr_prize_coupon_count'] > 0: return_html.append( '\n' + str(return_data['curr_prize_coupon_name'])) return_html.append( u'\n<a href="http://%s/termite/workbench/jqm/preview/?module=market_tool:coupon&model=usage&action=get&workspace_id=market_tool:coupon&webapp_owner_id=%s&project_id=0">点击查看</a>' % (host, data['webapp_owner_id'])) detail_prize_dict['coupon'] = { 'id': return_data['curr_prize_coupon_id'], 'name': str(return_data['curr_prize_coupon_name']) } else: return_html.append(u'\n奖励已领完,请联系客服补发') detail_prize_dict['coupon'] = { 'id': return_data['curr_prize_coupon_id'], 'name': u'优惠券已领完,请联系客服补发' } return_html.append(u'\n签到说明:%s\n' % sign_description) return_html.append(str(return_data['reply_content'])) detail_dict['prize'] = detail_prize_dict #记录签到历史 details = SignDetails(**detail_dict) details.save() return_html.append( u'\n<a href="http://%s/m/apps/sign/m_sign/?webapp_owner_id=%s"> >>点击查看详情</a>' % (host, data['webapp_owner_id'])) else: return None except Exception, e: print e return None
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