示例#1
0
def ajax_10(request):
    """
    给别人吐槽
    :param request:
        注意此处的source_id是推送的人的id,就是谁触发事件的
    :return:
    """
    response = HttpResponse()
    response['Content-Type'] = 'text/javascript'
    user_id = request.POST.get('openid', '')
    source_id = request.POST.get('source_id', '')
    tucao_con = request.POST.get('tucao_con', '')
    ret = '0'
    if user_id and source_id and tucao_con:
        user = User.objects.get(openid=user_id)
        user.count = user.count - 8000
        user.save()
        tucao = Tree(owner=user, tree_name=user.tree_name, type=6, action_time=time.time(), read=False,
                    source_id=source_id, content=tucao_con)
        tucao.save()
        ret = '1'
    else:
        ret = '2'
    response.write(ret)
    return response
示例#2
0
def ajax_10(request):
    """
    给别人吐槽
    :param request:
        注意此处的source_id是推送的人的id,就是谁触发事件的
    :return:
    """
    response = HttpResponse()
    response['Content-Type'] = 'text/javascript'
    user_id = request.POST.get('openid', '')
    source_id = request.POST.get('source_id', '')
    tucao_con = request.POST.get('tucao_con', '')
    ret = '0'
    if user_id and source_id and tucao_con:
        user = User.objects.get(openid=user_id)
        user.count = user.count - 8000
        user.save()
        tucao = Tree(owner=user,
                     tree_name=user.tree_name,
                     type=6,
                     action_time=time.time(),
                     read=False,
                     source_id=source_id,
                     content=tucao_con)
        tucao.save()
        ret = '1'
    else:
        ret = '2'
    response.write(ret)
    return response
示例#3
0
def ajax_8(request):
    """
    输入心愿提交到服务器
    :param request:
    :return:
    """
    response = HttpResponse()
    response['Content-Type'] = 'text/javascript'
    user_id = request.POST.get('openid', '')
    will_con = request.POST.get('will_con', '')
    ret = '0'
    if user_id and will_con:
        user = User.objects.get(openid=user_id)
        will = Tree(owner=user, tree_name=user.tree_name, type=2, action_time=time.time(), read=True, source_id=user_id,
                    content=will_con)
        if user.willing == 'none':
            user.count = user.count + 20000
        user.willing = 'yes'
        will.save()
        user.save()
        ret = '1'
    else:
        ret = '2'
    response.write(ret)
    return response
示例#4
0
def ajax_9(request):
    """
    :param request:
        给别人祝福,注意此处的_sourceid是推送的人的id,就是谁触发事件的
    :return:
    """
    response = HttpResponse()
    # response['Content-Type'] = 'text/javascript'
    user_id = request.POST.get('openid', '')
    source_id = request.POST.get('source_id', '')
    bless_con = request.POST.get('bless_con', '')
    ret = '0'
    if user_id and source_id and bless_con:
        user = User.objects.get(openid=user_id)
        user.count = user.count + 5000
        user.save()
        bless = Tree(owner=user,
                     tree_name=user.tree_name,
                     type=5,
                     action_time=time.time(),
                     read=False,
                     source_id=source_id,
                     content=bless_con)
        bless.save()
        ret = '1'
    else:
        ret = '2'
    response.write(ret)
    return response
示例#5
0
def ajax_8(request):
    """
    输入心愿提交到服务器
    :param request:
    :return:
    """
    response = HttpResponse()
    response['Content-Type'] = 'text/javascript'
    user_id = request.POST.get('openid', '')
    will_con = request.POST.get('will_con', '')
    ret = '0'
    if user_id and will_con:
        user = User.objects.get(openid=user_id)
        will = Tree(owner=user,
                    tree_name=user.tree_name,
                    type=2,
                    action_time=time.time(),
                    read=True,
                    source_id=user_id,
                    content=will_con)
        if user.willing == 'none':
            user.count = user.count + 20000
        user.willing = 'yes'
        will.save()
        user.save()
        ret = '1'
    else:
        ret = '2'
    response.write(ret)
    return response
