def get_active_client(cls):
     '''获取可执行的client'''
     _cookie = get_token_from_cookie()
     if _cookie:
         r = Dict(json.loads(_cookie))
         client = APIClient(app_key=wb.app_key, app_secret=wb.app_secret, redirect_uri=wb.redirect_uri)
         client.set_access_token(r.access_token, r.expires_in)
         return client
     _url = cls().get_weibo_login_url()
     return dict(done=False, url=_url, message=u'需要登录')
 def get_weibo_login_url(cls):
     '''获取微博登陆url'''
     _back = urllib.urlencode({
         'url': request.path,
         'ids': request.query.get('ids', '')
     })
     client = APIClient(app_key=wb.app_key,
                        app_secret=wb.app_secret,
                        redirect_uri='%s%s' % (wb.redirect_uri, _back))
     url = client.get_authorize_url()
     return url
 def get_token(cls):
     '''获取token及expires_in'''
     _code = request.query.get('code', None)
     _url = request.query.get('url', None)
     _ids = request.query.get('ids', None)
     if _code:
         client = APIClient(app_key=wb.app_key, app_secret=wb.app_secret, redirect_uri=wb.redirect_uri)
         r = client.request_access_token(_code)
         set_token_to_cookie(r)    #保存token到cookie中
         redirect('%s%s?ids=%s'%(get_site_url()[:-1], _url, _ids))
     return dict(done=False, url=cls().get_weibo_login_url(), message=u'需要登录')
 def get_active_client(cls):
     '''获取可执行的client'''
     _cookie = get_token_from_cookie()
     if _cookie:
         r = Dict(json.loads(_cookie))
         client = APIClient(app_key=wb.app_key,
                            app_secret=wb.app_secret,
                            redirect_uri=wb.redirect_uri)
         client.set_access_token(r.access_token, r.expires_in)
         return client
     _url = cls().get_weibo_login_url()
     return dict(done=False, url=_url, message=u'需要登录')
 def get_token(cls):
     '''获取token及expires_in'''
     _code = request.query.get('code', None)
     _url = request.query.get('url', None)
     _ids = request.query.get('ids', None)
     if _code:
         client = APIClient(app_key=wb.app_key,
                            app_secret=wb.app_secret,
                            redirect_uri=wb.redirect_uri)
         r = client.request_access_token(_code)
         set_token_to_cookie(r)  #保存token到cookie中
         redirect('%s%s?ids=%s' % (get_site_url()[:-1], _url, _ids))
     return dict(done=False,
                 url=cls().get_weibo_login_url(),
                 message=u'需要登录')
 def get_weibo_login_url(cls):
     '''获取微博登陆url'''
     _back = urllib.urlencode({'url':request.path,'ids':request.query.get('ids','')})
     client = APIClient(app_key=wb.app_key, app_secret=wb.app_secret, redirect_uri='%s%s'%(wb.redirect_uri, _back))
     url = client.get_authorize_url()
     return url