Beispiel #1
0
def get_qq_code():
    res = {'code':1000,'msg':'success'}
    codee = request.args.get("code")
    if not codee:
        logger.info('fail|code arg not found, return')
        return handle_param_error()

    try:
        logger.info('get qq codee:%s'%codee)

        loginS = QQLoginService(appid=QQ_APP_ID, secret=QQ_APP_SECRET)
        token,obj,expires = loginS.get_user_info_by_code(codee)
        if not (token and obj):
            logger.info('fail|get_user_info_by_code fail,code:%s, return'%codee)
            res['code'] = -1
            res['msg'] = 'login fail'
            return jsonify(res)

        #chuan_id = get_chuan_id_by_openid(openid)
        ps = ProfileService()
        userid = ps.insert_user_profile(obj)

        #nickname = urllib.quote(obj['nickname'])
        #usericon = urllib.quote(obj['usericon'])
        #expires  = urllib.quote(expires)

        logger.info('token:%s, obj:%s, expires:%s, userid:%s'%(token,obj,expires,userid))

        return redirect("http://nbstorage.sparta.html5.qq.com/qq/code/result?token=%s&userid=%s"%(token,userid), code=302)
    except:
        res = handle_failure()
        logger.error('fail|exception|ub request serve error|%s' % traceback.format_exc())

    return res
Beispiel #2
0
def get_weixin_code():
    res = {'code':1000,'msg':'success'}
    codee = request.args.get("code")
    if not codee:
        logger.info('fail|code arg not found, return')
        return handle_param_error()

    try:
        logger.info('get weixin codee:%s'%codee)

        loginS = WeiXinLoginService(appid=WX_APP_ID, secret=WX_APP_SECRET)
        token,obj = loginS.get_user_info_by_code(codee)
        obj['uid_type'] = 2
        if not (token and obj):
            logger.info('fail|get_user_info_by_code fail,code:%s, return'%codee)
            return handle_failure()


        #chuan_id = get_chuan_id_by_openid(openid)
        ps = ProfileService()
        userid = ps.insert_user_profile(obj)
        if not userid:
            obj    = ps.get_user_profile_by_uid(obj['openid'])
            if obj:
                userid =  obj['userid']

        if not userid:
            logger.warn('fail|get_user_info_by_code fail,userid is null,code:%s, return'%codee)
            return handle_failure()

        #nickname = urllib.quote(obj['nickname'])
        #usericon = urllib.quote(obj['usericon'])
        #expires  = urllib.quote(expires)
        result = {}
        result['token']   = token
        result['userid']  = userid
        res = handle_success(result, 1000, '成功')
        logger.info('get_weixin_code response:%s'%result)

        #return redirect("http://nbstorage.sparta.html5.qq.com/qq/code/result?token=%s&userid=%s"%(token,userid), code=302)
    except:
        res = handle_failure()
        logger.error('fail|exception|ub request serve error|%s' % traceback.format_exc())

    return res