示例#6
0
def ajax_1(request):
    """
    ajax_type='1': 第一次种树填入树名字时候保存到数据库
    :param request:
    :return:
    """
    response = HttpResponse()
    response['Content-Type'] = 'text/javascript'
    user_id = request.POST.get('openid', '')
    user_name = request.POST.get('nickname', '')
    tree_name = request.POST.get('tree_name', '')
    if user_id and user_name and tree_name:
        try:
            user = User.objects.get(openid=user_id)
            user.is_plant = True
            user.nickname = user_name
            user.tree_name = tree_name
            user.friends.add(user)
            friend = user.friends.exclude(openid=user_id)[0]
            # friend = User.objects.get(openid=friend_id.openid)
            friend.count = friend.count + 3000
            friend.save()
            user.save()
            msg = Tree(owner=friend, tree_name=friend.tree_name, type=4, action_time=time.time(),
                       read=False, source_id=user_id, content='成功添加好友'+user_name)
            msg.save()
            tree = Tree(owner=user, tree_name=user.tree_name, type=7, action_time=time.time(),
                        source_id=user_id, content='种下了自己的幸福树')
            tree.save()
            ret = '4'
        except ObjectDoesNotExist:
            user = User(openid=user_id, nickname=user_name, time_stamp=time.time(), tree_name=tree_name)
            user.save()
            user.friends.add(user)
            user.save()
            tree = Tree(owner=user, tree_name=tree_name, type=7, action_time=time.time(), read=True, source_id=user_id,
                        content='创建了祝福树')
            tree.save()
            ret = '3'
    else:
        ret = '2'
    response.write(ret)
    return response
示例#7
0
def ajax_9(request):
    """
    :param request:
        给别人祝福,注意此处的_sourceid是推送的人的id,就是谁触发事件的
    :return:
    """
    response = HttpResponse()
    # response['Content-Type'] = 'text/javascript'
    user_id = request.POST.get('openid', '')
    source_id = request.POST.get('source_id', '')
    bless_con = request.POST.get('bless_con', '')
    ret = '0'
    if user_id and source_id and bless_con:
        user = User.objects.get(openid=user_id)
        user.count = user.count + 5000
        user.save()
        bless = Tree(owner=user, tree_name=user.tree_name, type=5, action_time=time.time(),
                        read=False, source_id=source_id, content=bless_con)
        bless.save()
        ret = '1'
    else:
        ret = '2'
    response.write(ret)
    return response
示例#8
0
def ajax_4(request):
    """
    浇水成功提交积分上去
    :param request:
    :return:
    """
    response = HttpResponse()
    response['Content-Type'] = 'application/json'
    user_id = request.POST.get('openid', '')
    source_id = request.POST.get('source_id', '')
    if user_id:
        user = User.objects.get(openid=user_id)
        if user_id == source_id:
            type = 0
        else:
            type = 3
        Tree(owner=user,
             tree_name=user.tree_name,
             count=user.count,
             type=type,
             action_time=time.time(),
             source_id=source_id,
             content=User.objects.get(openid=source_id).nickname +
             '给树木浇水了').save()

        user.count = user.count + 1000
        if source_id:
            try:
                friend = user.friends.get(openid=source_id)
            except ObjectDoesNotExist:
                friend = 0
            if friend != 0:
                user.friends.add(User.objects.get(
                    openid=source_id))  # 通过朋友圈啊什么的浇水,自己浇水的时候自己是自己的朋友
        user.save()
        ret = '1'
    else:
        ret = '2'
    response.write(ret)
    return response
