Beispiel #1
0
    def get(self):
        api = QQAPIClient(config.get('qq_apiid'),
                          config.get('qq_appkey'),
                          redirect_uri=config.get('qq_callback_url'))
        code = self.request.query_arguments.get('code')[0]
        print code
        access_token = api.request_access_token(code)
        api.set_access_token(access_token['access_token'],
                             access_token['expires_in'])
        user_info = api.get.user__get_user_info()
        openid = api.get_openid()

        now = datetime.utcnow()
        user = User.objects.filter(third_info__third_type='qq',
                                 third_info__openid=openid).first()
        if not user:
            user = User(create_on=now, modify_on=now, last_login=now)
        else:
            user.modify_on = now
            user.last_login = now

        user.username = openid
        user.nick_name = user_info.get('nickname', '')
        user.email = '*****@*****.**' % openid
        gender = 'm' if user_info.get('gender') == u'男' else 'f'
        user.gender = gender
        user.avatar = user_info.get('figureurl_qq_2', '')
        user.third_info = {'third_type': 'qq', 'info': dict(user_info), 'openid': openid}
        user.save()

        # set user cookie
        self.set_secure_cookie(config.get('uname'), openid)
        self.write(json.dumps(make_success_response(user_info)))
Beispiel #2
0
#!/usr/bin/env python
# coding=utf-8

"""
just test for get an auth
"""


from sso.qq.api import APIClient

# Set your values here
APP_ID = '101284802'
APP_KEY = '2bc6db4840f7708c860a026efd91fc41'
#CALLBACK_URL = 'http://www.chatting2all.com/redirect/'
CALLBACK_URL = 'http://chat2all.lichenfan.com/qq_redirect/'


api = APIClient(APP_ID, APP_KEY, redirect_uri=CALLBACK_URL)
print 'Open this url in your browser: %s' % api.get_authorization_url("authorize")
code = raw_input('Enter code parameter in your callback url args: ').strip()
access_token = api.request_access_token(code)
api.set_access_token(access_token['access_token'], access_token['expires_in'])
print api.get.user__get_user_info()
Beispiel #3
0
 def get(self):
     api = QQAPIClient(config.get("qq_apiid"), config.get("qq_appkey"), redirect_uri=config.get("qq_callback_url"))
     auth_url = api.get_authorization_url("authorize")
     self.render("index.html", auth_url=auth_url)