def subEvent(msg): data = tools.client.user.get(msg.source) try: username = data["nickname"] users = User.objects.filter(openId=msg.source) if len(users) > 0: user = users[0] else: user = User(name=data["nickname"], sex=int(data["sex"]), openId=msg.source, comment=u"现在还是空的><") user.save() team = Team(name=basic_tools.teamName(None, username), type=0) team.save() team.members.add(user) user.name = username user.uid = int(random.random() * 100) if "headimgurl" in data: user.image = data["headimgurl"] user.save() date = basic_tools.getDate() #如果DayData不存在,则创建 if DayData.objects.filter(user=user, date=date).count() == 0: dayData = DayData(user=user, date=date) basic_tools.updateDayData(dayData, user) dayData.save() except: username = "" return HttpResponse( create_reply(u"%s!欢迎使用新中韩无敌了的手环公众号!\n%s" % (username, tools.help_text), message=msg))
def subEvent(msg): data = tools.client.user.get(msg.source) try: username = data["nickname"] users = User.objects.filter(openId=msg.source) if len(users) > 0: user = users[0] else: user = User(name=data["nickname"],sex=int(data["sex"]),openId=msg.source,comment=u"现在还是空的><") user.save() team = Team(name=basic_tools.teamName(None, username),type=0) team.save() team.members.add(user) user.name = username user.uid = int(random.random() * 100) if "headimgurl" in data: user.image = data["headimgurl"] user.save() date = basic_tools.getDate() #如果DayData不存在,则创建 if DayData.objects.filter(user=user,date=date).count() == 0: dayData = DayData(user=user,date=date) basic_tools.updateDayData(dayData, user) dayData.save() except: username = "" return HttpResponse(create_reply(u"%s!欢迎使用新中韩无敌了的手环公众号!\n%s" % (username, tools.help_text), message=msg))