示例#9
0
文件: views.py 项目: q7940/blessTree
def visit(request):
    """
    处理访问别人的主页的逻辑
    :param sourceid: 谁的空间
    :return:
    """

    sourceid = request.GET.get('openid', '')
    code = request.GET.get('code', '')

    high_verify = request.GET.get('state', '')
    if high_verify == 'high_verify':
        oauth_vis = WeChatOAuth(appId, appsecret, 'http://1.blesstree.sinaapp.com/wechat/visit'+'?openid='+sourceid)
    else:
        oauth_vis = WeChatOAuth(appId, appsecret,
                                'http://1.blesstree.sinaapp.com/wechat/visit'+'?openid='+sourceid,
                                scope='snsapi_userinfo',
                                state='high_verify')

    # 这里是防止用户种树后取消关注了(不种树了)老的链接被别人点进去了
    error = False
    try:
        client.fetch_access_token()
        owner_info = client.user.get(client, sourceid)
        owner = owner_info['nickname']
        avatar = owner_info['headimgurl']
        owner_db = User.objects.get(openid=sourceid)
        water_time = 0  # TODO:时间转化问题
        count = owner_db.count
        count_bar = count/3000
        tree_name = owner_db.tree_name
    except KeyError:
        pass
    try:
        User.objects.get(openid=sourceid, is_plant=False)
        error = True
    except ObjectDoesNotExist:
        pass

    # ios系统返回按钮出现的bug的解决方法
    try:
        access_token = oauth_vis.fetch_access_token(code)
    except KeyError:
        # access_token = oauth_vis.access_token = code_access_token[code]['access_token']
        # oauth_vis.open_id = code_access_token[code]['openid']
        return HttpResponseRedirect(oauth_vis.authorize_url)

    try:
        flip_id = openid = oauth_vis.open_id
    except AttributeError:
        flip_id = openid = code_access_token[code]['openid']

    # 经过高级用户认证后的访问就有了获取头像与昵称的能力
    flip_nickname = False
    if high_verify == 'high_verify':
        flip_user = oauth_vis.get_user_info(openid=flip_id, access_token=access_token)
        fl_nickname = flip_nickname = flip_user['nickname']
        flip_avatar = flip_user['headimgurl']
        flip_nickname = True
    else:
        # TODO:这里是没有关注公众号的时候用户点进去,想祝福/吐槽/浇水/的时候
        try:
            client.fetch_access_token()
            user_from_wechat = client.user.get(client, flip_id)
            fl_nickname = flip_nickname = user_from_wechat['nickname']
            flip_avatar = user_from_wechat['headimgurl']
        except KeyError:
            flip_nickname = False
            # 获取一个高级认证作为点击浇水/祝福/吐槽事件的跳转链接,认证之后回调到原来的位置
            btn_redirect_url = WeChatOAuth(appId, appsecret,
                                           'http://1.blesstree.sinaapp.com/wechat/visit'+'?openid='+sourceid,
                                           scope='snsapi_userinfo',
                                           state='high_verify').authorize_url

    try:
        user = User.objects.get(openid=openid, is_plant=True)
    except ObjectDoesNotExist:
        user = 0

    if user is not 0:
        # 用户已经中树,因为只有关注用户才能种树,不关注用户只能评论吐槽,但是朋友关系要保存
        try:
            user.friends.get(openid=sourceid)
        except ObjectDoesNotExist:
            user.friends.add(User.objects.get(openid=sourceid))
            user.save()
            msg = Tree(owner=owner_db, tree_name=owner_db.tree_name, type=4, action_time=time.time(),
                           read=False, source_id=user.openid, content='成功添加好友'+user.nickname)
            msg.save()
        my_zone_url = WeChatOAuth(appId, appsecret, 'http://1.blesstree.sinaapp.com/wechat/home/').authorize_url
        return render_to_response('visit.html', locals())

    # 用户没有种树,点击按钮都会跳到认证链接来获取信息,获取的信息要保存
    my_zone_url = WeChatOAuth(appId, appsecret,
                              'http://1.blesstree.sinaapp.com/wechat/home/'+"?visit_index='123'&return_openid="+sourceid)\
        .authorize_url
    if flip_nickname:  # 通过点击别人分享进去的都需要保存,这里互动了的
        try:
            friendship = User.objects.get(openid=flip_id)
            friendship.nickname = fl_nickname
            friendship.avatar_url = flip_avatar
            friendship.save()
        except ObjectDoesNotExist:
            friendship = User(openid=flip_id, nickname=fl_nickname,
                              avatar_url=flip_avatar, time_stamp=time.time(),
                              tree_name='na', is_plant=False)
            friendship.save()
            source_fr = User.objects.get(openid=sourceid)
            friendship.friends.add(source_fr)  # 保存朋友关系,只是此时保存的关系的友人尚未种树
            friendship.save()
    elif request.GET.get('add'):  # 通过点击别人分享进去的都需要保存,这里用户只是点击进去过没有互动
        try:
            friendship = User.objects.get(openid=flip_id)
        except ObjectDoesNotExist:
            friendship = User(openid=oauth_vis.open_id, nickname='na', time_stamp=time.time(), tree_name='na', is_plant=False)
            friendship.save()
            source_fr = User.objects.get(openid=sourceid)
            friendship.friends.add(source_fr)  # 保存朋友关系,只是此时保存的关系的友人尚未种树
            friendship.save()
    return render_to_response('visit.html', locals())
