Beispiel #1
0
def index():
    logging.info('*' * 50)
    union_id = session.get('union_id', '')
    target_union_id = session.get('target_union_id', '')
    logging.info('index session target_union_id:%s' % (target_union_id))
    if not target_union_id:
        target_union_id = request.args.get('union_id', '')
        logging.info('index request.args  target_union_id:%s' %
                     (target_union_id))
        logging.info('index request.form  target_union_id:%s' %
                     (request.form.get('union_id', '')))
    if not target_union_id:
        logging.info('index no  target_union_id')
        return redirect('/?union_id=%s' % union_id)
    logging.info('index union_id:%s, target_union_id:%s' %
                 (union_id, target_union_id))
    if union_id != target_union_id:
        cheer_num = get_odbc_inst().get_cheer_num(target_union_id)
        remain_cheer_num = get_remain_cheer_num(cheer_num)
        logging.info('target_cheer_num:%s' % cheer_num)
        session['target_union_id'] = ''
        return render_template('cheer.html',
                               union_id=union_id,
                               target_union_id=target_union_id,
                               remain_cheer_num=remain_cheer_num,
                               satisfy_cheer_num=SATISFY_CHEER_NUM)
    else:
        cheer_num = get_odbc_inst().get_cheer_num(union_id)
        remain_cheer_num = get_remain_cheer_num(cheer_num)
        return render_template('index.html',
                               union_id=union_id,
                               remain_cheer_num=remain_cheer_num,
                               satisfy_cheer_num=SATISFY_CHEER_NUM)
Beispiel #2
0
def index():
    logging.info('*' * 50)
    union_id = session.get('union_id', '')
    target_union_id = session.get('target_union_id', '')
    logging.info('index session target_union_id:%s' % (target_union_id))
    if not target_union_id:
        target_union_id = request.args.get('union_id', '')
        logging.info('index request.args  target_union_id:%s' % (target_union_id))
        logging.info('index request.form  target_union_id:%s' % (request.form.get('union_id', '')))
    if not target_union_id:
        logging.info('index no  target_union_id')
        return redirect('/?union_id=%s' % union_id)
    logging.info('index union_id:%s, target_union_id:%s' % (union_id, target_union_id))
    if union_id != target_union_id:
        cheer_num = get_odbc_inst().get_cheer_num(target_union_id)
        remain_cheer_num = get_remain_cheer_num(cheer_num)
        logging.info('target_cheer_num:%s' % cheer_num)
        session['target_union_id'] = ''
        return render_template('cheer.html', union_id=union_id, target_union_id=target_union_id,
                               remain_cheer_num=remain_cheer_num, satisfy_cheer_num=SATISFY_CHEER_NUM)
    else:
        cheer_num = get_odbc_inst().get_cheer_num(union_id)
        remain_cheer_num = get_remain_cheer_num(cheer_num)
        return render_template('index.html', union_id=union_id, remain_cheer_num=remain_cheer_num,
                               satisfy_cheer_num=SATISFY_CHEER_NUM)
Beispiel #3
0
def get_wx_ticket():
    cache_info = get_odbc_inst().get_cache(WX_TICKET)
    code = cache_info['code']
    wx_ticket = cache_info['cache']
    if code != RIGHT:
        urls = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi" % get_base_access_token()
        res = url_get(urls)
        wx_ticket = res.get('ticket', '')
        if wx_ticket:
            get_odbc_inst().save_cache(wx_ticket, WX_TICKET)
    return wx_ticket
Beispiel #4
0
def get_wx_ticket():
    cache_info = get_odbc_inst().get_cache(WX_TICKET)
    code = cache_info['code']
    wx_ticket = cache_info['cache']
    if code != RIGHT:
        urls = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi" % get_base_access_token(
        )
        res = url_get(urls)
        wx_ticket = res.get('ticket', '')
        if wx_ticket:
            get_odbc_inst().save_cache(wx_ticket, WX_TICKET)
    return wx_ticket
Beispiel #5
0
def get_base_access_token():
    cache_info = get_odbc_inst().get_cache(BASE_TOKEN)
    code = cache_info['code']
    access_token = cache_info['cache']
    if code != RIGHT:
        urls = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s" % (
            APPID, APPSECRET)
        res = url_get(urls)
        access_token = res.get('access_token', '')
        if access_token:
            get_odbc_inst().save_cache(access_token, BASE_TOKEN)
    return access_token
