def get(self): self.check_input('openid') try: studentId = User.get_by_openid(self.input['openid']).student_id except: studentId = '' return studentId
def get(self): self.check_input('openid', 'ticket') user = User.get_by_openid(self.input['openid']) student_id = user.student_id detail = Ticket.get_a_ticket(student_id, self.input['ticket']) detail['currentTime'] = int(datetime.datetime.now().timestamp()) return detail
def post(self): print("UserBind post") self.check_input('openid', 'student_id', 'password') user = User.get_by_openid(self.input['openid']) self.validate_user() user.student_id = self.input['student_id'] user.save()
def validate_user(self): user = User.get_by_openid(self.input['openid']) stuId = self.input['student_id'] try: User.objects.get(student_id=self.input['student_id']) except: user.student_id = stuId user.save() else: raise ValidateError("Existed student_id")
def get(self): self.check_input('openid', 'ticket') user = User.get_by_openid(self.input['openid']) ticket = Ticket.objects.get(unique_id=self.input['ticket']) act = Activity.objects.get(id=ticket.activity_id) return { 'activityName': act.name, 'place': act.place, 'activityKey': act.key, 'uniqueId': ticket.unique_id, 'startTime': act.start_time.timestamp(), 'endTime': act.end_time.timestamp(), 'currentTime': datetime.datetime.now().timestamp(), 'status': ticket.status } ###########################################################################
def handle(self): confirm = WechatConfirmation.get_or_create() if self.user.student_id == '': return self.reply_text('请先进行绑定') try: user = User.get_by_openid(self.user.open_id) except: raise LogicError('no such open_id') hw_num = 0 info_num = 0 url = 'http://se.zhuangty.com:8000/curriculum/' params = {user.student_id} response = requests.post('http://se.zhuangty.com:8000/learnhelper/' + user.student_id + '/courses') if response.status_code == 200: res = json.loads(response.content.decode()) for course in res['courses']: info_num += course['unreadnotice'] hw_num += course['unsubmittedoperations'] else: raise LogicError('Response Error') message_model = MessageModel() timenow = stamp_to_localstr_minute(current_stamp()) model = message_model.create_remind_model(self.user.open_id, hw_num, info_num, timenow) model_url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' model_url += confirm.get_access_token() res = requests.post(model_url, data=json.dumps(model)) return self.reply_text('欢迎使用提醒功能')
def get(self): self.check_input('openid') return User.get_by_openid(self.input['openid']).student_id
def post(self): self.check_input('openid', 'student_id', 'password') user = User.get_by_openid(self.input['openid']) self.validate_user() user.student_id = self.input['student_id'] user.save()