示例#10
0
def visit(request):
    """
    处理访问别人的主页的逻辑
    :param sourceid: 谁的空间
    :return:
    """

    sourceid = request.GET.get('openid', '')
    code = request.GET.get('code', '')

    high_verify = request.GET.get('state', '')
    if high_verify == 'high_verify':
        oauth_vis = WeChatOAuth(
            appId, appsecret, 'http://1.blesstree.sinaapp.com/wechat/visit' +
            '?openid=' + sourceid)
    else:
        oauth_vis = WeChatOAuth(appId,
                                appsecret,
                                'http://1.blesstree.sinaapp.com/wechat/visit' +
                                '?openid=' + sourceid,
                                scope='snsapi_userinfo',
                                state='high_verify')

    # 这里是防止用户种树后取消关注了(不种树了)老的链接被别人点进去了
    error = False
    try:
        client.fetch_access_token()
        owner_info = client.user.get(client, sourceid)
        owner = owner_info['nickname']
        avatar = owner_info['headimgurl']
        owner_db = User.objects.get(openid=sourceid)
        water_time = 0  # TODO:时间转化问题
        count = owner_db.count
        count_bar = count / 3000
        tree_name = owner_db.tree_name
    except KeyError:
        pass
    try:
        User.objects.get(openid=sourceid, is_plant=False)
        error = True
    except ObjectDoesNotExist:
        pass

    # ios系统返回按钮出现的bug的解决方法
    try:
        access_token = oauth_vis.fetch_access_token(code)
    except KeyError:
        # access_token = oauth_vis.access_token = code_access_token[code]['access_token']
        # oauth_vis.open_id = code_access_token[code]['openid']
        return HttpResponseRedirect(oauth_vis.authorize_url)

    try:
        flip_id = openid = oauth_vis.open_id
    except AttributeError:
        flip_id = openid = code_access_token[code]['openid']

    # 经过高级用户认证后的访问就有了获取头像与昵称的能力
    flip_nickname = False
    if high_verify == 'high_verify':
        flip_user = oauth_vis.get_user_info(openid=flip_id,
                                            access_token=access_token)
        fl_nickname = flip_nickname = flip_user['nickname']
        flip_avatar = flip_user['headimgurl']
        flip_nickname = True
    else:
        # TODO:这里是没有关注公众号的时候用户点进去,想祝福/吐槽/浇水/的时候
        try:
            client.fetch_access_token()
            user_from_wechat = client.user.get(client, flip_id)
            fl_nickname = flip_nickname = user_from_wechat['nickname']
            flip_avatar = user_from_wechat['headimgurl']
        except KeyError:
            flip_nickname = False
            # 获取一个高级认证作为点击浇水/祝福/吐槽事件的跳转链接,认证之后回调到原来的位置
            btn_redirect_url = WeChatOAuth(
                appId,
                appsecret,
                'http://1.blesstree.sinaapp.com/wechat/visit' + '?openid=' +
                sourceid,
                scope='snsapi_userinfo',
                state='high_verify').authorize_url

    try:
        user = User.objects.get(openid=openid, is_plant=True)
    except ObjectDoesNotExist:
        user = 0

    if user is not 0:
        # 用户已经中树,因为只有关注用户才能种树,不关注用户只能评论吐槽,但是朋友关系要保存
        try:
            user.friends.get(openid=sourceid)
        except ObjectDoesNotExist:
            user.friends.add(User.objects.get(openid=sourceid))
            user.save()
            msg = Tree(owner=owner_db,
                       tree_name=owner_db.tree_name,
                       type=4,
                       action_time=time.time(),
                       read=False,
                       source_id=user.openid,
                       content='成功添加好友' + user.nickname)
            msg.save()
        my_zone_url = WeChatOAuth(
            appId, appsecret,
            'http://1.blesstree.sinaapp.com/wechat/home/').authorize_url
        return render_to_response('visit.html', locals())

    # 用户没有种树,点击按钮都会跳到认证链接来获取信息,获取的信息要保存
    my_zone_url = WeChatOAuth(appId, appsecret,
                              'http://1.blesstree.sinaapp.com/wechat/home/'+"?visit_index='123'&return_openid="+sourceid)\
        .authorize_url
    if flip_nickname:  # 通过点击别人分享进去的都需要保存,这里互动了的
        try:
            friendship = User.objects.get(openid=flip_id)
            friendship.nickname = fl_nickname
            friendship.avatar_url = flip_avatar
            friendship.save()
        except ObjectDoesNotExist:
            friendship = User(openid=flip_id,
                              nickname=fl_nickname,
                              avatar_url=flip_avatar,
                              time_stamp=time.time(),
                              tree_name='na',
                              is_plant=False)
            friendship.save()
            source_fr = User.objects.get(openid=sourceid)
            friendship.friends.add(source_fr)  # 保存朋友关系,只是此时保存的关系的友人尚未种树
            friendship.save()
    elif request.GET.get('add'):  # 通过点击别人分享进去的都需要保存,这里用户只是点击进去过没有互动
        try:
            friendship = User.objects.get(openid=flip_id)
        except ObjectDoesNotExist:
            friendship = User(openid=oauth_vis.open_id,
                              nickname='na',
                              time_stamp=time.time(),
                              tree_name='na',
                              is_plant=False)
            friendship.save()
            source_fr = User.objects.get(openid=sourceid)
            friendship.friends.add(source_fr)  # 保存朋友关系,只是此时保存的关系的友人尚未种树
            friendship.save()
    return render_to_response('visit.html', locals())