Beispiel #6
0
def get_base_access_token():
    cache_info = get_odbc_inst().get_cache(BASE_TOKEN)
    code = cache_info['code']
    access_token = cache_info['cache']
    if code != RIGHT:
        urls = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s" % (
        APPID, APPSECRET)
        res = url_get(urls)
        access_token = res.get('access_token', '')
        if access_token:
            get_odbc_inst().save_cache(access_token, BASE_TOKEN)
    return access_token
Beispiel #7
0
def async_cheer():
    union_id = request.form.get('union_id', '')
    target_union_id = request.form.get('target_union_id', '')
    code = RIGHT
    if not union_id:
        code = CHEER_UNION_ID_IS_NULL
    elif not target_union_id:
        code = CHEER_TARGET_UNION_ID_IS_NULL
    else:
        code = get_odbc_inst().cheer(union_id, target_union_id)
    if code == RIGHT:
        target_cheer_num = get_odbc_inst().get_cheer_num(target_union_id)
        target_remain_cheer_num = get_remain_cheer_num(target_cheer_num)
        return json.dumps({'code': code, 'target_remain_cheer_num': target_remain_cheer_num})
    else:
        return json.dumps({'code': code})
Beispiel #8
0
def async_cheer():
    union_id = request.form.get('union_id', '')
    target_union_id = request.form.get('target_union_id', '')
    code = RIGHT
    if not union_id:
        code = CHEER_UNION_ID_IS_NULL
    elif not target_union_id:
        code = CHEER_TARGET_UNION_ID_IS_NULL
    else:
        code = get_odbc_inst().cheer(union_id, target_union_id)
    if code == RIGHT:
        target_cheer_num = get_odbc_inst().get_cheer_num(target_union_id)
        target_remain_cheer_num = get_remain_cheer_num(target_cheer_num)
        return json.dumps({
            'code': code,
            'target_remain_cheer_num': target_remain_cheer_num
        })
    else:
        return json.dumps({'code': code})
Beispiel #9
0
def get_cheer_info():
    code = RIGHT
    target_union_id = request.args.get('union_id', '')
    logging.info('get_cheer_info target_union_id:%s' % target_union_id)
    if not target_union_id:
        code = GET_CHEER_INFO_NO_UNION_ID
    cheer_info = get_odbc_inst().get_cheer_info(target_union_id)
    if not cheer_info:
        code = GET_CHEER_INFO_FAILED
    return json.dumps({'code': code, 'cheer_info': cheer_info})
Beispiel #10
0
def callback():
    logging.info('-' * 50)
    code = request.args.get('code', '')
    state = request.args.get('state')
    if code:
        code_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?' \
                   'appid=%s&secret=%s&code=%s&grant_type=authorization_code' % (APPID, APPSECRET, code)
        res = url_get(code_url)
        session['access_token'] = res['access_token']
        session['open_id'] = res['openid']
        user_info = get_user_info()
        logging.info('callback user_info:%s' % user_info)
        session['union_id'] = user_info['union_id']
        get_odbc_inst().register_user(user_info)
        args = session.get('target_union_id', '')
        logging.info('callbak target_union_id:%s' % args)
        if not args:
            args = user_info['union_id']
    return redirect('/?union_id=%s' % args)
Beispiel #11
0
def get_cheer_info():
    code = RIGHT
    target_union_id = request.args.get('union_id', '')
    logging.info('get_cheer_info target_union_id:%s' % target_union_id)
    if not target_union_id:
        code = GET_CHEER_INFO_NO_UNION_ID
    cheer_info = get_odbc_inst().get_cheer_info(target_union_id)
    if not cheer_info:
        code = GET_CHEER_INFO_FAILED
    return json.dumps({'code': code, 'cheer_info': cheer_info})
Beispiel #12
0
def callback():
    logging.info('-' * 50)
    code = request.args.get('code', '')
    state = request.args.get('state')
    if code:
        code_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?' \
                   'appid=%s&secret=%s&code=%s&grant_type=authorization_code' % (APPID, APPSECRET, code)
        res = url_get(code_url)
        session['access_token'] = res['access_token']
        session['open_id'] = res['openid']
        user_info = get_user_info()
        logging.info('callback user_info:%s' % user_info)
        session['union_id'] = user_info['union_id']
        get_odbc_inst().register_user(user_info)
        args = session.get('target_union_id', '')
        logging.info('callbak target_union_id:%s' % args)
        if not args:
            args = user_info['union_id']
    return redirect('/?union_id=%s' % args)