本帖最后由 WilliamJiang 于 2019-5-31 18:27 编辑
from QQLoginTool.QQtool import OAuthQQ
from django.conf import settings
import requests
class MyOAuthQQ(OAuthQQ):
def get_user_info(self, access_token, openid):
# 构建请求url
url = '''https://graph.qq.com/user/get_user_info?access_token=%s&oauth_consumer_key=%s&openid=%s''' % (access_token, settings.QQ_CLIENT_ID, openid)
# 发送请求
try:
response = requests.get(url)
data = response.text # json
except:
raise Exception('qq请求失败')
else:
return data
class Meta:
abstract = True
"""返回的数据为json,正确示例:
{
"ret":0,
"msg":"",
"nickname":"Peter",
"figureurl":"http://qzapp.qlogo.cn/qzapp/111111/942FEA70050EEAFBD4DCE2C1FC775E56/30",
"figureurl_1":"http://qzapp.qlogo.cn/qzapp/111111/942FEA70050EEAFBD4DCE2C1FC775E56/50",
"figureurl_2":"http://qzapp.qlogo.cn/qzapp/111111/942FEA70050EEAFBD4DCE2C1FC775E56/100",
"figureurl_qq_1":"http://q.qlogo.cn/qqapp/100312990/DE1931D5330620DBD07FB4A5422917B6/40",
"figureurl_qq_2":"http://q.qlogo.cn/qqapp/100312990/DE1931D5330620DBD07FB4A5422917B6/100",
"gender":"男",
"is_yellow_vip":"1",
"vip":"1",
"yellow_vip_level":"7",
"level":"7",
"is_yellow_year_vip":"1"
}
""" |
|