github地址:cppfun@wechat-open-third-party-dev
在开始本节之前,你需要先阅读前四节的内容:
微信公众号第三方平台开发python教程 Part 1
微信公众号第三方平台开发python教程 Part 2
微信公众号第三方平台开发python教程 Part 3
微信公众号第三方平台开发python教程 Part 4
本节第五讲,我们讲讲如何刷新token(刷新授权公众号的接口调用令牌)。
这个其实就更简单了,代码如下:
def get_refresh_authorizer_access_token
(
self
, authorizer_appid
, authorizer_refresh_token
):
url = 'https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token=%s' \
% self. get_com_access_token ( )
payload = {
"component_appid": self. component_appid ,
"authorizer_appid": authorizer_appid ,
"authorizer_refresh_token": authorizer_refresh_token
}
headers = { 'content-type': 'application/json' }
response = requests. post (url , data =json. dumps (payload ) , headers =headers )
return response. json ( )
url = 'https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token=%s' \
% self. get_com_access_token ( )
payload = {
"component_appid": self. component_appid ,
"authorizer_appid": authorizer_appid ,
"authorizer_refresh_token": authorizer_refresh_token
}
headers = { 'content-type': 'application/json' }
response = requests. post (url , data =json. dumps (payload ) , headers =headers )
return response. json ( )
这里需要两个参数:
# authorizer_appid
# 授权方appid
# authorizer_refresh_token
# 授权方的刷新令牌,刷新令牌主要用于公众号第三方平台获取和刷新已授权用户的access_token,只会在授权时刻提供,请妥善保存。
# 我们一般将其保存在数据库中,因为你授权的公众号不止一个
# 授权方appid
# authorizer_refresh_token
# 授权方的刷新令牌,刷新令牌主要用于公众号第三方平台获取和刷新已授权用户的access_token,只会在授权时刻提供,请妥善保存。
# 我们一般将其保存在数据库中,因为你授权的公众号不止一个
现在我们看看我们的class WxOpenSDK,其代码如下:
class WxOpenCallback:
def __init__ ( self ):
self. token =
def __init__ ( self ):
self. token =