检查access_token是否有效
由于access_token有效期为两小时,所以进行下一步操作前最好进行一次检查,接口为:
传入的参数为accesss_token和openid。
access_token有效时返回的json是:
{
errcode:0,errmsg:ok
}
失效时的返回数据为:
{
errcode:40003,errmsg:invalid openid
}
如果access_token有效,则跳过下一步,失效时需要刷新或续期access_token。
刷新或续期access_token
接口说明
access_token是调用授权关系接口的调用凭证,由于access_token有效期(目前为2个小时)较短,当access_token超时后,可以使用refresh_token进行刷新,access_token刷新结果有两种:
1.若access_token已超时,那么进行refresh_token会获取一个新的access_token,新的超时时间;
2.若access_token未超时,那么进行refresh_token不会改变access_token,但超时时间会刷新,相当于续期access_token。
refresh_token拥有较长的有效期(30天),当refresh_token失效的后,需要用户重新授权。
刷新accessToken接口为:
参数说明:
appid:应用唯一标识
grant_type:固定值,填refresh_token
refresh_token:填写前面获取到的refresh_token的值
返回的json数据有:
access_token:接口调用凭证
expires_in:access_token接口调用凭证超时时间,单位(秒)
refresh_token:用户刷新access_token
openid:授权用户唯一标识
scope:用户授权的作用域,使用逗号(,)分隔
检查access_token是否有效
由于access_token有效期为两小时,所以进行下一步操作前最好进行一次检查,接口为:
传入的参数为accesss_token和openid。
access_token有效时返回的json是:{
errcode:0,errmsg:ok
}
失效时的返回数据为:{
errcode:40003,errmsg:invalid openid
}
如果access_token有效,则跳过下一步,失效时需要刷新或续期access_token。
刷新或续期access_token
接口说明
access_token是调用授权关系接口的调用凭证,由于access_token有效期(目前为2个小时)较短,当access_token超时后,可以使用refresh_token进行刷新,access_token刷新结果有两种:
1.若access_token已超时,那么进行refresh_token会获取一个新的access_token,新的超时时间;
2.若access_token未超时,那么进行refresh_token不会改变access_token,但超时时间会刷新,相当于续期access_token。
refresh_token拥有较长的有效期(30天),当refresh_token失效的后,需要用户重新授权。
刷新accessToken接口为:
参数说明:appid:应用唯一标识
grant_type:固定值,填refresh_token
refresh_token:填写前面获取到的refresh_token的值
返回的json数据有:access_token:接口调用凭证
expires_in:access_token接口调用凭证超时时间,单位(秒)
refresh_token:用户刷新access_token
openid:授权用户唯一标识
scope:用户授权的作用域,使用逗号(,)分隔
的第三方登录授权过后,获取到了用户的信息后,再去点击 的登录按钮,不再跳转 的登录页面了