示例#11
0
def ajax_1(request):
    """
    ajax_type='1': 第一次种树填入树名字时候保存到数据库
    :param request:
    :return:
    """
    response = HttpResponse()
    response['Content-Type'] = 'text/javascript'
    user_id = request.POST.get('openid', '')
    user_name = request.POST.get('nickname', '')
    tree_name = request.POST.get('tree_name', '')
    if user_id and user_name and tree_name:
        try:
            user = User.objects.get(openid=user_id)
            user.is_plant = True
            user.nickname = user_name
            user.tree_name = tree_name
            user.friends.add(user)
            friend = user.friends.exclude(openid=user_id)[0]
            # friend = User.objects.get(openid=friend_id.openid)
            friend.count = friend.count + 3000
            friend.save()
            user.save()
            msg = Tree(owner=friend,
                       tree_name=friend.tree_name,
                       type=4,
                       action_time=time.time(),
                       read=False,
                       source_id=user_id,
                       content='成功添加好友' + user_name)
            msg.save()
            tree = Tree(owner=user,
                        tree_name=user.tree_name,
                        type=7,
                        action_time=time.time(),
                        source_id=user_id,
                        content='种下了自己的幸福树')
            tree.save()
            ret = '4'
        except ObjectDoesNotExist:
            user = User(openid=user_id,
                        nickname=user_name,
                        time_stamp=time.time(),
                        tree_name=tree_name)
            user.save()
            user.friends.add(user)
            user.save()
            tree = Tree(owner=user,
                        tree_name=tree_name,
                        type=7,
                        action_time=time.time(),
                        read=True,
                        source_id=user_id,
                        content='创建了祝福树')
            tree.save()
            ret = '3'
    else:
        ret = '2'
    response.write(ret)
    return response