本人编写用户认可的代码,出现错误: 40029错误的oauth_code问题。
在网上查找答案后,调用了两次请求,返回的代码相同,所以无效。
但是不知道为什么,我求你两次。
请求授权码:
def log in (请求) :
user=request.session.get (wx _ user ),default=None ) ) )。
#如果用户以前不关注
if user is None:
URL=(https://open.weixin.QQ.com/connect/oauth2/authorize? appid=% s redirect _ uri=% s response _ type=code scope=snsapi _ userinfo state=1# we chat _ redirect ' % ()
returnhttpresponseredirect(URL ) )。
else:
返回httpresponse (u '关注成功) ) )。
批准后,回调函数将检索代码,并调用以下函数请求检索access_token代码:
efgetuserbycode(app_id,APP_SECRET,代码) :
URL=' https://API.weixin.QQ.com/SNS/oauth2/access _ token? appid=% s secret=% scode=% s grant _ type=authorization _ code ' % (app _ id,APP_SECRET,code )
Jons=request.urlopen(URL ).read ) )。
JSONS=str(JSONS,encoding='utf-8 ' ) #将返回的bytes类型转换为字符串类型
arr=json.loads(jsons )
返回arr
对不起,我这样写问题的地方是哪里?