def test(self): c = Client() response = c.post(self.Url, trans_dict_to_xml(self.postTextMsg), content_type='text/xml') self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'news.xml') self.assertContains(response, origin_trans_str({'Title':self.act.name})) self.assertContains(response, origin_trans_str({'Description': self.act.description})) self.assertContains(response, origin_trans_str({'Url': settings.get_url('u/ticket',{'openid':self.postTextMsg['FromUserName'],'ticket':'123'})})) self.postTextMsg['Content'] = '取票 act_absent' response = c.post(self.Url, trans_dict_to_xml(self.postTextMsg), content_type='text/xml') self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'text.xml') self.assertContains(response, '未找到该活动!') self.postTextMsg['Content'] = '取票 act2' response = c.post(self.Url, trans_dict_to_xml(self.postTextMsg), content_type='text/xml') self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'text.xml') self.assertContains(response, '你没有该活动的票!')
def handle(self): if not self.user.student_id: return self.reply_text('需要绑定学号') if not Ticket.objects.filter(student_id=self.user.student_id): return self.reply_text('没有抢到的票') tickets = [] tics = Ticket.objects.all() for tic in tics: if tic.status == Ticket.STATUS_VALID and tic.student_id == self.user.student_id: tic_info = { 'Title': '电子票的活动名称 : ' + str(Activity.objects.get(id=tic.activity_id).name), 'Url': get_url('u/ticket', { 'openid': self.user.open_id, 'ticket': tic.unique_id }), } tickets.append(tic_info) return self.reply_news(tickets)
def handle(self): activity_key = self.input['Content'][3:] if self.user.student_id: activities = Activity.objects.filter(key=activity_key) if len(activities) == 1: tickets = Ticket.objects.filter( activity_id=activities[0].id, student_id=self.user.student_id, status=Ticket.STATUS_VALID) if len(tickets) == 1: i = tickets[0] article = { 'Title': '票:%s' % activities[0].name, 'Description': activities[0].description, 'PicUrl': activities[0].pic_url, 'Url': settings.get_url('u/ticket', { 'openid': self.user.open_id, 'ticket': i.unique_id }) } return self.reply_single_news(article=article) elif len(tickets) == 0: return self.reply_text('不存在未使用的票') return self.reply_text('查票出错') return self.reply_text('活动查询出错') return self.reply_text(self.get_message('bind_account'))
def handle(self): articles = [] if self.user.student_id: activity_ids = MenuIdList.get_menu() if activity_ids == 'Lock': return self.reply_text('管理员正在更新,请稍后再试') available_articles = Activity.objects.filter( id__in=activity_ids, book_start__lt=timezone.now(), book_end__gt=timezone.now(), status=Activity.STATUS_PUBLISHED) if len(available_articles) == 0: return self.reply_text('暂无活动') for i in available_articles: articles.append({ 'Title': '活动:%s' % i.name, 'Description': i.description, 'PicUrl': i.pic_url, 'Url': settings.get_url('u/activity', {'id': i.id}) }) return self.reply_news(articles=articles) return self.reply_text(self.get_message('bind_account'))
def handle(self): activity_list = Activity.objects.filter( status=Activity.STATUS_PUBLISHED) if activity_list.exists(): articles = [] for activity in activity_list: calibration_begintime = ( activity.start_time + timedelta(hours=8)).strftime("%Y-%m-%d %H:%M:%S") calibration_endtime = ( activity.book_end + timedelta(hours=8)).strftime("%Y-%m-%d %H:%M:%S") result = { 'Title': activity.name, 'Description': '开始时间:' + calibration_begintime + activity.description + '\n抢票结束时间:' + calibration_endtime, 'PicUrl': activity.pic_url, 'Url': settings.get_url("/u/activity/", {"id": activity.id}), } articles.append(result) return self.reply_news(articles) else: return self.reply_text("当前活动尚不可抢票")
def handle(self): if not self.user.student_id: return self.reply_text("请先绑定姓名学号") key = self.input['Content'][3:] try: activity = Activity.objects.get(key=key, status=Activity.STATUS_PUBLISHED) ticket = Ticket.objects.get(student_id=self.user.student_id, status=Ticket.STATUS_VALID, activity_id=activity.id) if ticket: calibration_begintime = ( activity.start_time + timedelta(hours=8)).strftime("%Y-%m-%d %H:%M:%S") messages = { 'Title': activity.name, 'Description': '开始时间:' + calibration_begintime + '\n地点:' + activity.place, 'PicUrl': activity.pic_url, 'Url': settings.get_url("/u/ticket/", { "openid": self.user.open_id, "ticket": ticket.unique_id }), } return self.reply_single_news(messages) return self.reply_text("抱歉,您并没有该活动的门票") except: return self.reply_text("抱歉,您并没有该活动的门票")
def test(self): c = Client() response = c.post(self.Url, trans_dict_to_xml(self.postClickMsg), content_type='text/xml') self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'text.xml') self.assertContains(response, '没有可以订票的活动!') act = Activity.objects.create(name='ganshuota', key='ganshuota', description='ganshuota', start_time=datetime(2019, 10, 20, 2, 31, 0), end_time=datetime(2019, 11, 8, 23, 59, 59), place='hell', book_start=datetime(2018, 10, 10, 8, 8, 8), book_end=datetime(2019, 10, 20, 0, 0, 0), total_tickets=100, status=Activity.STATUS_PUBLISHED, pic_url='https://www.pornhub.com/ycdfwzy.png', remain_tickets=2 ) response = c.post(self.Url, trans_dict_to_xml(self.postTextMsg), content_type='text/xml') self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'news.xml') self.assertContains(response, origin_trans_str({'Title': 'ganshuota'})) self.assertContains(response, origin_trans_str({'Description': 'ganshuota'})) self.assertContains(response, origin_trans_str({'Url': settings.get_url('u/activity', {'id':act.id})}))
def handle(self): details = [] if not self.user.student_id: return self.reply_text("您还未绑定") tickets = Ticket.objects.filter(student_id=self.user.student_id, status=Ticket.STATUS_VALID) if not tickets: return self.reply_text("没有票可用") else: for item in tickets: activity = Activity.objects.get( id=item.activity_id, status=Activity.STATUS_PUBLISHED) details.append({ 'Title': activity.name, 'Description': activity.description, 'PicUrl': activity.pic_url, 'Url': settings.get_url("/u/ticket", { 'openid': self.user.open_id, 'ticket': item.unique_id }) }) return self.reply_news(details)
def handle(self): if not self.user.student_id: return self.reply_text("您还没有绑定,绑定后才可使用该功能") ticket_list = Ticket.objects.filter(student_id=self.user.student_id, status=Ticket.STATUS_VALID) if not ticket_list.exists(): return self.reply_text("当前没有已购的票, 您可点击菜单栏中“抢啥”查看现有活动") articles = [] for ticket in ticket_list: activity = ticket.activity calibration_time = ( activity.start_time + timedelta(hours=8)).strftime("%Y-%m-%d %H:%M:%S") messages = { 'Title': activity.name, 'Description': '开始时间:' + calibration_time + '\n地点:' + activity.place, 'Url': settings.get_url("/u/ticket/", { "openid": self.user.open_id, "ticket": ticket.unique_id }), } articles.append(messages) return self.reply_news(articles)
def test(self): #通过 response.content 访问response内容 c = Client() response = c.post(self.Url, trans_dict_to_xml(self.postClickMsg), content_type='text/xml') self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'text.xml') self.assertContains(response, '你还没有票!') response = c.post(self.Url, trans_dict_to_xml(self.postTextMsg), content_type='text/xml') self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'text.xml') self.assertEqual(Activity.objects.get(name='gansita').remain_tickets, 49) unique_id = Ticket.objects.get(student_id='1234567890').unique_id response = c.post(self.Url, trans_dict_to_xml(self.postClickMsg), content_type='text/xml') self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'news.xml') # print("what the hell", response.content) self.assertContains(response, origin_trans_str({'Title':'gansita'})) self.assertContains(response, origin_trans_str({'Description':'gansita'})) self.assertContains(response, origin_trans_str({'Url': settings.get_url('u/ticket',{'openid':self.postClickMsg['FromUserName'],'ticket':unique_id})}))
def activity_to_new(self, activity): new = {} new['Title'] = activity.name new['Description'] = activity.description new['Url'] = settings.get_url('u/activity?id=' + str(activity.id)) new['PicUrl'] = activity.pic_url return new
def handle(self): if not self.user.student_id: return self.reply_text(self.get_message('bind_account')) this_user = self.user activity_key = self.input['Content'][3:] owned_tickets = Ticket.objects.filter(student_id=this_user.student_id, activity__key=activity_key) if len(owned_tickets) == 0: return self.reply_text('您还没有订票!') ticket = owned_tickets[0] if ticket.status == Ticket.STATUS_CANCELLED: return self.reply_text('您已把这张票退了!') tickets = [] for ticket in owned_tickets: tickets.append({ 'Url': settings.get_url('/u/ticket', { 'openid': this_user.open_id, 'ticket': ticket.unique_id }), 'Title': '%s' % ticket.activity.name, 'Description': ticket.activity.description, 'PicUrl': ticket.activity.pic_url }) return self.reply_news(articles=tickets)
def ticket_to_new(self, ticket): new = {} activity = ticket.activity new['Title'] = activity.name new['Description'] = activity.description new['Url'] = settings.get_url('u/ticket?ticket=' + str( ticket.unique_id)) + '&openid=' + str(self.user.open_id) return new
def handle(self): acts = [] if not self.user.student_id: return self.reply_text(self.get_message('bind_account')) act_list = Activity.objects.filter(status=Activity.STATUS_PUBLISHED) for item in act_list: acts.append({ 'Url': settings.get_url('u/activity', {'id': item.id}), 'Title': '%s' % item.name, 'Description': item.description, 'PicUrl': item.pic_url }) return self.reply_news(articles=acts)
def handle(self): recent_activities = self.get_recent_activities() if not recent_activities: return self.reply_text(self.get_message('book_empty')) article_list = [] for activity in recent_activities: article = {} article['Title'] = activity.name article['Description'] = activity.description article['Url'] = settings.get_url('u/activity', {'id': activity.id}) article['PicUrl'] = activity.pic_url article_list.append(article) return self.reply_news(article_list)
def handle(self): activities = [] acts = Activity.objects.all() for act in acts: if act.book_end.timestamp() > datetime.datetime.now().timestamp(): act_info = { 'Title': act.name, 'Description': act.description, 'PicUrl': act.pic_url, 'Url': get_url('u/activity', {'id': act.id}), } activities.append(act_info) return self.reply_news(activities)
def handle(self): if self.user.student_id == "": return self.reply_text(self.get_message('not_bind')) user_tickets = self.get_tickets() if not user_tickets: return self.reply_text(self.get_message('user_no_ticket')) article_list = [] for ticket in user_tickets: article = {} article['Title'] = ticket.activity.name + ":电子票" article['Description'] = "点击查看电子票详情" ticket_open_id = User.objects.get( student_id=ticket.student_id).open_id article['Url'] = settings.get_url('u/ticket', { 'openid': ticket_open_id, 'ticket': ticket.unique_id }) article_list.append(article) return self.reply_news(article_list)
def get_ticket_detail(self, ticket): activity = ticket.activity description = '活动时间:' + (activity.start_time + datetime.timedelta(hours=8)).strftime("%Y-%m-%d %H:%M:%S") + \ '\n活动地点:' + activity.place + \ '\n回复“退票 ' + activity.key + '”即可退票' result = { 'Title': activity.name, 'Description': description, 'Url': settings.get_url("/u/ticket/", { "openid": self.user.open_id, "ticket": ticket.unique_id }), } return result
def handle(self): details = [] activities = Activity.objects.filter(status=Activity.STATUS_PUBLISHED) if activities: for item in activities: details.append({ 'Title': item.name, 'Description': item.description, 'PicUrl': item.pic_url, 'Url': settings.get_url("/u/activity", {"id": item.id}) }) return self.reply_news(details) else: return self.reply_text(self.get_message('bind_account'))
def getConfList(interface, user_id, page, page_size): getUrl = 'http://60.205.137.139/adminweb/REST/API-V2/'+interface+'?userid=' + user_id + \ '&page=' + str(page) + '&page_size=' + str(page_size) retInfo = requests.get(getUrl) retInfo = retInfo.json() news = [] if (retInfo['code'] == 0): conf = retInfo['data'] length = len(conf) for i in range(0, length): news.append({ 'Title': conf[i]['name'], 'PicUrl': 'http://60.205.137.139/adminweb/' + conf[i]['image'], 'Url': settings.get_url('u/conference', { 'conf_id': str(conf[i]['id']), 'user_id': user_id }) }) return news
def handle(self): if not self.user.student_id: return self.reply_text(self.get_message('bind_account')) tickets = [] this_user = self.user ticket_list = Ticket.get_by_studentId(student_id=this_user.student_id) if len(ticket_list) == 0: return self.reply_text('您还没有订票!') for ticket in ticket_list: tickets.append({ 'Url': settings.get_url('/u/ticket', { 'openid': this_user.open_id, 'ticket': ticket.unique_id }), 'Title': '%s' % ticket.activity.name, 'Description': ticket.activity.description, 'PicUrl': ticket.activity.pic_url }) return self.reply_news(articles=tickets)
def get(self): conf_id = self.input['conf_id'] with open('configs.json', 'r') as f: data = json.load(f) appid = data['WECHAT_APPID'] secret = data['WECHAT_SECRET'] get_access_token_url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' + appid \ + '&secret=' + secret r = requests.get(get_access_token_url) print (r.text) access_token = r.json()['access_token'] requestUrl = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' + access_token template_id = "v7_-4_4is1o6UdwEJtko_UXPuA-4P_AA42epeF-QcZw" for user in User.objects.all(): if (user.user_id == ""): continue if checkFollower(conf_id, user.user_id): moreinfourl = settings.get_url('u/conference', {'conf_id': str(conf_id), 'user_id': user.user_id}) postUrl = 'http://60.205.137.139/adminweb/REST/API-V2/confInfo?confid=' + str(conf_id) retInfo = requests.get(postUrl).json() message = '{"touser":"******","template_id":"%(template_id)s","url":"%(url)s","data":{"conference":{"value":"%(conf_name)s","color":"#173177"}}}' \ % {"open_id": user.open_id, "template_id": template_id, "url": moreinfourl, "conf_name" : retInfo['data']['basic']['name']} message = message.encode('utf-8') requests.post(requestUrl, data=message).json()
def handle(self): articles = [] if self.user.student_id: available_articles = Ticket.objects.filter( student_id=self.user.student_id, status=Ticket.STATUS_VALID) if len(available_articles) == 0: return self.reply_text('暂无可用票') for i in available_articles: activity = Activity.objects.get(id=i.activity_id) articles.append({ 'Title': '票:%s' % activity.name, 'Description': activity.description, 'PicUrl': activity.pic_url, 'Url': settings.get_url('u/ticket', { 'openid': self.user.open_id, 'ticket': i.unique_id }) }) return self.reply_news(articles=articles) return self.reply_text(self.get_message('bind_account'))
def url_bind(self): return settings.get_url('u/bind', {'openid': self.user.open_id})
def url_help(self): return settings.get_url('u/help')
def url_book_ticket(self, ticket_id): return settings.get_url('u/ticket', { 'openid': self.user.open_id, 'ticket': ticket_id })
def url_book_what(self, activity_id): return settings.get_url('u/activity', {'id': activity_id})
def url_help(self): return settings.get_url('u/help')
def url_bind(self): return settings.get_url('u/bind', {'openid': self.user.open_id})
def url_ticket_detail(self, unique_id): temp = unique_id return settings.get_url('u/ticket', { 'openid': self.user.open_id, 'ticket': unique_id })
def url_activity_detail(self, act_id): return settings.get_url('u/activity', {'id': act_id})
def url_ticket_detail(self, open_id, unique_id): return settings.get_url('u/ticket', { 'ticket': unique_id, 'openid': open_id })